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
|
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.horcrux;
pkg = pkgs.callPackage ./pkg.nix { inherit pkgs; };
jsonFormat = pkgs.formats.json { };
in
{
options.services.horcrux = {
enable = lib.mkEnableOption "Horcrux git mirroring";
package = lib.mkOption {
type = lib.types.package;
default = pkg;
description = "The horcrux package";
};
json = lib.mkOption {
type = lib.types.bool;
default = false;
description = "JSON logging";
};
debug = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Debug logging";
};
storage = lib.mkOption {
type = lib.types.str;
default = "/var/lib/horcrux";
description = "Storage for the mirror repos";
};
config = lib.mkOption {
type = lib.types.attrs;
default = { };
description = "Config contents";
};
};
config = lib.mkIf cfg.enable {
systemd.services.horcrux = {
description = "Horcrux git mirroring";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
path = [
pkgs.openssh
pkgs.git
];
serviceConfig = {
ExecStart =
let
finalConfig = cfg.config // {
inherit (cfg) storage;
};
configFile = pkgs.writeText "horcrux-config.jsonnet" (
builtins.readFile (jsonFormat.generate "horcrux-config" finalConfig)
);
args = [
"--config=${configFile}"
(lib.optionalString cfg.json "--json")
(lib.optionalString cfg.debug "--debug")
];
in
"${lib.getExe cfg.package} ${lib.concatStringsSep " " args}";
Restart = "always";
User = "horcrux";
Group = "horcrux";
StateDirectory = "horcrux";
};
};
users = {
users.horcrux = {
isSystemUser = true;
group = "horcrux";
};
groups.horcrux = { };
};
};
}
|