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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
{
hjemSubmodule,
_class,
}: {
lib,
pkgs,
config,
...
}: let
inherit (builtins) concatLists mapAttrs;
inherit (lib.attrsets) filterAttrs mapAttrsToList;
inherit (lib.lists) optional;
inherit (lib.options) literalExpression mkOption;
inherit (lib.types) attrs attrsWith bool deferredModule either listOf nullOr package singleLineStr;
cfg = config.hjem;
enabledUsers = filterAttrs (_: u: u.enable) cfg.users;
in {
inherit _class;
options.hjem = {
cli.package = mkOption {
type = package;
default = pkgs.callPackage ../../cli/package.nix {};
defaultText = literalExpression "pkgs.callPackage ../../cli/package.nix { }";
description = "The Hjem CLI package to use.";
};
clobberByDefault = mkOption {
type = bool;
default = false;
description = ''
The default override behaviour for files managed by Hjem.
While `true`, existing files will be overriden with new files on rebuild.
The behaviour may be modified per-user by setting {option}`hjem.users.<username>.clobberFiles`
to the desired value.
'';
};
users = mkOption {
default = {};
type = attrsWith {
elemType = hjemSubmodule;
placeholder = "username";
};
description = "Hjem-managed user configurations.";
};
extraModules = mkOption {
type = listOf deferredModule;
default = [];
description = ''
Additional modules to be evaluated as a part of the users module
inside {option}`config.hjem.users.<username>`. This can be used to
extend each user configuration with additional options.
'';
};
specialArgs = mkOption {
type = attrs;
default = {};
example = literalExpression "{ inherit inputs; }";
description = ''
Additional `specialArgs` are passed to Hjem, allowing extra arguments
to be passed down to to all imported modules.
'';
};
linker = mkOption {
type = nullOr package;
default = cfg.cli.package;
defaultText = literalExpression "config.hjem.cli.package";
description = ''
Package to use to link files.
By default, Hjem uses its own standalone CLI linker.
Setting this to `null` will use `systemd-tmpfiles`,
which is only supported on Linux.
Specifying a non-null package uses an external linker that is invoked
with Hjem-managed manifests.
'';
};
linkerOptions = mkOption {
type = either (listOf singleLineStr) attrs;
default = [];
description = ''
Additional linker configuration.
When using Hjem's built-in standalone linker, only `prefix` is consumed
from an attribute set.
::: {.note}
When using an external linker package, list values are forwarded as
linker arguments and attribute-set values are forwarded as
`--linker-opts <json-file>`.
:::
'';
};
};
config = {
users.users = (mapAttrs (_: v: {inherit (v) packages;})) enabledUsers;
assertions =
concatLists
(mapAttrsToList (user: config:
map ({
assertion,
message,
...
}: {
inherit assertion;
message = "${config.user} profile: ${message}";
})
config.assertions)
enabledUsers)
++ [
{
assertion = cfg.linker == null -> pkgs.stdenv.hostPlatform.isLinux;
message = "The systemd-tmpfiles linker is only supported on Linux; on other platforms, use the manifest linker.";
}
];
warnings =
concatLists
(mapAttrsToList (
user: v:
map (
warning: "${v.user} profile: ${warning}"
)
v.warnings
)
enabledUsers)
++ optional
(enabledUsers == {}) ''
You have imported hjem, but you have not enabled hjem for any users.
'';
};
}
|