{ config, pkgs, ... }:
let
nix = pkgs.runCommand "nix-2.2" { } "mkdir -p $out";
in
{
nix.gc.automatic = true;
nix.gc.options = "--delete-older-than 30d";
nix.gc.user = "nixuser";
nix.package = nix;
test = ''
echo checking nix-gc service in /Library/LaunchDaemons >&2
grep "org.nixos.nix-gc" ${config.out}/Library/LaunchDaemons/org.nixos.nix-gc.plist
grep "/bin/wait4path /nix/store && exec ${nix}/bin/nix-collect-garbage --delete-older-than 30d" ${config.out}/Library/LaunchDaemons/org.nixos.nix-gc.plist
grep "UserName" ${config.out}/Library/LaunchDaemons/org.nixos.nix-gc.plist
grep "nixuser" ${config.out}/Library/LaunchDaemons/org.nixos.nix-gc.plist
(! grep "KeepAlive" ${config.out}/Library/LaunchDaemons/org.nixos.nix-gc.plist)
echo checking nix-gc validation >&2
(! grep "nix.gc.user = " ${config.out}/activate-user)
'';
}