From 13a2acfd701820311adb9bd12816f0d34a74d6dd Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 15 Mar 2025 04:55:09 +0000 Subject: [PATCH] scripts/update: dont hardcode the location of this repo --- scripts/update | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/scripts/update b/scripts/update index 08d927593..12a492700 100755 --- a/scripts/update +++ b/scripts/update @@ -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