1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-13 10:13:39 +02:00

nh: add module

Add nh to news
This commit is contained in:
John Titor 2024-04-23 23:07:08 +05:30
parent 67de98ae6e
commit 9b1f7944fe
No known key found for this signature in database
GPG Key ID: 29B0514F4E3C1CC0
3 changed files with 88 additions and 0 deletions

View File

@ -1537,6 +1537,14 @@ in {
for more.
'';
}
{
time = "2024-04-23T18:50:00+00:00";
condition = hostPlatform.isLinux;
message = ''
A new module is available: 'programs.nh'.
'';
}
];
};
}

View File

@ -165,6 +165,7 @@ let
./programs/neomutt.nix
./programs/neovim.nix
./programs/newsboat.nix
./programs/nh.nix
./programs/nheko.nix
./programs/nix-index.nix
./programs/nnn.nix

79
modules/programs/nh.nix Normal file
View File

@ -0,0 +1,79 @@
{ config, osConfig, lib, pkgs, ... }:
let cfg = config.programs.nh;
in {
meta.maintainers = with lib.maintainers; [ johnrtitor ];
options.programs.nh = {
enable = lib.mkEnableOption "nh, yet another Nix CLI helper";
package = lib.mkPackageOption pkgs "nh" { };
flake = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = ''
The path that will be used for the `FLAKE` environment variable.
`FLAKE` is used by nh as the default flake for performing actions, like `nh os switch`.
'';
};
clean = {
enable = lib.mkEnableOption
"periodic garbage collection for user profile and nix store with nh clean user";
dates = lib.mkOption {
type = lib.types.singleLineStr;
default = "weekly";
description = ''
How often cleanup is performed. Passed to systemd.time
The format is described in
{manpage}`systemd.time(7)`.
'';
};
extraArgs = lib.mkOption {
type = lib.types.singleLineStr;
default = "";
example = "--keep 5 --keep-since 3d";
description = ''
Options given to nh clean when the service is run automatically.
See `nh clean all --help` for more information.
'';
};
};
};
config = {
warnings = lib.optionals (!(cfg.clean.enable -> !osConfig.nix.gc.automatic))
[
"programs.nh.clean.enable and nix.gc.automatic (system-wide in configuration.nix) are both enabled. Please use one or the other to avoid conflict."
];
assertions = [{
assertion = (cfg.flake != null) -> !(lib.hasSuffix ".nix" cfg.flake);
message = "nh.flake must be a directory, not a nix file";
}];
home = lib.mkIf cfg.enable {
packages = [ cfg.package ];
sessionVariables = lib.mkIf (cfg.flake != null) { FLAKE = cfg.flake; };
};
systemd.user = lib.mkIf cfg.clean.enable {
services.nh-clean = {
description = "Nh clean (user)";
script =
"exec ${lib.getExe cfg.package} clean user ${cfg.clean.extraArgs}";
startAt = cfg.clean.dates;
path = [ config.nix.package ];
serviceConfig.Type = "oneshot";
};
timers.nh-clean = { timerConfig = { Persistent = true; }; };
};
};
}