2021-11-20 17:34:13 +00:00
|
|
|
|
{ lib, systemdUtils }:
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2013-10-30 14:33:20 +00:00
|
|
|
|
let
|
2024-03-28 05:00:34 +00:00
|
|
|
|
inherit (systemdUtils.lib)
|
|
|
|
|
assertValueOneOf
|
|
|
|
|
automountConfig
|
|
|
|
|
checkUnitConfig
|
|
|
|
|
makeJobScript
|
|
|
|
|
mountConfig
|
|
|
|
|
serviceConfig
|
|
|
|
|
unitConfig
|
|
|
|
|
unitNameType
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
inherit (lib)
|
|
|
|
|
any
|
|
|
|
|
concatMap
|
|
|
|
|
filterOverrides
|
|
|
|
|
isList
|
|
|
|
|
mergeEqualOption
|
|
|
|
|
mkIf
|
|
|
|
|
mkMerge
|
|
|
|
|
mkOption
|
|
|
|
|
mkOptionType
|
|
|
|
|
singleton
|
|
|
|
|
toList
|
|
|
|
|
types
|
|
|
|
|
;
|
|
|
|
|
|
2014-11-20 09:41:05 +00:00
|
|
|
|
checkService = checkUnitConfig "Service" [
|
|
|
|
|
(assertValueOneOf "Type" [
|
2024-02-14 16:52:13 +00:00
|
|
|
|
"exec" "simple" "forking" "oneshot" "dbus" "notify" "notify-reload" "idle"
|
2014-11-20 09:41:05 +00:00
|
|
|
|
])
|
|
|
|
|
(assertValueOneOf "Restart" [
|
2015-01-19 10:41:18 +00:00
|
|
|
|
"no" "on-success" "on-failure" "on-abnormal" "on-abort" "always"
|
2014-11-20 09:41:05 +00:00
|
|
|
|
])
|
|
|
|
|
];
|
|
|
|
|
|
2015-04-19 20:05:12 +01:00
|
|
|
|
in rec {
|
2013-10-30 14:33:20 +00:00
|
|
|
|
|
2013-11-18 14:45:24 +00:00
|
|
|
|
unitOption = mkOptionType {
|
|
|
|
|
name = "systemd option";
|
2016-03-01 19:47:08 +00:00
|
|
|
|
merge = loc: defs:
|
2013-11-18 14:51:21 +00:00
|
|
|
|
let
|
|
|
|
|
defs' = filterOverrides defs;
|
2013-11-18 14:45:24 +00:00
|
|
|
|
in
|
2024-02-18 12:20:40 +00:00
|
|
|
|
if any (def: isList def.value) defs'
|
|
|
|
|
then concatMap (def: toList def.value) defs'
|
2019-11-08 15:45:44 +00:00
|
|
|
|
else mergeEqualOption loc defs';
|
2013-11-18 14:45:24 +00:00
|
|
|
|
};
|
|
|
|
|
|
2014-04-17 22:35:05 +01:00
|
|
|
|
sharedOptions = {
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2012-10-29 20:01:36 +00:00
|
|
|
|
enable = mkOption {
|
|
|
|
|
default = true;
|
2013-10-28 14:12:11 +00:00
|
|
|
|
type = types.bool;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2012-10-29 20:01:36 +00:00
|
|
|
|
If set to false, this unit will be a symlink to
|
|
|
|
|
/dev/null. This is primarily useful to prevent specific
|
2017-09-16 11:48:16 +01:00
|
|
|
|
template instances
|
|
|
|
|
(e.g. `serial-getty@ttyS0`) from being
|
|
|
|
|
started. Note that `enable=true` does not
|
|
|
|
|
make a unit start by default at boot; if you want that, see
|
|
|
|
|
`wantedBy`.
|
2012-10-29 20:01:36 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-21 13:52:12 +00:00
|
|
|
|
name = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
description = ''
|
|
|
|
|
The name of this systemd unit, including its extension.
|
|
|
|
|
This can be used to refer to this unit from other systemd units.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-06 21:29:56 +01:00
|
|
|
|
overrideStrategy = mkOption {
|
|
|
|
|
default = "asDropinIfExists";
|
|
|
|
|
type = types.enum [ "asDropinIfExists" "asDropin" ];
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-08-06 21:29:56 +01:00
|
|
|
|
Defines how unit configuration is provided for systemd:
|
|
|
|
|
|
|
|
|
|
`asDropinIfExists` creates a unit file when no unit file is provided by the package
|
|
|
|
|
otherwise a drop-in file name `overrides.conf`.
|
|
|
|
|
|
|
|
|
|
`asDropin` creates a drop-in file named `overrides.conf`.
|
|
|
|
|
Mainly needed to define instances for systemd template units (e.g. `systemd-nspawn@mycontainer.service`).
|
|
|
|
|
|
2022-12-31 11:19:48 +00:00
|
|
|
|
See also {manpage}`systemd.unit(5)`.
|
2022-08-06 21:29:56 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-17 22:35:05 +01:00
|
|
|
|
requiredBy = mkOption {
|
|
|
|
|
default = [];
|
2021-12-27 12:00:00 +00:00
|
|
|
|
type = types.listOf unitNameType;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-11-02 07:03:22 +00:00
|
|
|
|
Units that require (i.e. depend on and need to go down with) this unit.
|
|
|
|
|
As discussed in the `wantedBy` option description this also creates
|
|
|
|
|
`.requires` symlinks automatically.
|
2017-09-16 11:48:16 +01:00
|
|
|
|
'';
|
2014-04-17 22:35:05 +01:00
|
|
|
|
};
|
|
|
|
|
|
2024-02-10 11:43:31 +00:00
|
|
|
|
upheldBy = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf unitNameType;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2024-02-10 11:43:31 +00:00
|
|
|
|
Keep this unit running as long as the listed units are running. This is a continuously
|
|
|
|
|
enforced version of wantedBy.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-17 22:35:05 +01:00
|
|
|
|
wantedBy = mkOption {
|
|
|
|
|
default = [];
|
2021-12-27 12:00:00 +00:00
|
|
|
|
type = types.listOf unitNameType;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-11-02 07:03:22 +00:00
|
|
|
|
Units that want (i.e. depend on) this unit. The default method for
|
|
|
|
|
starting a unit by default at boot time is to set this option to
|
2023-05-18 17:04:31 +01:00
|
|
|
|
`["multi-user.target"]` for system services. Likewise for user units
|
2022-11-02 07:03:22 +00:00
|
|
|
|
(`systemd.user.<name>.*`) set it to `["default.target"]` to make a unit
|
|
|
|
|
start by default when the user `<name>` logs on.
|
|
|
|
|
|
|
|
|
|
This option creates a `.wants` symlink in the given target that exists
|
|
|
|
|
statelessly without the need for running `systemctl enable`.
|
2022-12-31 11:19:48 +00:00
|
|
|
|
The `[Install]` section described in {manpage}`systemd.unit(5)` however is
|
2022-11-02 07:03:22 +00:00
|
|
|
|
not supported because it is a stateful process that does not fit well
|
|
|
|
|
into the NixOS design.
|
2017-09-16 11:48:16 +01:00
|
|
|
|
'';
|
2014-04-17 22:35:05 +01:00
|
|
|
|
};
|
|
|
|
|
|
2017-02-01 21:51:16 +00:00
|
|
|
|
aliases = mkOption {
|
|
|
|
|
default = [];
|
2021-12-27 12:00:00 +00:00
|
|
|
|
type = types.listOf unitNameType;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = "Aliases of that unit.";
|
2017-02-01 21:51:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
2014-04-17 22:35:05 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
concreteUnitOptions = sharedOptions // {
|
|
|
|
|
|
|
|
|
|
text = mkOption {
|
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = null;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = "Text of this systemd unit.";
|
2014-04-17 22:35:05 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
unit = mkOption {
|
|
|
|
|
internal = true;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = "The generated unit.";
|
2014-04-17 22:35:05 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
commonUnitOptions = {
|
|
|
|
|
options = sharedOptions // {
|
2014-04-17 22:35:05 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
description = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
type = types.singleLineStr;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = "Description of this unit used in systemd messages and progress indicators.";
|
2022-04-04 11:48:13 +01:00
|
|
|
|
};
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
documentation = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf types.str;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = "A list of URIs referencing documentation for this unit or its configuration.";
|
2022-04-04 11:48:13 +01:00
|
|
|
|
};
|
2016-04-27 03:56:40 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
requires = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf unitNameType;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Start the specified units when this unit is started, and stop
|
|
|
|
|
this unit when the specified units are stopped or fail.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
wants = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf unitNameType;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Start the specified units when this unit is started.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2024-02-10 11:43:31 +00:00
|
|
|
|
upholds = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf unitNameType;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2024-02-10 20:25:24 +00:00
|
|
|
|
Keeps the specified running while this unit is running. A continuous version of `wants`.
|
2024-02-10 11:43:31 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
after = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf unitNameType;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
If the specified units are started at the same time as
|
|
|
|
|
this unit, delay this unit until they have started.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
before = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf unitNameType;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
If the specified units are started at the same time as
|
|
|
|
|
this unit, delay them until this unit has started.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
bindsTo = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf unitNameType;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Like ‘requires’, but in addition, if the specified units
|
|
|
|
|
unexpectedly disappear, this unit will be stopped as well.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2012-10-10 21:50:41 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
partOf = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf unitNameType;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
If the specified units are stopped or restarted, then this
|
|
|
|
|
unit is stopped or restarted as well.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2012-08-15 20:36:54 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
conflicts = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf unitNameType;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
If the specified units are started, then this unit is stopped
|
|
|
|
|
and vice versa.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2013-09-22 20:04:54 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
requisite = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf unitNameType;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Similar to requires. However if the units listed are not started,
|
|
|
|
|
they will not be started and the transaction will fail.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2014-11-19 21:11:30 +00:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
unitConfig = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
example = { RequiresMountsFor = "/data"; };
|
|
|
|
|
type = types.attrsOf unitOption;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Each attribute in this set specifies an option in the
|
|
|
|
|
`[Unit]` section of the unit. See
|
2022-08-29 15:51:16 +01:00
|
|
|
|
{manpage}`systemd.unit(5)` for details.
|
2022-04-04 11:48:13 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
2012-10-01 23:58:11 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
onFailure = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf unitNameType;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
A list of one or more units that are activated when
|
|
|
|
|
this unit enters the "failed" state.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2015-11-16 14:07:10 +00:00
|
|
|
|
|
2022-04-07 12:21:58 +01:00
|
|
|
|
onSuccess = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf unitNameType;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-07 12:21:58 +01:00
|
|
|
|
A list of one or more units that are activated when
|
|
|
|
|
this unit enters the "inactive" state.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
startLimitBurst = mkOption {
|
|
|
|
|
type = types.int;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Configure unit start rate limiting. Units which are started
|
|
|
|
|
more than startLimitBurst times within an interval time
|
|
|
|
|
interval are not permitted to start any more.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2020-09-09 08:31:27 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
startLimitIntervalSec = mkOption {
|
|
|
|
|
type = types.int;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Configure unit start rate limiting. Units which are started
|
|
|
|
|
more than startLimitBurst times within an interval time
|
|
|
|
|
interval are not permitted to start any more.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2018-11-20 17:34:43 +00:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
};
|
|
|
|
|
};
|
2022-04-01 09:44:08 +01:00
|
|
|
|
|
|
|
|
|
stage2CommonUnitOptions = {
|
|
|
|
|
imports = [
|
|
|
|
|
commonUnitOptions
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
restartTriggers = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf types.unspecified;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-01 09:44:08 +01:00
|
|
|
|
An arbitrary list of items such as derivations. If any item
|
|
|
|
|
in the list changes between reconfigurations, the service will
|
|
|
|
|
be restarted.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
reloadTriggers = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf unitOption;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-01 09:44:08 +01:00
|
|
|
|
An arbitrary list of items such as derivations. If any item
|
|
|
|
|
in the list changes between reconfigurations, the service will
|
|
|
|
|
be reloaded. If anything but a reload trigger changes in the
|
|
|
|
|
unit file, the unit will be restarted instead.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
};
|
2012-10-01 23:58:11 +01:00
|
|
|
|
};
|
2022-04-01 09:44:08 +01:00
|
|
|
|
stage1CommonUnitOptions = commonUnitOptions;
|
2012-10-01 23:58:11 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
serviceOptions = { name, config, ... }: {
|
|
|
|
|
options = {
|
2012-10-01 23:58:11 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
environment = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
type = with types; attrsOf (nullOr (oneOf [ str path package ]));
|
|
|
|
|
example = { PATH = "/foo/bar/bin"; LANG = "nl_NL.UTF-8"; };
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = "Environment variables passed to the service's processes.";
|
2022-04-04 11:48:13 +01:00
|
|
|
|
};
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
path = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = with types; listOf (oneOf [ package str ]);
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Packages added to the service's {env}`PATH`
|
|
|
|
|
environment variable. Both the {file}`bin`
|
|
|
|
|
and {file}`sbin` subdirectories of each
|
|
|
|
|
package are added.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
serviceConfig = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
example =
|
|
|
|
|
{ RestartSec = 5;
|
|
|
|
|
};
|
|
|
|
|
type = types.addCheck (types.attrsOf unitOption) checkService;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Each attribute in this set specifies an option in the
|
|
|
|
|
`[Service]` section of the unit. See
|
2022-08-29 15:51:16 +01:00
|
|
|
|
{manpage}`systemd.service(5)` for details.
|
2022-04-04 11:48:13 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
script = mkOption {
|
|
|
|
|
type = types.lines;
|
|
|
|
|
default = "";
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = "Shell commands executed as the service's main process.";
|
2022-04-04 11:48:13 +01:00
|
|
|
|
};
|
2022-04-01 09:44:08 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
scriptArgs = mkOption {
|
|
|
|
|
type = types.str;
|
|
|
|
|
default = "";
|
2022-12-22 14:17:05 +00:00
|
|
|
|
example = "%i";
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-12-22 14:17:05 +00:00
|
|
|
|
Arguments passed to the main process script.
|
|
|
|
|
Can contain specifiers (`%` placeholders expanded by systemd, see {manpage}`systemd.unit(5)`).
|
|
|
|
|
'';
|
2022-04-04 11:48:13 +01:00
|
|
|
|
};
|
2022-04-01 09:44:08 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
preStart = mkOption {
|
|
|
|
|
type = types.lines;
|
|
|
|
|
default = "";
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Shell commands executed before the service's main process
|
|
|
|
|
is started.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2022-04-01 09:44:08 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
postStart = mkOption {
|
|
|
|
|
type = types.lines;
|
|
|
|
|
default = "";
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Shell commands executed after the service's main process
|
|
|
|
|
is started.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2022-04-01 09:44:08 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
reload = mkOption {
|
|
|
|
|
type = types.lines;
|
|
|
|
|
default = "";
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Shell commands executed when the service's main process
|
|
|
|
|
is reloaded.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2022-04-01 09:44:08 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
preStop = mkOption {
|
|
|
|
|
type = types.lines;
|
|
|
|
|
default = "";
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Shell commands executed to stop the service.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2022-04-01 09:44:08 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
postStop = mkOption {
|
|
|
|
|
type = types.lines;
|
|
|
|
|
default = "";
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Shell commands executed after the service's main process
|
|
|
|
|
has exited.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2022-04-01 09:44:08 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
jobScripts = mkOption {
|
|
|
|
|
type = with types; coercedTo path singleton (listOf path);
|
|
|
|
|
internal = true;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = "A list of all job script derivations of this unit.";
|
2022-04-04 11:48:13 +01:00
|
|
|
|
default = [];
|
|
|
|
|
};
|
2022-04-01 09:44:08 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
};
|
2022-04-04 10:04:45 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
config = mkMerge [
|
|
|
|
|
(mkIf (config.preStart != "") rec {
|
|
|
|
|
jobScripts = makeJobScript "${name}-pre-start" config.preStart;
|
|
|
|
|
serviceConfig.ExecStartPre = [ jobScripts ];
|
|
|
|
|
})
|
|
|
|
|
(mkIf (config.script != "") rec {
|
|
|
|
|
jobScripts = makeJobScript "${name}-start" config.script;
|
|
|
|
|
serviceConfig.ExecStart = jobScripts + " " + config.scriptArgs;
|
|
|
|
|
})
|
|
|
|
|
(mkIf (config.postStart != "") rec {
|
|
|
|
|
jobScripts = (makeJobScript "${name}-post-start" config.postStart);
|
|
|
|
|
serviceConfig.ExecStartPost = [ jobScripts ];
|
|
|
|
|
})
|
|
|
|
|
(mkIf (config.reload != "") rec {
|
|
|
|
|
jobScripts = makeJobScript "${name}-reload" config.reload;
|
|
|
|
|
serviceConfig.ExecReload = jobScripts;
|
|
|
|
|
})
|
|
|
|
|
(mkIf (config.preStop != "") rec {
|
|
|
|
|
jobScripts = makeJobScript "${name}-pre-stop" config.preStop;
|
|
|
|
|
serviceConfig.ExecStop = jobScripts;
|
|
|
|
|
})
|
|
|
|
|
(mkIf (config.postStop != "") rec {
|
|
|
|
|
jobScripts = makeJobScript "${name}-post-stop" config.postStop;
|
|
|
|
|
serviceConfig.ExecStopPost = jobScripts;
|
|
|
|
|
})
|
|
|
|
|
];
|
2022-04-04 10:04:45 +01:00
|
|
|
|
|
|
|
|
|
};
|
2022-04-01 09:44:08 +01:00
|
|
|
|
|
2022-04-04 10:04:45 +01:00
|
|
|
|
stage2ServiceOptions = {
|
|
|
|
|
imports = [
|
|
|
|
|
stage2CommonUnitOptions
|
|
|
|
|
serviceOptions
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
options = {
|
2022-04-01 09:44:08 +01:00
|
|
|
|
restartIfChanged = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = true;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-01 09:44:08 +01:00
|
|
|
|
Whether the service should be restarted during a NixOS
|
|
|
|
|
configuration switch if its definition has changed.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
reloadIfChanged = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-01 09:44:08 +01:00
|
|
|
|
Whether the service should be reloaded during a NixOS
|
|
|
|
|
configuration switch if its definition has changed. If
|
|
|
|
|
enabled, the value of {option}`restartIfChanged` is
|
|
|
|
|
ignored.
|
|
|
|
|
|
|
|
|
|
This option should not be used anymore in favor of
|
|
|
|
|
{option}`reloadTriggers` which allows more granular
|
|
|
|
|
control of when a service is reloaded and when a service
|
|
|
|
|
is restarted.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
stopIfChanged = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = true;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-01 09:44:08 +01:00
|
|
|
|
If set, a changed unit is restarted by calling
|
|
|
|
|
{command}`systemctl stop` in the old configuration,
|
|
|
|
|
then {command}`systemctl start` in the new one.
|
|
|
|
|
Otherwise, it is restarted in a single step using
|
|
|
|
|
{command}`systemctl restart` in the new configuration.
|
|
|
|
|
The latter is less correct because it runs the
|
|
|
|
|
`ExecStop` commands from the new
|
|
|
|
|
configuration.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
startAt = mkOption {
|
|
|
|
|
type = with types; either str (listOf str);
|
|
|
|
|
default = [];
|
|
|
|
|
example = "Sun 14:00:00";
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-01 09:44:08 +01:00
|
|
|
|
Automatically start this unit at the given date/time, which
|
|
|
|
|
must be in the format described in
|
2022-08-29 15:51:16 +01:00
|
|
|
|
{manpage}`systemd.time(7)`. This is equivalent
|
2022-04-01 09:44:08 +01:00
|
|
|
|
to adding a corresponding timer unit with
|
|
|
|
|
{option}`OnCalendar` set to the value given here.
|
|
|
|
|
'';
|
|
|
|
|
apply = v: if isList v then v else [ v ];
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
2013-10-09 13:28:35 +01:00
|
|
|
|
|
2022-04-01 09:44:08 +01:00
|
|
|
|
stage1ServiceOptions = {
|
|
|
|
|
imports = [
|
|
|
|
|
stage1CommonUnitOptions
|
|
|
|
|
serviceOptions
|
|
|
|
|
];
|
2012-08-06 16:45:59 +01:00
|
|
|
|
};
|
|
|
|
|
|
2012-10-09 20:14:15 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
socketOptions = {
|
|
|
|
|
options = {
|
2012-10-09 20:14:15 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
listenStreams = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf types.str;
|
|
|
|
|
example = [ "0.0.0.0:993" "/run/my-socket" ];
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
For each item in this list, a `ListenStream`
|
|
|
|
|
option in the `[Socket]` section will be created.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2013-05-14 15:07:55 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
listenDatagrams = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf types.str;
|
|
|
|
|
example = [ "0.0.0.0:993" "/run/my-socket" ];
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
For each item in this list, a `ListenDatagram`
|
|
|
|
|
option in the `[Socket]` section will be created.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2020-08-11 22:46:39 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
socketConfig = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
example = { ListenStream = "/run/my-socket"; };
|
|
|
|
|
type = types.attrsOf unitOption;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Each attribute in this set specifies an option in the
|
|
|
|
|
`[Socket]` section of the unit. See
|
2022-08-29 15:51:16 +01:00
|
|
|
|
{manpage}`systemd.socket(5)` for details.
|
2022-04-04 11:48:13 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
2012-10-09 20:14:15 +01:00
|
|
|
|
};
|
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
};
|
2022-04-01 09:44:08 +01:00
|
|
|
|
|
|
|
|
|
stage2SocketOptions = {
|
|
|
|
|
imports = [
|
|
|
|
|
stage2CommonUnitOptions
|
|
|
|
|
socketOptions
|
|
|
|
|
];
|
2012-10-09 20:14:15 +01:00
|
|
|
|
};
|
|
|
|
|
|
2022-04-01 09:44:08 +01:00
|
|
|
|
stage1SocketOptions = {
|
|
|
|
|
imports = [
|
|
|
|
|
stage1CommonUnitOptions
|
|
|
|
|
socketOptions
|
|
|
|
|
];
|
|
|
|
|
};
|
2013-03-02 00:03:13 +00:00
|
|
|
|
|
2022-04-01 09:44:08 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
timerOptions = {
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
|
|
timerConfig = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
example = { OnCalendar = "Sun 14:00:00"; Unit = "foo.service"; };
|
|
|
|
|
type = types.attrsOf unitOption;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Each attribute in this set specifies an option in the
|
|
|
|
|
`[Timer]` section of the unit. See
|
2022-08-29 15:51:16 +01:00
|
|
|
|
{manpage}`systemd.timer(5)` and
|
|
|
|
|
{manpage}`systemd.time(7)` for details.
|
2022-04-04 11:48:13 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
2013-03-02 00:03:13 +00:00
|
|
|
|
|
|
|
|
|
};
|
2022-04-04 11:48:13 +01:00
|
|
|
|
};
|
2022-04-01 09:44:08 +01:00
|
|
|
|
|
|
|
|
|
stage2TimerOptions = {
|
|
|
|
|
imports = [
|
|
|
|
|
stage2CommonUnitOptions
|
|
|
|
|
timerOptions
|
|
|
|
|
];
|
2013-03-02 00:03:13 +00:00
|
|
|
|
};
|
|
|
|
|
|
2022-04-01 09:44:08 +01:00
|
|
|
|
stage1TimerOptions = {
|
|
|
|
|
imports = [
|
|
|
|
|
stage1CommonUnitOptions
|
|
|
|
|
timerOptions
|
|
|
|
|
];
|
|
|
|
|
};
|
2013-03-02 00:03:13 +00:00
|
|
|
|
|
2022-04-01 09:44:08 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
pathOptions = {
|
|
|
|
|
options = {
|
2014-03-31 11:23:27 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
pathConfig = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
example = { PathChanged = "/some/path"; Unit = "changedpath.service"; };
|
|
|
|
|
type = types.attrsOf unitOption;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Each attribute in this set specifies an option in the
|
|
|
|
|
`[Path]` section of the unit. See
|
2022-08-29 15:51:16 +01:00
|
|
|
|
{manpage}`systemd.path(5)` for details.
|
2022-04-04 11:48:13 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
2014-03-31 11:23:27 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
};
|
|
|
|
|
};
|
2022-04-01 09:44:08 +01:00
|
|
|
|
|
|
|
|
|
stage2PathOptions = {
|
|
|
|
|
imports = [
|
|
|
|
|
stage2CommonUnitOptions
|
|
|
|
|
pathOptions
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
stage1PathOptions = {
|
|
|
|
|
imports = [
|
|
|
|
|
stage1CommonUnitOptions
|
|
|
|
|
pathOptions
|
|
|
|
|
];
|
2014-03-31 11:23:27 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
mountOptions = {
|
|
|
|
|
options = {
|
2012-12-28 12:29:53 +00:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
what = mkOption {
|
|
|
|
|
example = "/dev/sda1";
|
|
|
|
|
type = types.str;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = "Absolute path of device node, file or other resource. (Mandatory)";
|
2022-04-04 11:48:13 +01:00
|
|
|
|
};
|
2012-12-28 12:29:53 +00:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
where = mkOption {
|
|
|
|
|
example = "/mnt";
|
|
|
|
|
type = types.str;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Absolute path of a directory of the mount point.
|
|
|
|
|
Will be created if it doesn't exist. (Mandatory)
|
|
|
|
|
'';
|
|
|
|
|
};
|
2012-12-28 12:29:53 +00:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
type = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
example = "ext4";
|
|
|
|
|
type = types.str;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = "File system type.";
|
2022-04-04 11:48:13 +01:00
|
|
|
|
};
|
2012-12-28 12:29:53 +00:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
options = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
example = "noatime";
|
|
|
|
|
type = types.commas;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = "Options used to mount the file system.";
|
2022-04-04 11:48:13 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
mountConfig = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
example = { DirectoryMode = "0775"; };
|
|
|
|
|
type = types.attrsOf unitOption;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Each attribute in this set specifies an option in the
|
|
|
|
|
`[Mount]` section of the unit. See
|
2022-08-29 15:51:16 +01:00
|
|
|
|
{manpage}`systemd.mount(5)` for details.
|
2022-04-04 11:48:13 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
2012-12-28 12:29:53 +00:00
|
|
|
|
|
|
|
|
|
};
|
2022-04-04 11:48:13 +01:00
|
|
|
|
};
|
2022-04-01 09:44:08 +01:00
|
|
|
|
|
|
|
|
|
stage2MountOptions = {
|
|
|
|
|
imports = [
|
|
|
|
|
stage2CommonUnitOptions
|
|
|
|
|
mountOptions
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
stage1MountOptions = {
|
|
|
|
|
imports = [
|
|
|
|
|
stage1CommonUnitOptions
|
|
|
|
|
mountOptions
|
|
|
|
|
];
|
2012-12-28 12:29:53 +00:00
|
|
|
|
};
|
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
automountOptions = {
|
|
|
|
|
options = {
|
2013-09-23 21:56:05 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
where = mkOption {
|
|
|
|
|
example = "/mnt";
|
|
|
|
|
type = types.str;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Absolute path of a directory of the mount point.
|
|
|
|
|
Will be created if it doesn't exist. (Mandatory)
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
automountConfig = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
example = { DirectoryMode = "0775"; };
|
|
|
|
|
type = types.attrsOf unitOption;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Each attribute in this set specifies an option in the
|
|
|
|
|
`[Automount]` section of the unit. See
|
2022-08-29 15:51:16 +01:00
|
|
|
|
{manpage}`systemd.automount(5)` for details.
|
2022-04-04 11:48:13 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
2013-09-23 21:56:05 +01:00
|
|
|
|
|
|
|
|
|
};
|
2022-04-04 11:48:13 +01:00
|
|
|
|
};
|
2022-04-01 09:44:08 +01:00
|
|
|
|
|
|
|
|
|
stage2AutomountOptions = {
|
|
|
|
|
imports = [
|
|
|
|
|
stage2CommonUnitOptions
|
|
|
|
|
automountOptions
|
|
|
|
|
];
|
2013-09-23 21:56:05 +01:00
|
|
|
|
};
|
|
|
|
|
|
2022-04-01 09:44:08 +01:00
|
|
|
|
stage1AutomountOptions = {
|
|
|
|
|
imports = [
|
|
|
|
|
stage1CommonUnitOptions
|
|
|
|
|
automountOptions
|
|
|
|
|
];
|
|
|
|
|
};
|
2014-04-17 22:35:05 +01:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
sliceOptions = {
|
|
|
|
|
options = {
|
2016-12-20 06:21:52 +00:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
sliceConfig = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
example = { MemoryMax = "2G"; };
|
|
|
|
|
type = types.attrsOf unitOption;
|
2024-04-02 00:58:23 +01:00
|
|
|
|
description = ''
|
2022-04-04 11:48:13 +01:00
|
|
|
|
Each attribute in this set specifies an option in the
|
|
|
|
|
`[Slice]` section of the unit. See
|
2022-08-29 15:51:16 +01:00
|
|
|
|
{manpage}`systemd.slice(5)` for details.
|
2022-04-04 11:48:13 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
2016-12-20 06:21:52 +00:00
|
|
|
|
|
2022-04-04 11:48:13 +01:00
|
|
|
|
};
|
|
|
|
|
};
|
2022-04-01 09:44:08 +01:00
|
|
|
|
|
|
|
|
|
stage2SliceOptions = {
|
|
|
|
|
imports = [
|
|
|
|
|
stage2CommonUnitOptions
|
|
|
|
|
sliceOptions
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
stage1SliceOptions = {
|
|
|
|
|
imports = [
|
|
|
|
|
stage1CommonUnitOptions
|
|
|
|
|
sliceOptions
|
|
|
|
|
];
|
2016-12-20 06:21:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-02-15 02:50:41 +00:00
|
|
|
|
}
|