fix only first of multiple consecutive updates being applied

This commit is contained in:
bit 2025-08-22 17:13:22 +02:00
parent a44fd5e362
commit 173380598e

View File

@ -18,11 +18,9 @@
...
}:
''
#!/usr/bin/env bash
set -e
do_update() {
hostname=$(${hostname})
new_system=$(nix build --no-link --print-out-paths "${cfg.flake}#nixosConfigurations.''${hostname}.config.system.build.toplevel")
new_system=$(nix build --refresh --no-link --print-out-paths "${cfg.flake}#nixosConfigurations.''${hostname}.config.system.build.toplevel")
last_flake_update_time() {
nix flake metadata --refresh --json "$1" | ${jq} .lastModified
@ -106,7 +104,7 @@
echo "last system update: $(${date} -d @"$system_update_time")"
echo "last flake update: $(${date} -d @"$flake_update_time")"
if [[ "$system_update_time" -gt "$flake_update_time" ]]
if [[ -z "$1" ]] && [[ "$system_update_time" -gt "$flake_update_time" ]]
then
echo ""
echo "System is newer than remote!"
@ -182,4 +180,11 @@
fi
"''${new_system}/bin/switch-to-configuration" "boot"
fi
if [[ "$(last_flake_update_time "${cfg.flake}")" -gt "$flake_update_time" ]]
then
echo "flake was update after last update."
do_update force
fi
}
''