diff --git a/modules/services/home-manager-auto-expire.nix b/modules/services/home-manager-auto-expire.nix index cb60417c..2f98d205 100644 --- a/modules/services/home-manager-auto-expire.nix +++ b/modules/services/home-manager-auto-expire.nix @@ -55,6 +55,8 @@ in as the `OnCalendar` option. The format is described in {manpage}`systemd.time(7)`. + + ${lib.hm.darwin.intervalDocumentation} ''; }; @@ -104,6 +106,23 @@ in }; }; }) + + (lib.mkIf pkgs.stdenv.isDarwin { + assertions = [ + (lib.hm.darwin.assertInterval "services.home-manager.autoExpire.frequency" cfg.frequency pkgs) + ]; + + launchd.agents.home-manager-auto-expire = { + enable = true; + config = { + ProgramArguments = [ (toString script) ]; + ProcessType = "Background"; + StartCalendarInterval = lib.hm.darwin.mkCalendarInterval cfg.frequency; + StandardOutPath = "${config.home.homeDirectory}/Library/Logs/home-manager-auto-expire/launchd-stdout.log"; + StandardErrorPath = "${config.home.homeDirectory}/Library/Logs/home-manager-auto-expire/launchd-stderr.log"; + }; + }; + }) ] ); } diff --git a/tests/default.nix b/tests/default.nix index 40a858d7..f6d41e4b 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -335,6 +335,7 @@ import nmtSrc { ./modules/services/emacs-darwin ./modules/services/espanso-darwin ./modules/services/git-sync-darwin + ./modules/services/home-manager-auto-expire-darwin ./modules/services/imapnotify-darwin ./modules/services/jankyborders ./modules/services/macos-remap-keys diff --git a/tests/modules/services/home-manager-auto-expire-darwin/basic-configuration.nix b/tests/modules/services/home-manager-auto-expire-darwin/basic-configuration.nix new file mode 100644 index 00000000..6b094ae4 --- /dev/null +++ b/tests/modules/services/home-manager-auto-expire-darwin/basic-configuration.nix @@ -0,0 +1,14 @@ +{ + services.home-manager.autoExpire = { + enable = true; + frequency = "weekly"; + }; + + nmt.script = '' + serviceFile=LaunchAgents/org.nix-community.home.home-manager-auto-expire.plist + assertFileExists "$serviceFile" + + serviceFileNormalized="$(normalizeStorePaths "$serviceFile")" + assertFileContent "$serviceFileNormalized" ${./expected-agent.plist} + ''; +} diff --git a/tests/modules/services/home-manager-auto-expire-darwin/default.nix b/tests/modules/services/home-manager-auto-expire-darwin/default.nix new file mode 100644 index 00000000..1f42ebfe --- /dev/null +++ b/tests/modules/services/home-manager-auto-expire-darwin/default.nix @@ -0,0 +1,4 @@ +{ + darwin-home-manager-autoExpire-service-basic-configuration = ./basic-configuration.nix; + darwin-home-manager-autoExpire-frequency-assertion = ./frequency-assertion.nix; +} diff --git a/tests/modules/services/home-manager-auto-expire-darwin/expected-agent.plist b/tests/modules/services/home-manager-auto-expire-darwin/expected-agent.plist new file mode 100644 index 00000000..fb3878d1 --- /dev/null +++ b/tests/modules/services/home-manager-auto-expire-darwin/expected-agent.plist @@ -0,0 +1,29 @@ + + + + + Label + org.nix-community.home.home-manager-auto-expire + ProcessType + Background + ProgramArguments + + /nix/store/00000000000000000000000000000000-home-manager-auto-expire + + StandardErrorPath + /home/hm-user/Library/Logs/home-manager-auto-expire/launchd-stderr.log + StandardOutPath + /home/hm-user/Library/Logs/home-manager-auto-expire/launchd-stdout.log + StartCalendarInterval + + + Hour + 0 + Minute + 0 + Weekday + 1 + + + + \ No newline at end of file diff --git a/tests/modules/services/home-manager-auto-expire-darwin/frequency-assertion.nix b/tests/modules/services/home-manager-auto-expire-darwin/frequency-assertion.nix new file mode 100644 index 00000000..568d2043 --- /dev/null +++ b/tests/modules/services/home-manager-auto-expire-darwin/frequency-assertion.nix @@ -0,0 +1,10 @@ +{ + services.home-manager.autoExpire = { + enable = true; + frequency = "00:02:00"; + }; + + test.asserts.assertions.expected = [ + "On Darwin services.home-manager.autoExpire.frequency must be one of: hourly, daily, weekly, monthly, semiannually, annually." + ]; +}