diff --git a/services/baremetal-builder/default.nix b/services/baremetal-builder/default.nix index 581a0e8..ee3dbdf 100644 --- a/services/baremetal-builder/default.nix +++ b/services/baremetal-builder/default.nix @@ -146,14 +146,23 @@ in }; systemd.services.hydra-gc = { + wantedBy = [ "multi-user.target" ]; description = "Nix Garbage Collector"; - script = "exec ${config.nix.package.out}/bin/nix-store --gc --store /mnt"; + script = '' + while : ; do + percent_filled=$(($(stat -f --format="100-(100*%a/%b)" /))) + if [ "$percent_filled" -gt "85" ]; then + ${config.nix.package.out}/bin/nix-store --gc --max-freed 100G --store /mnt + else + break + fi + done + ''; serviceConfig.Type = "oneshot"; serviceConfig.User = "builder"; }; systemd.timers.hydra-gc = { - timerConfig.OnStartupSec = "4h"; - timerConfig.OnUnitActiveSec = "20h"; + timerConfig.OnUnitInactiveSec = "10min"; wantedBy = [ "timers.target" ]; }; systemd.timers.hydra-gc.timerConfig.Persistent = true;