From 15a684c5d7e1ee25cdd6f2941ed17c01aa107781 Mon Sep 17 00:00:00 2001 From: Yureka Date: Fri, 26 Jul 2024 12:17:04 +0200 Subject: [PATCH] baremetal-builders: more 'intelligent' gc --- services/baremetal-builder/default.nix | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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;