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