-
-
Notifications
You must be signed in to change notification settings - Fork 12.7k
/
systemd.nix
41 lines (37 loc) · 1.14 KB
/
systemd.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
# This merges systemd support into the generic instance module.
{ lib, config, options, ... }:
let
inherit (lib) concatMapAttrs mkOption types;
dash = before: after:
# maybe add nice clever escaping?
if after == ""
then before
else "${before}-${after}";
in
{
# First half of the magic: mix systemd logic into the otherwise abstract services
options = {
services.abstract = mkOption {
type = types.lazyAttrsOf (types.submoduleWith { modules = [ ./instance/systemd.nix ]; });
};
};
# Second half of the magic: siphon units that were defined in isolation to the system
config = {
systemd.services =
concatMapAttrs
(abstractServiceName: abstractServiceConfig:
if abstractServiceConfig.enable
then
concatMapAttrs
(subServiceName: unitModule: {
"${dash abstractServiceName subServiceName}" = { ... }: {
imports = [ unitModule ];
};
})
abstractServiceConfig.systemd.services
else {})
config.services.abstract;
# systemd.sockets =
# ... same ...
};
}