-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathoptions.nix
283 lines (258 loc) · 6.95 KB
/
options.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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
{
config,
lib,
pkgs,
...
}:
with lib;
with lib.types;
let
ownerOptionsType = submodule (_: {
options = {
group = mkOption {
type = str;
description = "Group that will own the secret.";
default = "root";
};
user = mkOption {
type = str;
description = "User who will own the secret.";
default = "root";
};
};
});
keyOptionsType = submodule (_: {
options = {
destination = mkOption {
type = str;
description = "Remote path";
};
source = mkOption {
type = str;
description = "Local path";
};
owner = mkOption {
default = { };
type = ownerOptionsType;
description = ''
Owner of the secret.
'';
};
permissions = mkOption {
default = "0400";
type = str;
description = "Permissions expressed as octal.";
};
action = mkOption {
default = [ ];
type = listOf str;
description = "Action to perform on remote host after uploading secret.";
};
mkDirs = mkOption {
default = true;
type = bool;
description = ''
Whether to create parent directories to secret destination.
In particular, morph will execute `sudo mkdir -p -m 755 /path/to/secret/destination`
prior to moving the secret in place.
'';
};
uploadAt = mkOption {
default = "pre-activation";
type = enum [
"pre-activation"
"post-activation"
];
description = ''
When to upload the secret.
`pre-activation` (the default) will upload the secret and run any associated action prior to activating the system configuration.
`post-activation` will upload the secret and run any associated action after activating the system configuration.
'';
};
};
});
healthCheckType = submodule (_: {
options = {
cmd = mkOption {
type = listOf cmdHealthCheckType;
default = [ ];
description = "List of command health checks";
};
http = mkOption {
type = listOf httpHealthCheckType;
default = [ ];
description = "List of HTTP health checks";
};
};
});
httpHealthCheckType = types.submodule (_: {
options = {
description = mkOption {
type = str;
description = "Health check description";
};
host = mkOption {
type = nullOr str;
description = "Host name";
default = null;
#default = config.networking.hostName;
};
scheme = mkOption {
type = str;
description = "Scheme";
default = "http";
};
port = mkOption {
type = int;
description = "Port number";
};
path = mkOption {
type = path;
description = "HTTP request path";
default = "/";
};
headers = mkOption {
type = attrsOf str;
description = "HTTP request headers";
default = { };
};
period = mkOption {
type = int;
description = "Seconds between checks";
default = 2;
};
timeout = mkOption {
type = int;
description = "Timeout in seconds";
default = 5;
};
insecureSSL = mkOption {
type = bool;
description = "Ignore SSL errors";
default = false;
};
};
});
cmdHealthCheckType = types.submodule (_: {
options = {
description = mkOption {
type = str;
description = "Health check description";
};
cmd = mkOption {
type = nullOr (listOf str);
description = "Command to run as list";
default = null;
};
period = mkOption {
type = int;
description = "Seconds between checks";
default = 2;
};
timeout = mkOption {
type = int;
description = "Timeout in seconds";
default = 5;
};
};
});
in
{
options.deployment = {
targetHost = mkOption {
type = str;
default = "";
description = ''
The remote host used for deployment. If this is not set it will fallback to the deployments attribute name.
'';
};
targetPort = mkOption {
type = nullOr int;
default = null;
description = ''
The port number of remote host used for deployment.
'';
};
targetUser = mkOption {
type = str;
default = "";
description = ''
The remote user used for deployment. If this is not set it will fallback to the user specified in the
<literal>SSH_USER</literal> environment variable or use the current local user as a last resort.
'';
};
buildOnly = mkOption {
type = bool;
default = false;
description = ''
Set to true if the host will not be real or reachable.
This is useful for system configs used to build iso's, local testing etc.
Will make the following features unavailable for the host:
push, deploy, check-health, upload-secrets, exec
'';
};
substituteOnDestination = mkOption {
type = bool;
default = false;
description = ''
Sets the `--substitute-on-destination` flag on nix copy,
allowing for the deployment target to use substitutes.
See `nix copy --help`.
'';
};
secrets = mkOption {
default = { };
example = {
"nix-cache-signing-key" = {
source = "../secrets/very-secret.txt";
destination = "/var/secrets/very-secret.txt";
owner.user = "nginx";
owner.group = "root";
permissions = "0400"; # this is the default
action = [
"sudo"
"systemctl"
"reload"
"nginx.service"
]; # restart nginx after uploading the secret
};
};
type = attrsOf keyOptionsType;
description = ''
Attrset where each attribute describes a key to be copied via ssh
instead of through the Nix closure (keeping it out of the Nix store.)
'';
};
healthChecks = mkOption {
type = healthCheckType;
description = ''
Health check configuration.
'';
default = { };
};
preDeployChecks = mkOption {
type = healthCheckType;
description = ''
Pre-check configuration.
'';
default = { };
};
tags = mkOption {
type = listOf str;
default = [ ];
description = ''
Host tags.
'';
};
};
# Creates a txt-file that lists all system healthcheck commands
# The file will end up linked in /run/current-system along with
# all derived dependencies.
config.system.extraDependencies =
let
cmds = concatMap (h: h.cmd) (
config.deployment.preDeployChecks.cmd ++ config.deployment.healthChecks.cmd
);
in
[ (pkgs.writeText "healthcheck-commands.txt" (concatStringsSep "\n" cmds)) ];
}