forked from viperML/nh
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
239 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
self:{ config | ||
, lib | ||
, pkgs | ||
, ... | ||
}: | ||
let | ||
cfg = config.programs.nh; | ||
in | ||
{ | ||
meta.maintainers = [ lib.maintainers.ToyVo ]; | ||
|
||
options.programs.nh = { | ||
enable = lib.mkEnableOption "nh, yet another Nix CLI helper"; | ||
|
||
package = lib.mkPackageOption pkgs "nh" { } // { | ||
default = self.packages.${pkgs.stdenv.hostPlatform.system}.default; | ||
}; | ||
|
||
flake = lib.mkOption { | ||
type = lib.types.nullOr lib.types.path; | ||
default = null; | ||
description = '' | ||
The path that will be used for the `NH_FLAKE` environment variable. | ||
`NH_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"; | ||
|
||
# Not in NixOS module | ||
user = lib.mkOption { | ||
type = lib.types.nullOr lib.types.str; | ||
default = null; | ||
description = "User that runs the garbage collector."; | ||
}; | ||
|
||
interval = lib.mkOption { | ||
type = lib.types.attrs; | ||
default = { Weekday = 0; }; | ||
description = '' | ||
How often cleanup is performed. Passed to launchd.StartCalendarInterval | ||
The format is described in | ||
{manpage}`crontab(5)`. | ||
''; | ||
}; | ||
|
||
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"; | ||
} | ||
]; | ||
|
||
nixpkgs.overlays = [ self.overlays.default ]; | ||
|
||
environment = lib.mkIf cfg.enable { | ||
systemPackages = [ cfg.package ]; | ||
variables = lib.mkIf (cfg.flake != null) { | ||
NH_FLAKE = cfg.flake; | ||
}; | ||
}; | ||
|
||
launchd = lib.mkIf cfg.clean.enable { | ||
daemons.nh-clean = { | ||
command = "exec ${lib.getExe cfg.package} clean all ${cfg.clean.extraArgs}"; | ||
environment.NIX_REMOTE = lib.optionalString config.nix.useDaemon "daemon"; | ||
serviceConfig.RunAtLoad = false; | ||
serviceConfig.StartCalendarInterval = [ cfg.clean.interval ]; | ||
serviceConfig.UserName = cfg.clean.user; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Notice: this file will only exist until this pr is merged https://github.com/nix-community/home-manager/pull/5304 | ||
self: { 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" { } // { | ||
default = self.packages.${pkgs.stdenv.hostPlatform.system}.default; | ||
}; | ||
|
||
flake = lib.mkOption { | ||
type = lib.types.nullOr lib.types.path; | ||
default = null; | ||
description = '' | ||
The path that will be used for the `NH_FLAKE` environment variable. | ||
`NH_FLAKE` is used by nh as the default flake for performing actions, like `nh os switch`. | ||
''; | ||
}; | ||
}; | ||
|
||
config = { | ||
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) { NH_FLAKE = cfg.flake; }; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
self: { config, pkgs, lib, ... }: | ||
{ | ||
config = { | ||
nixpkgs.overlays = [ self.overlays.default ]; | ||
programs.nh.package = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.default; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters