scripts/update: expand

This commit is contained in:
2024-06-07 07:34:51 +00:00
parent 14f4f1e80d
commit 56cd1f211c

View File

@@ -1,14 +1,68 @@
#!/bin/sh #!/bin/sh
showHelp() {
echo "update: updates flake inputs"
echo "usage: update [flags] [input [input ...]]"
echo ""
echo "flags:"
echo " --help"
echo " --dry-run"
echo "inputs:"
echo " all: update every input"
echo " safe: update inputs which rarely break the build, or are trivial to patch"
echo " unsafe: update inputs which may be annoying to patch if they break the build"
echo " nixpkgs"
echo " next"
}
inputs=() inputs=()
dryRun=
parseArgs() {
for arg in "$@"; do
case $arg in
(--help)
showHelp
exit 1
;;
(--dry-run)
dryRun=1
;;
(*)
addInputs "$arg"
;;
esac
done
# if no inputs were specified, assume "all"
if [ ${#inputs} -eq 0 ]; then
addInputs all
fi
}
# add $1 to `inputs` array, after parsing it
addInputs() { addInputs() {
case $1 in case $1 in
(all)
addInputs safe
addInputs unsafe
;;
(next)
addInputs nixpkgs-next-unpatched
addInputs nixpkgs-staging-unpatched
;;
(safe) (safe)
inputs+=(uninsane-dot-org nixpkgs-unpatched nixpkgs-next-unpatched sops-nix) addInputs next
addInputs nixpkgs-unpatched
addInputs sops-nix
addInputs uninsane-dot-org
;; ;;
(unsafe) (unsafe)
# these tend to break more frequently # these tend to break more frequently
inputs+=(mobile-nixos nixpkgs-wayland) addInputs mobile-nixos
addInputs nixpkgs-wayland
;;
(mobile-nixos|nixpkgs-next-unpatched|nixpkgs-staging-unpatched|nixpkgs-unpatched|nixpkgs-wayland|sops-nix|uninsane-dot-org)
inputs+=("$1")
;; ;;
(*) (*)
echo "unknown input '$1'" echo "unknown input '$1'"
@@ -17,19 +71,21 @@ addInputs() {
esac esac
} }
case "$1" in # exec $@, unless we're in a dry-run in which case just print what would be done
(all|"") doEffect() {
addInputs "safe" if [ -n "$dryRun" ]; then
addInputs "unsafe" echo "dry-run: $*"
;; else
(*) "$@"
addInputs "$1" fi
;; }
esac
parseArgs "$@"
echo "updating:" "${inputs[@]}" echo "updating:" "${inputs[@]}"
nixFlags=() nixFlags=()
for i in "${inputs[@]}"; do for i in "${inputs[@]}"; do
nixFlags+=("--update-input" "$i") nixFlags+=("--update-input" "$i")
done done
nix flake lock "${nixFlags[@]}"
doEffect nix flake lock "${nixFlags[@]}"