diff options
Diffstat (limited to 'modules/networkd/systemd-unit-options.nix')
-rw-r--r-- | modules/networkd/systemd-unit-options.nix | 536 |
1 files changed, 536 insertions, 0 deletions
diff --git a/modules/networkd/systemd-unit-options.nix b/modules/networkd/systemd-unit-options.nix new file mode 100644 index 00000000..4154389b --- /dev/null +++ b/modules/networkd/systemd-unit-options.nix | |||
@@ -0,0 +1,536 @@ | |||
1 | { config, lib }: | ||
2 | |||
3 | with lib; | ||
4 | with import ./systemd-lib.nix { inherit config lib pkgs; }; | ||
5 | |||
6 | let | ||
7 | checkService = checkUnitConfig "Service" [ | ||
8 | (assertValueOneOf "Type" [ | ||
9 | "exec" "simple" "forking" "oneshot" "dbus" "notify" "idle" | ||
10 | ]) | ||
11 | (assertValueOneOf "Restart" [ | ||
12 | "no" "on-success" "on-failure" "on-abnormal" "on-abort" "always" | ||
13 | ]) | ||
14 | ]; | ||
15 | |||
16 | in rec { | ||
17 | |||
18 | unitOption = mkOptionType { | ||
19 | name = "systemd option"; | ||
20 | merge = loc: defs: | ||
21 | let | ||
22 | defs' = filterOverrides defs; | ||
23 | defs'' = getValues defs'; | ||
24 | in | ||
25 | if isList (head defs'') | ||
26 | then concatLists defs'' | ||
27 | else mergeEqualOption loc defs'; | ||
28 | }; | ||
29 | |||
30 | sharedOptions = { | ||
31 | |||
32 | enable = mkOption { | ||
33 | default = true; | ||
34 | type = types.bool; | ||
35 | description = '' | ||
36 | If set to false, this unit will be a symlink to | ||
37 | /dev/null. This is primarily useful to prevent specific | ||
38 | template instances | ||
39 | (e.g. <literal>serial-getty@ttyS0</literal>) from being | ||
40 | started. Note that <literal>enable=true</literal> does not | ||
41 | make a unit start by default at boot; if you want that, see | ||
42 | <literal>wantedBy</literal>. | ||
43 | ''; | ||
44 | }; | ||
45 | |||
46 | requiredBy = mkOption { | ||
47 | default = []; | ||
48 | type = types.listOf types.str; | ||
49 | description = '' | ||
50 | Units that require (i.e. depend on and need to go down with) | ||
51 | this unit. The discussion under <literal>wantedBy</literal> | ||
52 | applies here as well: inverse <literal>.requires</literal> | ||
53 | symlinks are established. | ||
54 | ''; | ||
55 | }; | ||
56 | |||
57 | wantedBy = mkOption { | ||
58 | default = []; | ||
59 | type = types.listOf types.str; | ||
60 | description = '' | ||
61 | Units that want (i.e. depend on) this unit. The standard way | ||
62 | to make a unit start by default at boot is to set this option | ||
63 | to <literal>[ "multi-user.target" ]</literal>. That's despite | ||
64 | the fact that the systemd.unit(5) manpage says this option | ||
65 | goes in the <literal>[Install]</literal> section that controls | ||
66 | the behaviour of <literal>systemctl enable</literal>. Since | ||
67 | such a process is stateful and thus contrary to the design of | ||
68 | NixOS, setting this option instead causes the equivalent | ||
69 | inverse <literal>.wants</literal> symlink to be present, | ||
70 | establishing the same desired relationship in a stateless way. | ||
71 | ''; | ||
72 | }; | ||
73 | |||
74 | aliases = mkOption { | ||
75 | default = []; | ||
76 | type = types.listOf types.str; | ||
77 | description = "Aliases of that unit."; | ||
78 | }; | ||
79 | |||
80 | }; | ||
81 | |||
82 | concreteUnitOptions = sharedOptions // { | ||
83 | |||
84 | text = mkOption { | ||
85 | type = types.nullOr types.str; | ||
86 | default = null; | ||
87 | description = "Text of this systemd unit."; | ||
88 | }; | ||
89 | |||
90 | unit = mkOption { | ||
91 | internal = true; | ||
92 | description = "The generated unit."; | ||
93 | }; | ||
94 | |||
95 | }; | ||
96 | |||
97 | commonUnitOptions = sharedOptions // { | ||
98 | |||
99 | description = mkOption { | ||
100 | default = ""; | ||
101 | type = types.str; | ||
102 | description = "Description of this unit used in systemd messages and progress indicators."; | ||
103 | }; | ||
104 | |||
105 | documentation = mkOption { | ||
106 | default = []; | ||
107 | type = types.listOf types.str; | ||
108 | description = "A list of URIs referencing documentation for this unit or its configuration."; | ||
109 | }; | ||
110 | |||
111 | requires = mkOption { | ||
112 | default = []; | ||
113 | type = types.listOf types.str; | ||
114 | description = '' | ||
115 | Start the specified units when this unit is started, and stop | ||
116 | this unit when the specified units are stopped or fail. | ||
117 | ''; | ||
118 | }; | ||
119 | |||
120 | wants = mkOption { | ||
121 | default = []; | ||
122 | type = types.listOf types.str; | ||
123 | description = '' | ||
124 | Start the specified units when this unit is started. | ||
125 | ''; | ||
126 | }; | ||
127 | |||
128 | after = mkOption { | ||
129 | default = []; | ||
130 | type = types.listOf types.str; | ||
131 | description = '' | ||
132 | If the specified units are started at the same time as | ||
133 | this unit, delay this unit until they have started. | ||
134 | ''; | ||
135 | }; | ||
136 | |||
137 | before = mkOption { | ||
138 | default = []; | ||
139 | type = types.listOf types.str; | ||
140 | description = '' | ||
141 | If the specified units are started at the same time as | ||
142 | this unit, delay them until this unit has started. | ||
143 | ''; | ||
144 | }; | ||
145 | |||
146 | bindsTo = mkOption { | ||
147 | default = []; | ||
148 | type = types.listOf types.str; | ||
149 | description = '' | ||
150 | Like ‘requires’, but in addition, if the specified units | ||
151 | unexpectedly disappear, this unit will be stopped as well. | ||
152 | ''; | ||
153 | }; | ||
154 | |||
155 | partOf = mkOption { | ||
156 | default = []; | ||
157 | type = types.listOf types.str; | ||
158 | description = '' | ||
159 | If the specified units are stopped or restarted, then this | ||
160 | unit is stopped or restarted as well. | ||
161 | ''; | ||
162 | }; | ||
163 | |||
164 | conflicts = mkOption { | ||
165 | default = []; | ||
166 | type = types.listOf types.str; | ||
167 | description = '' | ||
168 | If the specified units are started, then this unit is stopped | ||
169 | and vice versa. | ||
170 | ''; | ||
171 | }; | ||
172 | |||
173 | requisite = mkOption { | ||
174 | default = []; | ||
175 | type = types.listOf types.str; | ||
176 | description = '' | ||
177 | Similar to requires. However if the units listed are not started, | ||
178 | they will not be started and the transaction will fail. | ||
179 | ''; | ||
180 | }; | ||
181 | |||
182 | unitConfig = mkOption { | ||
183 | default = {}; | ||
184 | example = { RequiresMountsFor = "/data"; }; | ||
185 | type = types.attrsOf unitOption; | ||
186 | description = '' | ||
187 | Each attribute in this set specifies an option in the | ||
188 | <literal>[Unit]</literal> section of the unit. See | ||
189 | <citerefentry><refentrytitle>systemd.unit</refentrytitle> | ||
190 | <manvolnum>5</manvolnum></citerefentry> for details. | ||
191 | ''; | ||
192 | }; | ||
193 | |||
194 | restartTriggers = mkOption { | ||
195 | default = []; | ||
196 | type = types.listOf types.unspecified; | ||
197 | description = '' | ||
198 | An arbitrary list of items such as derivations. If any item | ||
199 | in the list changes between reconfigurations, the service will | ||
200 | be restarted. | ||
201 | ''; | ||
202 | }; | ||
203 | |||
204 | onFailure = mkOption { | ||
205 | default = []; | ||
206 | type = types.listOf types.str; | ||
207 | description = '' | ||
208 | A list of one or more units that are activated when | ||
209 | this unit enters the "failed" state. | ||
210 | ''; | ||
211 | }; | ||
212 | |||
213 | startLimitBurst = mkOption { | ||
214 | type = types.int; | ||
215 | description = '' | ||
216 | Configure unit start rate limiting. Units which are started | ||
217 | more than startLimitBurst times within an interval time | ||
218 | interval are not permitted to start any more. | ||
219 | ''; | ||
220 | }; | ||
221 | |||
222 | startLimitIntervalSec = mkOption { | ||
223 | type = types.int; | ||
224 | description = '' | ||
225 | Configure unit start rate limiting. Units which are started | ||
226 | more than startLimitBurst times within an interval time | ||
227 | interval are not permitted to start any more. | ||
228 | ''; | ||
229 | }; | ||
230 | |||
231 | }; | ||
232 | |||
233 | |||
234 | serviceOptions = commonUnitOptions // { | ||
235 | |||
236 | environment = mkOption { | ||
237 | default = {}; | ||
238 | type = with types; attrsOf (nullOr (oneOf [ str path package ])); | ||
239 | example = { PATH = "/foo/bar/bin"; LANG = "nl_NL.UTF-8"; }; | ||
240 | description = "Environment variables passed to the service's processes."; | ||
241 | }; | ||
242 | |||
243 | path = mkOption { | ||
244 | default = []; | ||
245 | type = with types; listOf (oneOf [ package str ]); | ||
246 | description = '' | ||
247 | Packages added to the service's <envar>PATH</envar> | ||
248 | environment variable. Both the <filename>bin</filename> | ||
249 | and <filename>sbin</filename> subdirectories of each | ||
250 | package are added. | ||
251 | ''; | ||
252 | }; | ||
253 | |||
254 | serviceConfig = mkOption { | ||
255 | default = {}; | ||
256 | example = | ||
257 | { RestartSec = 5; | ||
258 | }; | ||
259 | type = types.addCheck (types.attrsOf unitOption) checkService; | ||
260 | description = '' | ||
261 | Each attribute in this set specifies an option in the | ||
262 | <literal>[Service]</literal> section of the unit. See | ||
263 | <citerefentry><refentrytitle>systemd.service</refentrytitle> | ||
264 | <manvolnum>5</manvolnum></citerefentry> for details. | ||
265 | ''; | ||
266 | }; | ||
267 | |||
268 | script = mkOption { | ||
269 | type = types.lines; | ||
270 | default = ""; | ||
271 | description = "Shell commands executed as the service's main process."; | ||
272 | }; | ||
273 | |||
274 | scriptArgs = mkOption { | ||
275 | type = types.str; | ||
276 | default = ""; | ||
277 | description = "Arguments passed to the main process script."; | ||
278 | }; | ||
279 | |||
280 | preStart = mkOption { | ||
281 | type = types.lines; | ||
282 | default = ""; | ||
283 | description = '' | ||
284 | Shell commands executed before the service's main process | ||
285 | is started. | ||
286 | ''; | ||
287 | }; | ||
288 | |||
289 | postStart = mkOption { | ||
290 | type = types.lines; | ||
291 | default = ""; | ||
292 | description = '' | ||
293 | Shell commands executed after the service's main process | ||
294 | is started. | ||
295 | ''; | ||
296 | }; | ||
297 | |||
298 | reload = mkOption { | ||
299 | type = types.lines; | ||
300 | default = ""; | ||
301 | description = '' | ||
302 | Shell commands executed when the service's main process | ||
303 | is reloaded. | ||
304 | ''; | ||
305 | }; | ||
306 | |||
307 | preStop = mkOption { | ||
308 | type = types.lines; | ||
309 | default = ""; | ||
310 | description = '' | ||
311 | Shell commands executed to stop the service. | ||
312 | ''; | ||
313 | }; | ||
314 | |||
315 | postStop = mkOption { | ||
316 | type = types.lines; | ||
317 | default = ""; | ||
318 | description = '' | ||
319 | Shell commands executed after the service's main process | ||
320 | has exited. | ||
321 | ''; | ||
322 | }; | ||
323 | |||
324 | restartIfChanged = mkOption { | ||
325 | type = types.bool; | ||
326 | default = true; | ||
327 | description = '' | ||
328 | Whether the service should be restarted during a NixOS | ||
329 | configuration switch if its definition has changed. | ||
330 | ''; | ||
331 | }; | ||
332 | |||
333 | reloadIfChanged = mkOption { | ||
334 | type = types.bool; | ||
335 | default = false; | ||
336 | description = '' | ||
337 | Whether the service should be reloaded during a NixOS | ||
338 | configuration switch if its definition has changed. If | ||
339 | enabled, the value of <option>restartIfChanged</option> is | ||
340 | ignored. | ||
341 | ''; | ||
342 | }; | ||
343 | |||
344 | stopIfChanged = mkOption { | ||
345 | type = types.bool; | ||
346 | default = true; | ||
347 | description = '' | ||
348 | If set, a changed unit is restarted by calling | ||
349 | <command>systemctl stop</command> in the old configuration, | ||
350 | then <command>systemctl start</command> in the new one. | ||
351 | Otherwise, it is restarted in a single step using | ||
352 | <command>systemctl restart</command> in the new configuration. | ||
353 | The latter is less correct because it runs the | ||
354 | <literal>ExecStop</literal> commands from the new | ||
355 | configuration. | ||
356 | ''; | ||
357 | }; | ||
358 | |||
359 | startAt = mkOption { | ||
360 | type = with types; either str (listOf str); | ||
361 | default = []; | ||
362 | example = "Sun 14:00:00"; | ||
363 | description = '' | ||
364 | Automatically start this unit at the given date/time, which | ||
365 | must be in the format described in | ||
366 | <citerefentry><refentrytitle>systemd.time</refentrytitle> | ||
367 | <manvolnum>7</manvolnum></citerefentry>. This is equivalent | ||
368 | to adding a corresponding timer unit with | ||
369 | <option>OnCalendar</option> set to the value given here. | ||
370 | ''; | ||
371 | apply = v: if isList v then v else [ v ]; | ||
372 | }; | ||
373 | |||
374 | }; | ||
375 | |||
376 | |||
377 | socketOptions = commonUnitOptions // { | ||
378 | |||
379 | listenStreams = mkOption { | ||
380 | default = []; | ||
381 | type = types.listOf types.str; | ||
382 | example = [ "0.0.0.0:993" "/run/my-socket" ]; | ||
383 | description = '' | ||
384 | For each item in this list, a <literal>ListenStream</literal> | ||
385 | option in the <literal>[Socket]</literal> section will be created. | ||
386 | ''; | ||
387 | }; | ||
388 | |||
389 | listenDatagrams = mkOption { | ||
390 | default = []; | ||
391 | type = types.listOf types.str; | ||
392 | example = [ "0.0.0.0:993" "/run/my-socket" ]; | ||
393 | description = '' | ||
394 | For each item in this list, a <literal>ListenDatagram</literal> | ||
395 | option in the <literal>[Socket]</literal> section will be created. | ||
396 | ''; | ||
397 | }; | ||
398 | |||
399 | socketConfig = mkOption { | ||
400 | default = {}; | ||
401 | example = { ListenStream = "/run/my-socket"; }; | ||
402 | type = types.attrsOf unitOption; | ||
403 | description = '' | ||
404 | Each attribute in this set specifies an option in the | ||
405 | <literal>[Socket]</literal> section of the unit. See | ||
406 | <citerefentry><refentrytitle>systemd.socket</refentrytitle> | ||
407 | <manvolnum>5</manvolnum></citerefentry> for details. | ||
408 | ''; | ||
409 | }; | ||
410 | |||
411 | }; | ||
412 | |||
413 | |||
414 | timerOptions = commonUnitOptions // { | ||
415 | |||
416 | timerConfig = mkOption { | ||
417 | default = {}; | ||
418 | example = { OnCalendar = "Sun 14:00:00"; Unit = "foo.service"; }; | ||
419 | type = types.attrsOf unitOption; | ||
420 | description = '' | ||
421 | Each attribute in this set specifies an option in the | ||
422 | <literal>[Timer]</literal> section of the unit. See | ||
423 | <citerefentry><refentrytitle>systemd.timer</refentrytitle> | ||
424 | <manvolnum>5</manvolnum></citerefentry> and | ||
425 | <citerefentry><refentrytitle>systemd.time</refentrytitle> | ||
426 | <manvolnum>7</manvolnum></citerefentry> for details. | ||
427 | ''; | ||
428 | }; | ||
429 | |||
430 | }; | ||
431 | |||
432 | |||
433 | pathOptions = commonUnitOptions // { | ||
434 | |||
435 | pathConfig = mkOption { | ||
436 | default = {}; | ||
437 | example = { PathChanged = "/some/path"; Unit = "changedpath.service"; }; | ||
438 | type = types.attrsOf unitOption; | ||
439 | description = '' | ||
440 | Each attribute in this set specifies an option in the | ||
441 | <literal>[Path]</literal> section of the unit. See | ||
442 | <citerefentry><refentrytitle>systemd.path</refentrytitle> | ||
443 | <manvolnum>5</manvolnum></citerefentry> for details. | ||
444 | ''; | ||
445 | }; | ||
446 | |||
447 | }; | ||
448 | |||
449 | |||
450 | mountOptions = commonUnitOptions // { | ||
451 | |||
452 | what = mkOption { | ||
453 | example = "/dev/sda1"; | ||
454 | type = types.str; | ||
455 | description = "Absolute path of device node, file or other resource. (Mandatory)"; | ||
456 | }; | ||
457 | |||
458 | where = mkOption { | ||
459 | example = "/mnt"; | ||
460 | type = types.str; | ||
461 | description = '' | ||
462 | Absolute path of a directory of the mount point. | ||
463 | Will be created if it doesn't exist. (Mandatory) | ||
464 | ''; | ||
465 | }; | ||
466 | |||
467 | type = mkOption { | ||
468 | default = ""; | ||
469 | example = "ext4"; | ||
470 | type = types.str; | ||
471 | description = "File system type."; | ||
472 | }; | ||
473 | |||
474 | options = mkOption { | ||
475 | default = ""; | ||
476 | example = "noatime"; | ||
477 | type = types.commas; | ||
478 | description = "Options used to mount the file system."; | ||
479 | }; | ||
480 | |||
481 | mountConfig = mkOption { | ||
482 | default = {}; | ||
483 | example = { DirectoryMode = "0775"; }; | ||
484 | type = types.attrsOf unitOption; | ||
485 | description = '' | ||
486 | Each attribute in this set specifies an option in the | ||
487 | <literal>[Mount]</literal> section of the unit. See | ||
488 | <citerefentry><refentrytitle>systemd.mount</refentrytitle> | ||
489 | <manvolnum>5</manvolnum></citerefentry> for details. | ||
490 | ''; | ||
491 | }; | ||
492 | }; | ||
493 | |||
494 | automountOptions = commonUnitOptions // { | ||
495 | |||
496 | where = mkOption { | ||
497 | example = "/mnt"; | ||
498 | type = types.str; | ||
499 | description = '' | ||
500 | Absolute path of a directory of the mount point. | ||
501 | Will be created if it doesn't exist. (Mandatory) | ||
502 | ''; | ||
503 | }; | ||
504 | |||
505 | automountConfig = mkOption { | ||
506 | default = {}; | ||
507 | example = { DirectoryMode = "0775"; }; | ||
508 | type = types.attrsOf unitOption; | ||
509 | description = '' | ||
510 | Each attribute in this set specifies an option in the | ||
511 | <literal>[Automount]</literal> section of the unit. See | ||
512 | <citerefentry><refentrytitle>systemd.automount</refentrytitle> | ||
513 | <manvolnum>5</manvolnum></citerefentry> for details. | ||
514 | ''; | ||
515 | }; | ||
516 | }; | ||
517 | |||
518 | targetOptions = commonUnitOptions; | ||
519 | |||
520 | sliceOptions = commonUnitOptions // { | ||
521 | |||
522 | sliceConfig = mkOption { | ||
523 | default = {}; | ||
524 | example = { MemoryMax = "2G"; }; | ||
525 | type = types.attrsOf unitOption; | ||
526 | description = '' | ||
527 | Each attribute in this set specifies an option in the | ||
528 | <literal>[Slice]</literal> section of the unit. See | ||
529 | <citerefentry><refentrytitle>systemd.slice</refentrytitle> | ||
530 | <manvolnum>5</manvolnum></citerefentry> for details. | ||
531 | ''; | ||
532 | }; | ||
533 | |||
534 | }; | ||
535 | |||
536 | } | ||