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; {
updateWithSuper = false; #< don't update feeds unless explicitly asked to by the user
mkFeed = callPackage ./template.nix {};
feed-pkgs = let
byName = lib.mapAttrs

View File

@@ -1,5 +1,5 @@
#!/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
@@ -53,7 +53,7 @@ getPkgs() {
nix-instantiate -A nix "$NIX_FILES_TOP"
nix-instantiate -A nixpkgs "$NIX_FILES_TOP"
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"
attrsArr+=($attrs)
}
@@ -61,11 +61,6 @@ getPkgs() {
updateOnePkg() {
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 " "')
if [ -z "$updateScript" ]; then
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=
ignore=
toplevelsToUpdate=()
verbose=
parseArgs() {
@@ -107,9 +109,11 @@ parseArgs() {
usage
;;
(--dry-run)
scriptFlags+=(--dry-run)
dryRun=1
;;
(--verbose)
scriptFlags+=(--verbose)
verbose=1
;;
(*)
@@ -118,7 +122,6 @@ parseArgs() {
esac
done
if [ "${#toplevelsToUpdate[@]}" -eq 0 ]; then
ignore=sane.feeds
toplevelsToUpdate=(sane)
fi
}
@@ -129,6 +132,14 @@ for t in "${toplevelsToUpdate[@]}"; do
getPkgs pkgsToUpdate "$t"
done
for p in "${pkgsToUpdate[@]}"; do
hasEffect updateOnePkg "$p"
done
case "${#pkgsToUpdate[@]}" in
(0)
echo "nothing to do"
;;
(1)
hasEffect updateOnePkg "${pkgsToUpdate[0]}"
;;
(*)
hasEffect updatePkgsInParallel "${pkgsToUpdate[@]}"
;;
esac