forked from ToyVo/nh_plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
home-manager-module.nix
67 lines (58 loc) · 2.08 KB
/
home-manager-module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 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;
nh_darwin = self.packages.${pkgs.stdenv.hostPlatform.system}.nh_darwin;
nh = pkgs.callPackage ./alias.nix { nh_darwin = cfg.package; };
in
{
meta.maintainers = with lib.maintainers; [ johnrtitor ];
options.programs.nh = {
enable = lib.mkEnableOption "nh_darwin, yet another Nix CLI helper. Works on NixOS, NixDarwin, and HomeManager Standalone";
package = lib.mkPackageOption pkgs "nh" { } // {
default = nh_darwin;
};
alias = lib.mkEnableOption "Enable alias of nh_darwin to nh";
os.flake = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = ''
The path that will be used for the `NH_OS_FLAKE` environment variable.
`NH_OS_FLAKE` is used by nh_darwin as the default flake for performing actions on NixOS/nix-darwin, like `nh_darwin os switch`.
'';
};
home.flake = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = ''
The path that will be used for the `NH_HOME_FLAKE` environment variable.
`NH_HOME_FLAKE` is used by nh_darwin as the default flake for performing actions on home-manager, like `nh_darwin home switch`.
'';
};
};
config = {
assertions = [
{
assertion = (cfg.os.flake != null) -> !(lib.hasSuffix ".nix" cfg.os.flake);
message = "nh.os.flake must be a directory, not a nix file";
}
{
assertion = (cfg.home.flake != null) -> !(lib.hasSuffix ".nix" cfg.home.flake);
message = "nh.home.flake must be a directory, not a nix file";
}
];
home = lib.mkIf cfg.enable {
packages = [ cfg.package ] ++ lib.optionals (cfg.alias) [ nh ];
sessionVariables = lib.mkMerge [
(lib.mkIf (cfg.os.flake != null) { NH_OS_FLAKE = cfg.os.flake; })
(lib.mkIf (cfg.home.flake != null) { NH_HOME_FLAKE = cfg.home.flake; })
];
};
};
}