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
|
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.ugit;
settingsFormat = pkgs.formats.json { };
name = "myapp";
configFile = settingsFormat.generate "${name}.json" (
lib.filterAttrsRecursive (_: v: v != null) cfg.settings
);
in
{
options.services.${name} = {
enable = lib.mkEnableOption name;
package = lib.mkOption {
type = lib.types.package;
description = "The ${name} package to use.";
};
settings = lib.mkOption {
type = lib.types.submodule {
# Pass one argument per @nix(import) name used by the schema.
options = import ./options.nix {
inherit lib;
profileLink = import ./profile-link.nix { inherit lib; };
};
};
default = { };
description = "${name} configuration, rendered to JSON and passed via --config.";
};
};
config = lib.mkIf cfg.enable {
systemd.services.${name} = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
ExecStart = "${cfg.package}/bin/${name} --config ${configFile}";
DynamicUser = true;
StateDirectory = name;
WorkingDirectory = "/var/lib/${name}";
};
};
};
}
|