From db40fead89db185dfd863aed5dad1d675f82a3fc Mon Sep 17 00:00:00 2001 From: Ninja3047 <1284324+Ninja3047@users.noreply.github.com> Date: Mon, 22 Jul 2024 21:51:02 -0400 Subject: [PATCH] nix-gc: call nix-collect-garbage in a shell script This will match the behavior in the upstream service which allows the user to set options to something that uses shell syntax. --- modules/services/nix-gc.nix | 5 +++-- tests/modules/services/nix-gc/basic.nix | 2 +- tests/modules/services/nix-gc/expected.service | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/services/nix-gc.nix b/modules/services/nix-gc.nix index 652c575a..0f477204 100644 --- a/modules/services/nix-gc.nix +++ b/modules/services/nix-gc.nix @@ -110,9 +110,10 @@ in { systemd.user.services.nix-gc = { Unit = { Description = "Nix Garbage Collector"; }; Service = { - ExecStart = "${nixPackage}/bin/nix-collect-garbage ${ + ExecStart = toString (pkgs.writeShellScript "nix-gc" '' + exec "${nixPackage}/bin/nix-collect-garbage ${ lib.optionalString (cfg.options != null) cfg.options - }"; + }"''); }; }; systemd.user.timers.nix-gc = { diff --git a/tests/modules/services/nix-gc/basic.nix b/tests/modules/services/nix-gc/basic.nix index d6511a17..507c9598 100644 --- a/tests/modules/services/nix-gc/basic.nix +++ b/tests/modules/services/nix-gc/basic.nix @@ -4,7 +4,7 @@ nix.gc = { automatic = true; frequency = "monthly"; - options = "--delete-older-than 30d"; + options = "--delete-older-than 30d --max-freed $((64 * 1024**3))"; }; test.stubs.nix = { name = "nix"; }; diff --git a/tests/modules/services/nix-gc/expected.service b/tests/modules/services/nix-gc/expected.service index 4aafd6af..73c0355c 100644 --- a/tests/modules/services/nix-gc/expected.service +++ b/tests/modules/services/nix-gc/expected.service @@ -1,5 +1,5 @@ [Service] -ExecStart=@nix@/bin/nix-collect-garbage --delete-older-than 30d +ExecStart=/nix/store/00000000000000000000000000000000-nix-gc [Unit] Description=Nix Garbage Collector