at master 2.3 kB view raw
1{ ... }: 2{ 3 name = "angrr"; 4 nodes = { 5 machine = { 6 services.angrr = { 7 enable = true; 8 period = "7d"; 9 }; 10 # `angrr.service` integrates to `nix-gc.service` by default 11 nix.gc.automatic = true; 12 13 # Create a normal nix user for test 14 users.users.normal.isNormalUser = true; 15 # For `nix build /run/current-system --out-link`, 16 # `nix-build` does not support this use case. 17 nix.settings.experimental-features = [ "nix-command" ]; 18 }; 19 }; 20 21 testScript = '' 22 start_all() 23 24 machine.wait_for_unit("default.target") 25 26 machine.systemctl("stop nix-gc.timer") 27 28 # Creates some auto gc roots 29 # Use /run/current-system so that we do not need to build anything new 30 machine.succeed("nix build /run/current-system --out-link /tmp/root-auto-gc-root-1") 31 machine.succeed("nix build /run/current-system --out-link /tmp/root-auto-gc-root-2") 32 machine.succeed("su normal --command 'nix build /run/current-system --out-link /tmp/user-auto-gc-root-1'") 33 machine.succeed("su normal --command 'nix build /run/current-system --out-link /tmp/user-auto-gc-root-2'") 34 35 machine.systemctl("start nix-gc.service") 36 # Not auto gc root will be removed 37 machine.succeed("readlink /tmp/root-auto-gc-root-1") 38 machine.succeed("readlink /tmp/root-auto-gc-root-2") 39 machine.succeed("readlink /tmp/user-auto-gc-root-1") 40 machine.succeed("readlink /tmp/user-auto-gc-root-2") 41 42 # Change time to 8 days after (greater than 7d) 43 machine.succeed("date -s '8 days'") 44 45 # Touch GC roots `-2` 46 machine.succeed("touch /tmp/root-auto-gc-root-2 --no-dereference") 47 machine.succeed("touch /tmp/user-auto-gc-root-2 --no-dereference") 48 49 machine.systemctl("start nix-gc.service") 50 # Only GC roots `-1` are removed 51 machine.succeed("test ! -f /tmp/root-auto-gc-root-1") 52 machine.succeed("readlink /tmp/root-auto-gc-root-2") 53 machine.succeed("test ! -f /tmp/user-auto-gc-root-1") 54 machine.succeed("readlink /tmp/user-auto-gc-root-2") 55 56 # Change time again 57 machine.succeed("date -s '8 days'") 58 machine.systemctl("start nix-gc.service") 59 # All auto GC roots are removed 60 machine.succeed("test ! -f /tmp/root-auto-gc-root-2") 61 machine.succeed("test ! -f /tmp/user-auto-gc-root-2") 62 ''; 63}