nixos/systemd-initrd: Remove unit options that don't work

This commit is contained in:
Janne Heß 2022-04-01 10:44:08 +02:00
parent 1e5261f31c
commit b7c62b8238
No known key found for this signature in database
GPG key ID: 69165158F05265DF
4 changed files with 300 additions and 188 deletions

View file

@ -273,9 +273,9 @@ in rec {
{ Conflicts = toString config.conflicts; } { Conflicts = toString config.conflicts; }
// optionalAttrs (config.requisite != []) // optionalAttrs (config.requisite != [])
{ Requisite = toString config.requisite; } { Requisite = toString config.requisite; }
// optionalAttrs (config.restartTriggers != []) // optionalAttrs (config ? restartTriggers && config.restartTriggers != [])
{ X-Restart-Triggers = toString config.restartTriggers; } { X-Restart-Triggers = toString config.restartTriggers; }
// optionalAttrs (config.reloadTriggers != []) // optionalAttrs (config ? reloadTriggers && config.reloadTriggers != [])
{ X-Reload-Triggers = toString config.reloadTriggers; } { X-Reload-Triggers = toString config.reloadTriggers; }
// optionalAttrs (config.description != "") { // optionalAttrs (config.description != "") {
Description = config.description; } Description = config.description; }
@ -291,36 +291,8 @@ in rec {
}; };
}; };
serviceConfig = { name, config, ... }: { serviceConfig = { config, ... }: {
config = mkMerge config.environment.PATH = mkIf (config.path != []) "${makeBinPath config.path}:${makeSearchPathOutput "bin" "sbin" config.path}";
[ {
environment.PATH = mkIf (config.path != []) "${makeBinPath config.path}:${makeSearchPathOutput "bin" "sbin" config.path}";
}
(mkIf (config ? preStart && config.preStart != "")
{ serviceConfig.ExecStartPre =
[ (makeJobScript "${name}-pre-start" config.preStart) ];
})
(mkIf (config ? script && config.script != "")
{ serviceConfig.ExecStart =
makeJobScript "${name}-start" config.script + " " + config.scriptArgs;
})
(mkIf (config ? postStart && config.postStart != "")
{ serviceConfig.ExecStartPost =
[ (makeJobScript "${name}-post-start" config.postStart) ];
})
(mkIf (config ? reload && config.reload != "")
{ serviceConfig.ExecReload =
makeJobScript "${name}-reload" config.reload;
})
(mkIf (config ? preStop && config.preStop != "")
{ serviceConfig.ExecStop =
makeJobScript "${name}-pre-stop" config.preStop;
})
(mkIf (config ? postStart && config.postStop != "")
{ serviceConfig.ExecStopPost =
makeJobScript "${name}-post-stop" config.postStop;
})
];
}; };
stage2ServiceConfig = { stage2ServiceConfig = {
@ -384,12 +356,12 @@ in rec {
# systemd max line length is now 1MiB # systemd max line length is now 1MiB
# https://github.com/systemd/systemd/commit/e6dde451a51dc5aaa7f4d98d39b8fe735f73d2af # https://github.com/systemd/systemd/commit/e6dde451a51dc5aaa7f4d98d39b8fe735f73d2af
in if stringLength s >= 1048576 then throw "The value of the environment variable ${n} in systemd service ${name}.service is too long." else s) (attrNames env)} in if stringLength s >= 1048576 then throw "The value of the environment variable ${n} in systemd service ${name}.service is too long." else s) (attrNames env)}
${if def.reloadIfChanged then '' ${if def ? reloadIfChanged && def.reloadIfChanged then ''
X-ReloadIfChanged=true X-ReloadIfChanged=true
'' else if !def.restartIfChanged then '' '' else if (def ? restartIfChanged && !def.restartIfChanged) then ''
X-RestartIfChanged=false X-RestartIfChanged=false
'' else ""} '' else ""}
${optionalString (!def.stopIfChanged) "X-StopIfChanged=false"} ${optionalString (def ? stopIfChanged && !def.stopIfChanged) "X-StopIfChanged=false"}
${attrsToSection def.serviceConfig} ${attrsToSection def.serviceConfig}
''; '';
}; };

View file

@ -11,20 +11,27 @@ rec {
config = { unit = mkDefault (systemdUtils.lib.makeUnit name config); }; config = { unit = mkDefault (systemdUtils.lib.makeUnit name config); };
})); }));
services = with types; attrsOf (submodule [ { options = serviceOptions; } unitConfig stage2ServiceConfig ]); services = with types; attrsOf (submodule [ stage2ServiceOptions unitConfig stage2ServiceConfig ]);
initrdServices = with types; attrsOf (submodule [ { options = serviceOptions; } unitConfig stage1ServiceConfig ]); initrdServices = with types; attrsOf (submodule [ stage1ServiceOptions unitConfig stage1ServiceConfig ]);
targets = with types; attrsOf (submodule [ { options = targetOptions; } unitConfig ]); targets = with types; attrsOf (submodule [ stage2CommonUnitOptions unitConfig ]);
initrdTargets = with types; attrsOf (submodule [ stage1CommonUnitOptions unitConfig ]);
sockets = with types; attrsOf (submodule [ { options = socketOptions; } unitConfig ]); sockets = with types; attrsOf (submodule [ stage2SocketOptions unitConfig ]);
initrdSockets = with types; attrsOf (submodule [ stage1SocketOptions unitConfig ]);
timers = with types; attrsOf (submodule [ { options = timerOptions; } unitConfig ]); timers = with types; attrsOf (submodule [ stage2TimerOptions unitConfig ]);
initrdTimers = with types; attrsOf (submodule [ stage1TimerOptions unitConfig ]);
paths = with types; attrsOf (submodule [ { options = pathOptions; } unitConfig ]); paths = with types; attrsOf (submodule [ stage2PathOptions unitConfig ]);
initrdPaths = with types; attrsOf (submodule [ stage1PathOptions unitConfig ]);
slices = with types; attrsOf (submodule [ { options = sliceOptions; } unitConfig ]); slices = with types; attrsOf (submodule [ stage2SliceOptions unitConfig ]);
initrdSlices = with types; attrsOf (submodule [ stage1SliceOptions unitConfig ]);
mounts = with types; listOf (submodule [ { options = mountOptions; } unitConfig mountConfig ]); mounts = with types; listOf (submodule [ stage2MountOptions unitConfig mountConfig ]);
initrdMounts = with types; listOf (submodule [ stage1MountOptions unitConfig mountConfig ]);
automounts = with types; listOf (submodule [ { options = automountOptions; } unitConfig automountConfig ]); automounts = with types; listOf (submodule [ stage2AutomountOptions unitConfig automountConfig ]);
initrdAutomounts = with types; attrsOf (submodule [ stage1AutomountOptions unitConfig automountConfig ]);
} }

View file

@ -94,7 +94,7 @@ in rec {
}; };
commonUnitOptions = sharedOptions // { commonUnitOptions = { options = (sharedOptions // {
description = mkOption { description = mkOption {
default = ""; default = "";
@ -191,27 +191,6 @@ in rec {
''; '';
}; };
restartTriggers = mkOption {
default = [];
type = types.listOf types.unspecified;
description = ''
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;
description = ''
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.
'';
};
onFailure = mkOption { onFailure = mkOption {
default = []; default = [];
type = types.listOf unitNameType; type = types.listOf unitNameType;
@ -239,10 +218,39 @@ in rec {
''; '';
}; };
}); };
stage2CommonUnitOptions = {
imports = [
commonUnitOptions
];
options = {
restartTriggers = mkOption {
default = [];
type = types.listOf types.unspecified;
description = ''
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;
description = ''
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.
'';
};
};
}; };
stage1CommonUnitOptions = commonUnitOptions;
serviceOptions = { options = {
serviceOptions = commonUnitOptions // {
environment = mkOption { environment = mkOption {
default = {}; default = {};
@ -276,121 +284,164 @@ in rec {
''; '';
}; };
script = mkOption { }; };
type = types.lines;
default = ""; stage2ServiceOptions = { name, config, ... }: {
description = "Shell commands executed as the service's main process."; imports = [
stage2CommonUnitOptions
serviceOptions
];
options = {
script = mkOption {
type = types.lines;
default = "";
description = "Shell commands executed as the service's main process.";
};
scriptArgs = mkOption {
type = types.str;
default = "";
description = "Arguments passed to the main process script.";
};
preStart = mkOption {
type = types.lines;
default = "";
description = ''
Shell commands executed before the service's main process
is started.
'';
};
postStart = mkOption {
type = types.lines;
default = "";
description = ''
Shell commands executed after the service's main process
is started.
'';
};
reload = mkOption {
type = types.lines;
default = "";
description = ''
Shell commands executed when the service's main process
is reloaded.
'';
};
preStop = mkOption {
type = types.lines;
default = "";
description = ''
Shell commands executed to stop the service.
'';
};
postStop = mkOption {
type = types.lines;
default = "";
description = ''
Shell commands executed after the service's main process
has exited.
'';
};
restartIfChanged = mkOption {
type = types.bool;
default = true;
description = ''
Whether the service should be restarted during a NixOS
configuration switch if its definition has changed.
'';
};
reloadIfChanged = mkOption {
type = types.bool;
default = false;
description = ''
Whether the service should be reloaded during a NixOS
configuration switch if its definition has changed. If
enabled, the value of <option>restartIfChanged</option> is
ignored.
This option should not be used anymore in favor of
<option>reloadTriggers</option> which allows more granular
control of when a service is reloaded and when a service
is restarted.
'';
};
stopIfChanged = mkOption {
type = types.bool;
default = true;
description = ''
If set, a changed unit is restarted by calling
<command>systemctl stop</command> in the old configuration,
then <command>systemctl start</command> in the new one.
Otherwise, it is restarted in a single step using
<command>systemctl restart</command> in the new configuration.
The latter is less correct because it runs the
<literal>ExecStop</literal> commands from the new
configuration.
'';
};
startAt = mkOption {
type = with types; either str (listOf str);
default = [];
example = "Sun 14:00:00";
description = ''
Automatically start this unit at the given date/time, which
must be in the format described in
<citerefentry><refentrytitle>systemd.time</refentrytitle>
<manvolnum>7</manvolnum></citerefentry>. This is equivalent
to adding a corresponding timer unit with
<option>OnCalendar</option> set to the value given here.
'';
apply = v: if isList v then v else [ v ];
};
}; };
scriptArgs = mkOption { config = mkMerge
type = types.str; [ (mkIf (config.preStart != "")
default = ""; { serviceConfig.ExecStartPre =
description = "Arguments passed to the main process script."; [ (makeJobScript "${name}-pre-start" config.preStart) ];
}; })
(mkIf (config.script != "")
preStart = mkOption { { serviceConfig.ExecStart =
type = types.lines; makeJobScript "${name}-start" config.script + " " + config.scriptArgs;
default = ""; })
description = '' (mkIf (config.postStart != "")
Shell commands executed before the service's main process { serviceConfig.ExecStartPost =
is started. [ (makeJobScript "${name}-post-start" config.postStart) ];
''; })
}; (mkIf (config.reload != "")
{ serviceConfig.ExecReload =
postStart = mkOption { makeJobScript "${name}-reload" config.reload;
type = types.lines; })
default = ""; (mkIf (config.preStop != "")
description = '' { serviceConfig.ExecStop =
Shell commands executed after the service's main process makeJobScript "${name}-pre-stop" config.preStop;
is started. })
''; (mkIf (config.postStop != "")
}; { serviceConfig.ExecStopPost =
makeJobScript "${name}-post-stop" config.postStop;
reload = mkOption { })
type = types.lines; ];
default = ""; };
description = ''
Shell commands executed when the service's main process
is reloaded.
'';
};
preStop = mkOption {
type = types.lines;
default = "";
description = ''
Shell commands executed to stop the service.
'';
};
postStop = mkOption {
type = types.lines;
default = "";
description = ''
Shell commands executed after the service's main process
has exited.
'';
};
restartIfChanged = mkOption {
type = types.bool;
default = true;
description = ''
Whether the service should be restarted during a NixOS
configuration switch if its definition has changed.
'';
};
reloadIfChanged = mkOption {
type = types.bool;
default = false;
description = ''
Whether the service should be reloaded during a NixOS
configuration switch if its definition has changed. If
enabled, the value of <option>restartIfChanged</option> is
ignored.
This option should not be used anymore in favor of
<option>reloadTriggers</option> which allows more granular
control of when a service is reloaded and when a service
is restarted.
'';
};
stopIfChanged = mkOption {
type = types.bool;
default = true;
description = ''
If set, a changed unit is restarted by calling
<command>systemctl stop</command> in the old configuration,
then <command>systemctl start</command> in the new one.
Otherwise, it is restarted in a single step using
<command>systemctl restart</command> in the new configuration.
The latter is less correct because it runs the
<literal>ExecStop</literal> commands from the new
configuration.
'';
};
startAt = mkOption {
type = with types; either str (listOf str);
default = [];
example = "Sun 14:00:00";
description = ''
Automatically start this unit at the given date/time, which
must be in the format described in
<citerefentry><refentrytitle>systemd.time</refentrytitle>
<manvolnum>7</manvolnum></citerefentry>. This is equivalent
to adding a corresponding timer unit with
<option>OnCalendar</option> set to the value given here.
'';
apply = v: if isList v then v else [ v ];
};
stage1ServiceOptions = {
imports = [
stage1CommonUnitOptions
serviceOptions
];
}; };
socketOptions = commonUnitOptions // { socketOptions = { options = {
listenStreams = mkOption { listenStreams = mkOption {
default = []; default = [];
@ -424,10 +475,24 @@ in rec {
''; '';
}; };
}; };
stage2SocketOptions = {
imports = [
stage2CommonUnitOptions
socketOptions
];
};
stage1SocketOptions = {
imports = [
stage1CommonUnitOptions
socketOptions
];
}; };
timerOptions = commonUnitOptions // { timerOptions = { options = {
timerConfig = mkOption { timerConfig = mkOption {
default = {}; default = {};
@ -443,10 +508,24 @@ in rec {
''; '';
}; };
}; };
stage2TimerOptions = {
imports = [
stage2CommonUnitOptions
timerOptions
];
};
stage1TimerOptions = {
imports = [
stage1CommonUnitOptions
timerOptions
];
}; };
pathOptions = commonUnitOptions // { pathOptions = { options = {
pathConfig = mkOption { pathConfig = mkOption {
default = {}; default = {};
@ -460,10 +539,24 @@ in rec {
''; '';
}; };
}; };
stage2PathOptions = {
imports = [
stage2CommonUnitOptions
pathOptions
];
};
stage1PathOptions = {
imports = [
stage1CommonUnitOptions
pathOptions
];
}; };
mountOptions = commonUnitOptions // { mountOptions = { options = {
what = mkOption { what = mkOption {
example = "/dev/sda1"; example = "/dev/sda1";
@ -505,9 +598,23 @@ in rec {
<manvolnum>5</manvolnum></citerefentry> for details. <manvolnum>5</manvolnum></citerefentry> for details.
''; '';
}; };
}; };
stage2MountOptions = {
imports = [
stage2CommonUnitOptions
mountOptions
];
}; };
automountOptions = commonUnitOptions // { stage1MountOptions = {
imports = [
stage1CommonUnitOptions
mountOptions
];
};
automountOptions = { options = {
where = mkOption { where = mkOption {
example = "/mnt"; example = "/mnt";
@ -529,11 +636,23 @@ in rec {
<manvolnum>5</manvolnum></citerefentry> for details. <manvolnum>5</manvolnum></citerefentry> for details.
''; '';
}; };
}; };
stage2AutomountOptions = {
imports = [
stage2CommonUnitOptions
automountOptions
];
}; };
targetOptions = commonUnitOptions; stage1AutomountOptions = {
imports = [
stage1CommonUnitOptions
automountOptions
];
};
sliceOptions = commonUnitOptions // { sliceOptions = { options = {
sliceConfig = mkOption { sliceConfig = mkOption {
default = {}; default = {};
@ -547,6 +666,20 @@ in rec {
''; '';
}; };
}; };
stage2SliceOptions = {
imports = [
stage2CommonUnitOptions
sliceOptions
];
};
stage1SliceOptions = {
imports = [
stage1CommonUnitOptions
sliceOptions
];
}; };
} }

View file

@ -231,7 +231,7 @@ in {
targets = mkOption { targets = mkOption {
default = {}; default = {};
visible = false; visible = false;
type = systemdUtils.types.targets; type = systemdUtils.types.initrdTargets;
description = "Definition of systemd target units."; description = "Definition of systemd target units.";
}; };
@ -244,28 +244,28 @@ in {
sockets = mkOption { sockets = mkOption {
default = {}; default = {};
type = systemdUtils.types.sockets; type = systemdUtils.types.initrdSockets;
visible = false; visible = false;
description = "Definition of systemd socket units."; description = "Definition of systemd socket units.";
}; };
timers = mkOption { timers = mkOption {
default = {}; default = {};
type = systemdUtils.types.timers; type = systemdUtils.types.initrdTimers;
visible = false; visible = false;
description = "Definition of systemd timer units."; description = "Definition of systemd timer units.";
}; };
paths = mkOption { paths = mkOption {
default = {}; default = {};
type = systemdUtils.types.paths; type = systemdUtils.types.initrdPaths;
visible = false; visible = false;
description = "Definition of systemd path units."; description = "Definition of systemd path units.";
}; };
mounts = mkOption { mounts = mkOption {
default = []; default = [];
type = systemdUtils.types.mounts; type = systemdUtils.types.initrdMounts;
visible = false; visible = false;
description = '' description = ''
Definition of systemd mount units. Definition of systemd mount units.