diff --git a/modules/programs/nh.nix b/modules/programs/nh.nix index ef078d18..2950f3db 100644 --- a/modules/programs/nh.nix +++ b/modules/programs/nh.nix @@ -37,7 +37,9 @@ in description = '' How often cleanup is performed. - The format is described in {manpage}`systemd.time(7)`. + On linux the format is described in {manpage}`systemd.time(7)`. + + ${lib.hm.darwin.intervalDocumentation} ''; }; @@ -59,6 +61,10 @@ in lib.optional (cfg.clean.enable && config.nix.gc.automatic) "programs.nh.clean.enable and nix.gc.automatic (Home-Manager) are both enabled. Please use one or the other to avoid conflict."; + assertions = lib.optionals pkgs.stdenv.isDarwin [ + (lib.hm.darwin.assertInterval "programs.nh.clean.dates" cfg.clean.dates pkgs) + ]; + home = lib.mkIf cfg.enable { packages = [ cfg.package ]; sessionVariables = lib.mkIf (cfg.flake != null) ( @@ -70,7 +76,7 @@ in ); }; - systemd.user = lib.mkIf cfg.clean.enable { + systemd.user = lib.mkIf (cfg.clean.enable && pkgs.stdenv.isLinux) { services.nh-clean = { Unit.Description = "Nh clean (user)"; @@ -90,6 +96,21 @@ in Install.WantedBy = [ "timers.target" ]; }; + + }; + + launchd.agents.nh-clean = lib.mkIf (cfg.clean.enable && pkgs.stdenv.isDarwin) { + enable = true; + config = { + ProgramArguments = [ + "${lib.getExe cfg.package}" + "clean" + "user" + ] ++ lib.optional (cfg.clean.extraArgs != "") cfg.clean.extraArgs; + + StartCalendarInterval = lib.hm.darwin.mkCalendarInterval cfg.clean.dates; + + }; }; }; } diff --git a/tests/darwinScrublist.nix b/tests/darwinScrublist.nix index 952f7a0f..e80fceb2 100644 --- a/tests/darwinScrublist.nix +++ b/tests/darwinScrublist.nix @@ -101,6 +101,7 @@ let "neovide" "neovim" "newsboat" + "nh" "nheko" "nix" "nix-direnv" diff --git a/tests/modules/programs/nh/darwin/config.nix b/tests/modules/programs/nh/darwin/config.nix new file mode 100644 index 00000000..20f9c821 --- /dev/null +++ b/tests/modules/programs/nh/darwin/config.nix @@ -0,0 +1,22 @@ +{ + programs.nh = { + enable = true; + + flake = "/path/to/flake"; + + clean = { + enable = true; + dates = "weekly"; + }; + }; + + nmt.script = '' + serviceFile="LaunchAgents/org.nix-community.home.nh-clean.plist" + serviceFileNormalized="$(normalizeStorePaths "$serviceFile")" + + assertFileExists $serviceFile + assertFileContent $serviceFileNormalized ${./launchd.plist} + + assertFileRegex home-path/etc/profile.d/hm-session-vars.sh 'NH_FLAKE="/path/to/flake"' + ''; +} diff --git a/tests/modules/programs/nh/darwin/launchd.plist b/tests/modules/programs/nh/darwin/launchd.plist new file mode 100644 index 00000000..efdb65d2 --- /dev/null +++ b/tests/modules/programs/nh/darwin/launchd.plist @@ -0,0 +1,25 @@ + + + + + Label + org.nix-community.home.nh-clean + ProgramArguments + + @nh@/bin/nh + clean + user + + StartCalendarInterval + + + Hour + 0 + Minute + 0 + Weekday + 1 + + + + \ No newline at end of file diff --git a/tests/modules/programs/nh/default.nix b/tests/modules/programs/nh/default.nix index 557f4c05..bcd3e320 100644 --- a/tests/modules/programs/nh/default.nix +++ b/tests/modules/programs/nh/default.nix @@ -1,4 +1,7 @@ { lib, pkgs, ... }: -lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { - nh = ./nh.nix; -} +(lib.optionalAttrs pkgs.stdenv.hostPlatform.isDarwin { + nh = ./darwin/config.nix; +}) +// (lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { + nh = ./linux/config.nix; +}) diff --git a/tests/modules/programs/nh/nh.nix b/tests/modules/programs/nh/linux/config.nix similarity index 100% rename from tests/modules/programs/nh/nh.nix rename to tests/modules/programs/nh/linux/config.nix