7 cfg = config.programs.nh;
10 meta.maintainers = [ lib.maintainers.viperML ];
12 options.programs.nh = {
13 enable = lib.mkEnableOption "nh, yet another Nix CLI helper";
15 package = lib.mkPackageOption pkgs "nh" { };
17 flake = lib.mkOption {
18 type = lib.types.nullOr lib.types.path;
21 The path that will be used for the `FLAKE` environment variable.
23 `FLAKE` is used by nh as the default flake for performing actions, like `nh os switch`.
28 enable = lib.mkEnableOption "periodic garbage collection with nh clean all";
30 dates = lib.mkOption {
31 type = lib.types.singleLineStr;
34 How often cleanup is performed. Passed to systemd.time
36 The format is described in
37 {manpage}`systemd.time(7)`.
41 extraArgs = lib.mkOption {
42 type = lib.types.singleLineStr;
44 example = "--keep 5 --keep-since 3d";
46 Options given to nh clean when the service is run automatically.
48 See `nh clean all --help` for more information.
56 if (!(cfg.clean.enable -> !config.nix.gc.automatic)) then [
57 "programs.nh.clean.enable and nix.gc.automatic are both enabled. Please use one or the other to avoid conflict."
61 # Not strictly required but probably a good assertion to have
63 assertion = cfg.clean.enable -> cfg.enable;
64 message = "programs.nh.clean.enable requires programs.nh.enable";
68 assertion = (cfg.flake != null) -> !(lib.hasSuffix ".nix" cfg.flake);
69 message = "nh.flake must be a directory, not a nix file";
73 environment = lib.mkIf cfg.enable {
74 systemPackages = [ cfg.package ];
75 variables = lib.mkIf (cfg.flake != null) {
80 systemd = lib.mkIf cfg.clean.enable {
82 description = "Nh clean";
83 script = "exec ${lib.getExe cfg.package} clean all ${cfg.clean.extraArgs}";
84 startAt = cfg.clean.dates;
85 path = [ config.nix.package ];
86 serviceConfig.Type = "oneshot";