scripts/update: dont hardcode the location of this repo

This commit is contained in:
2025-03-15 04:55:09 +00:00
parent bbefa924cf
commit 13a2acfd70

View File

@@ -1,9 +1,9 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p findutils -p nix-update
#!nix-shell -i bash -p findutils -p git -p nix-update
NIX_FILES_TOP=/home/colin/nixos
# each update job has to do an entire nix eval, which can be memory intensive; be careful when tuning this
PARALLELISM=8
SELF_PATH=$PWD/$0
usage() {
echo "update: update rev/hash for one or more packages"
@@ -41,6 +41,14 @@ hasEffect() {
fi
}
REPO_ROOT=
repo_root() {
if [ -z "$REPO_ROOT" ]; then
REPO_ROOT=$(git -C "$(dirname SELF_PATH)" rev-parse --show-toplevel)
fi
echo "$REPO_ROOT"
}
# usage: getPkgs outVar prefix
getPkgs() {
local -n attrsArr="$1"
@@ -53,10 +61,10 @@ getPkgs() {
# # but since i use Import From Derivation along paths which i also want to query,
# # then i need to ensure those derivations are available for import.
# debug "creating requisite .drv store paths"
# nix-instantiate -A nix "$NIX_FILES_TOP"
# nix-instantiate -A nixpkgs-bootstrap.master "$NIX_FILES_TOP"
# nix-instantiate -A nix "$(repo_root)"
# nix-instantiate -A nixpkgs-bootstrap.master "$(repo_root)"
debug "querying packages to update as part of '$attrPrefix'"
local attrs=$(nix eval --raw -f "$NIX_FILES_TOP" 'updateTargets."'"$attrPrefix"'"' --apply 'builtins.concatStringsSep " "' "${nixFlags[@]}")
local attrs=$(nix eval --raw -f "$(repo_root)" 'updateTargets."'"$attrPrefix"'"' --apply 'builtins.concatStringsSep " "' "${nixFlags[@]}")
debug "got: $attrs"
attrsArr+=($attrs)
}
@@ -64,14 +72,14 @@ getPkgs() {
updateOnePkg() {
local attrPath="$1"
local updateScript=$(nix eval --raw -f "$NIX_FILES_TOP" 'updateScripts."'"$attrPath"'"' "${nixFlags[@]}")
local updateScript=$(nix eval --raw -f "$(repo_root)" 'updateScripts."'"$attrPath"'"' "${nixFlags[@]}")
if [ -z "$updateScript" ]; then
warn "don't know how to update '$attrPath'"
return
fi
# make sure everything needed to invoke the update script exists in-store
local context=$(nix eval --raw -f "$NIX_FILES_TOP" 'updateScripts."'"$attrPath"'"' --apply 's: builtins.concatStringsSep " " (builtins.attrNames (builtins.getContext s))' "${nixFlags[@]}")
local context=$(nix eval --raw -f "$(repo_root)" 'updateScripts."'"$attrPath"'"' --apply 's: builtins.concatStringsSep " " (builtins.attrNames (builtins.getContext s))' "${nixFlags[@]}")
for c in $context; do
debug "realizing updateScript requisite: $context"
nix-store --realize "$c" "${nixFlags[@]}" || true