blob: 2709fbb885ba37189a007ffaa12218015fe229e2 (
plain)
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
147
148
|
{
config,
pkgs,
lib,
...
}:
let
cfg = config.services.olivetin;
settingsFormat = pkgs.formats.yaml { };
in
{
meta.maintainers = with lib.maintainers; [ defelo ];
options.services.olivetin = {
enable = lib.mkEnableOption "OliveTin";
package = lib.mkOption {
type = lib.types.package;
description = "The olivetin package to use.";
default =
if lib.versionAtLeast config.system.stateVersion "26.05" then pkgs.olivetin-3k else pkgs.olivetin;
defaultText = lib.literalExpression ''
if lib.versionAtLeast config.system.stateVersion "26.05"
then pkgs.olivetin-3k
else pkgs.olivetin
'';
};
user = lib.mkOption {
type = lib.types.str;
description = "The user account under which OliveTin runs.";
default = "olivetin";
};
group = lib.mkOption {
type = lib.types.str;
description = "The group under which OliveTin runs.";
default = "olivetin";
};
path = lib.mkOption {
type =
with lib.types;
listOf (oneOf [
package
str
]);
description = ''
Packages added to the service's {env}`PATH`.
'';
defaultText = lib.literalExpression ''
with pkgs; [ bash ]
'';
};
settings = lib.mkOption {
description = ''
Configuration of OliveTin. See <https://docs.olivetin.app/config.html> for more information.
'';
default = { };
type = lib.types.submodule {
freeformType = settingsFormat.type;
options = {
ListenAddressSingleHTTPFrontend = lib.mkOption {
type = lib.types.str;
description = ''
The address to listen on for the internal "microproxy" frontend.
'';
default = "127.0.0.1:8000";
example = "0.0.0.0:8000";
};
};
};
};
extraConfigFiles = lib.mkOption {
type = lib.types.listOf lib.types.path;
default = [ ];
example = [ "/run/secrets/olivetin.yaml" ];
description = ''
Config files to merge into the settings defined in [](#opt-services.olivetin.settings).
This is useful to avoid putting secrets into the nix store.
See <https://docs.olivetin.app/config.html> for more information.
'';
};
};
config = lib.mkIf cfg.enable {
services.olivetin = {
path = with pkgs; [ bash ];
};
systemd.services.olivetin = {
description = "OliveTin";
wantedBy = [ "multi-user.target" ];
wants = [
"network-online.target"
"local-fs.target"
];
after = [
"network-online.target"
"local-fs.target"
];
inherit (cfg) path;
preStart = ''
shopt -s nullglob
tmp="$(mktemp)"
${lib.getExe pkgs.yq-go} eval-all '. as $item ireduce ({}; . *+ $item)' \
${settingsFormat.generate "olivetin-config.yaml" cfg.settings} \
$CREDENTIALS_DIRECTORY/config-*.yaml > "$tmp"
chmod -w "$tmp"
mkdir -p /run/olivetin/config
mv "$tmp" /run/olivetin/config/config.yaml
'';
serviceConfig = {
User = cfg.user;
Group = cfg.group;
RuntimeDirectory = "olivetin";
Restart = "always";
LoadCredential = lib.imap0 (i: path: "config-${toString i}.yaml:${path}") cfg.extraConfigFiles;
ExecStart = "${lib.getExe cfg.package} -configdir /run/olivetin/config";
};
};
users.users = lib.mkIf (cfg.user == "olivetin") {
olivetin = {
group = cfg.group;
isSystemUser = true;
};
};
users.groups = lib.mkIf (cfg.group == "olivetin") { olivetin = { }; };
};
}
|