nh: fix clean option behaviour for Darwin
This commit is contained in:
parent
78fc50f1cf
commit
e8a3e2c1e0
6 changed files with 77 additions and 5 deletions
|
|
@ -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;
|
||||
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ let
|
|||
"neovide"
|
||||
"neovim"
|
||||
"newsboat"
|
||||
"nh"
|
||||
"nheko"
|
||||
"nix"
|
||||
"nix-direnv"
|
||||
|
|
|
|||
22
tests/modules/programs/nh/darwin/config.nix
Normal file
22
tests/modules/programs/nh/darwin/config.nix
Normal file
|
|
@ -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"'
|
||||
'';
|
||||
}
|
||||
25
tests/modules/programs/nh/darwin/launchd.plist
Normal file
25
tests/modules/programs/nh/darwin/launchd.plist
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>org.nix-community.home.nh-clean</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>@nh@/bin/nh</string>
|
||||
<string>clean</string>
|
||||
<string>user</string>
|
||||
</array>
|
||||
<key>StartCalendarInterval</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>Hour</key>
|
||||
<integer>0</integer>
|
||||
<key>Minute</key>
|
||||
<integer>0</integer>
|
||||
<key>Weekday</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
@ -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;
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue