scripts/update: cleanup

This commit is contained in:
2024-07-21 06:36:21 +00:00
parent 993c3df09e
commit 0f7ec33dac
2 changed files with 25 additions and 12 deletions

View File

@@ -8,6 +8,8 @@
}: }:
lib.makeScope newScope (self: with self; { lib.makeScope newScope (self: with self; {
updateWithSuper = false; #< don't update feeds unless explicitly asked to by the user
mkFeed = callPackage ./template.nix {}; mkFeed = callPackage ./template.nix {};
feed-pkgs = let feed-pkgs = let
byName = lib.mapAttrs byName = lib.mapAttrs

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env nix-shell #!/usr/bin/env nix-shell
#!nix-shell -i bash -p nix-update #!nix-shell -i bash -p findutils -p nix-update
NIX_FILES_TOP=/home/colin/nixos NIX_FILES_TOP=/home/colin/nixos
@@ -53,7 +53,7 @@ getPkgs() {
nix-instantiate -A nix "$NIX_FILES_TOP" nix-instantiate -A nix "$NIX_FILES_TOP"
nix-instantiate -A nixpkgs "$NIX_FILES_TOP" nix-instantiate -A nixpkgs "$NIX_FILES_TOP"
debug "querying packages to update as part of '$attrPrefix'" debug "querying packages to update as part of '$attrPrefix'"
local attrs=$(nix eval --raw -f "$NIX_FILES_TOP" updateTargets."$attrPrefix" --apply 'builtins.concatStringsSep " "') local attrs=$(nix eval --raw -f "$NIX_FILES_TOP" 'updateTargets."'"$attrPrefix"'"' --apply 'builtins.concatStringsSep " "')
debug "got: $attrs" debug "got: $attrs"
attrsArr+=($attrs) attrsArr+=($attrs)
} }
@@ -61,11 +61,6 @@ getPkgs() {
updateOnePkg() { updateOnePkg() {
local attrPath="$1" local attrPath="$1"
if [ -n "$ignore" ] && [[ "$attrPath" =~ ^"$ignore" ]]; then
warn "ignoring $attrPath"
return
fi
local updateScript=$(nix eval --raw -f "$NIX_FILES_TOP" $attrPath.passthru.updateScript --apply 'builtins.concatStringsSep " "') local updateScript=$(nix eval --raw -f "$NIX_FILES_TOP" $attrPath.passthru.updateScript --apply 'builtins.concatStringsSep " "')
if [ -z "$updateScript" ]; then if [ -z "$updateScript" ]; then
warn "don't know how to update '$attrPath'" warn "don't know how to update '$attrPath'"
@@ -94,8 +89,15 @@ updateOnePkg() {
) )
} }
updatePkgsInParallel() {
debug "updating packages in parallel using xargs"
debug "- $@"
debug "- xargs -n 1 -P 4 $0 ${scriptFlags[*]}"
echo "$@" | xargs -n 1 -P 4 "$0" "${scriptFlags[@]}"
}
scriptFlags=()
dryRun= dryRun=
ignore=
toplevelsToUpdate=() toplevelsToUpdate=()
verbose= verbose=
parseArgs() { parseArgs() {
@@ -107,9 +109,11 @@ parseArgs() {
usage usage
;; ;;
(--dry-run) (--dry-run)
scriptFlags+=(--dry-run)
dryRun=1 dryRun=1
;; ;;
(--verbose) (--verbose)
scriptFlags+=(--verbose)
verbose=1 verbose=1
;; ;;
(*) (*)
@@ -118,7 +122,6 @@ parseArgs() {
esac esac
done done
if [ "${#toplevelsToUpdate[@]}" -eq 0 ]; then if [ "${#toplevelsToUpdate[@]}" -eq 0 ]; then
ignore=sane.feeds
toplevelsToUpdate=(sane) toplevelsToUpdate=(sane)
fi fi
} }
@@ -129,6 +132,14 @@ for t in "${toplevelsToUpdate[@]}"; do
getPkgs pkgsToUpdate "$t" getPkgs pkgsToUpdate "$t"
done done
for p in "${pkgsToUpdate[@]}"; do case "${#pkgsToUpdate[@]}" in
hasEffect updateOnePkg "$p" (0)
done echo "nothing to do"
;;
(1)
hasEffect updateOnePkg "${pkgsToUpdate[0]}"
;;
(*)
hasEffect updatePkgsInParallel "${pkgsToUpdate[@]}"
;;
esac