mirror of
https://github.com/nix-community/home-manager.git
synced 2025-12-01 06:31:04 +01:00
From what I understand, the warning removed in this PR was incorrect. There shouldn't be any conflict between osConfig.nix.gc and programs.nh.clean as our home-manager service only cleans user profiles (which nix-collect-garbage does not do). In this scenario they should both work at the same time as they are cleaning two different things.
95 lines
2.4 KiB
Nix
95 lines
2.4 KiB
Nix
{
|
|
config,
|
|
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.singleLineStr;
|
|
default = null;
|
|
description = ''
|
|
The path that will be used for the {env}`FLAKE` environment variable.
|
|
|
|
{env}`FLAKE` is used by nh as the default flake for performing actions,
|
|
like {command}`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.
|
|
|
|
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.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.";
|
|
|
|
home = lib.mkIf cfg.enable {
|
|
packages = [ cfg.package ];
|
|
sessionVariables = lib.mkIf (cfg.flake != null) (
|
|
let
|
|
packageVersion = lib.getVersion cfg.package;
|
|
isVersion4OrHigher = lib.versionAtLeast packageVersion "4.0.0";
|
|
in
|
|
if isVersion4OrHigher then { NH_FLAKE = cfg.flake; } else { FLAKE = cfg.flake; }
|
|
);
|
|
};
|
|
|
|
systemd.user = lib.mkIf cfg.clean.enable {
|
|
services.nh-clean = {
|
|
Unit.Description = "Nh clean (user)";
|
|
|
|
Service = {
|
|
Type = "oneshot";
|
|
ExecStart = "${lib.getExe cfg.package} clean user ${cfg.clean.extraArgs}";
|
|
};
|
|
};
|
|
|
|
timers.nh-clean = {
|
|
Unit.Description = "Run nh clean";
|
|
|
|
Timer = {
|
|
OnCalendar = cfg.clean.dates;
|
|
Persistent = true;
|
|
};
|
|
|
|
Install.WantedBy = [ "timers.target" ];
|
|
};
|
|
};
|
|
};
|
|
}
|