nixpkgs/nixos/modules/programs/nh.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

101 lines
2.5 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
cfg = config.programs.nh;
in
{
meta.maintainers = [ lib.maintainers.viperML ];
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 with nh clean all";
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 =
if (!(cfg.clean.enable -> !config.nix.gc.automatic)) then
[
"programs.nh.clean.enable and nix.gc.automatic are both enabled. Please use one or the other to avoid conflict."
]
else
[ ];
assertions = [
# Not strictly required but probably a good assertion to have
{
assertion = cfg.clean.enable -> cfg.enable;
message = "programs.nh.clean.enable requires programs.nh.enable";
}
{
assertion = (cfg.flake != null) -> !(lib.hasSuffix ".nix" cfg.flake);
message = "nh.flake must be a directory, not a nix file";
}
];
environment = lib.mkIf cfg.enable {
systemPackages = [ cfg.package ];
variables = lib.mkIf (cfg.flake != null) {
FLAKE = cfg.flake;
};
};
systemd = lib.mkIf cfg.clean.enable {
services.nh-clean = {
description = "Nh clean";
script = "exec ${lib.getExe cfg.package} clean all ${cfg.clean.extraArgs}";
startAt = cfg.clean.dates;
path = [ config.nix.package ];
serviceConfig.Type = "oneshot";
};
timers.nh-clean = {
timerConfig = {
Persistent = true;
};
};
};
};
}