Strictly check the arguments to mkOption
And fix various instances of bad arguments.
This commit is contained in:
@@ -2,7 +2,19 @@
|
||||
|
||||
with pkgs.lib;
|
||||
|
||||
rec {
|
||||
let
|
||||
|
||||
checkService = v:
|
||||
let assertValueOneOf = name: values: attr:
|
||||
let val = getAttr name attr;
|
||||
in optional ( hasAttr name attr && !elem val values) "Systemd service field `${name}' cannot have value `${val}'.";
|
||||
checkType = assertValueOneOf "Type" ["simple" "forking" "oneshot" "dbus" "notify" "idle"];
|
||||
checkRestart = assertValueOneOf "Restart" ["no" "on-success" "on-failure" "on-abort" "always"];
|
||||
errors = concatMap (c: c v) [checkType checkRestart];
|
||||
in if errors == [] then true
|
||||
else builtins.trace (concatStringsSep "\n" errors) false;
|
||||
|
||||
in rec {
|
||||
|
||||
unitOptions = {
|
||||
|
||||
@@ -147,23 +159,13 @@ rec {
|
||||
{ StartLimitInterval = 10;
|
||||
RestartSec = 5;
|
||||
};
|
||||
type = types.attrs;
|
||||
type = types.addCheck types.attrs checkService;
|
||||
description = ''
|
||||
Each attribute in this set specifies an option in the
|
||||
<literal>[Service]</literal> section of the unit. See
|
||||
<citerefentry><refentrytitle>systemd.service</refentrytitle>
|
||||
<manvolnum>5</manvolnum></citerefentry> for details.
|
||||
'';
|
||||
|
||||
check = v:
|
||||
let assertValueOneOf = name: values: attr:
|
||||
let val = getAttr name attr;
|
||||
in optional ( hasAttr name attr && !elem val values) "${name} ${val} not known to systemd";
|
||||
checkType = assertValueOneOf "Type" ["simple" "forking" "oneshot" "dbus" "notify" "idle"];
|
||||
checkRestart = assertValueOneOf "Restart" ["no" "on-success" "on-failure" "on-abort" "always"];
|
||||
errors = concatMap (c: c v) [checkType checkRestart];
|
||||
in if errors == [] then true
|
||||
else builtins.trace (concatStringsSep "\n" errors) false;
|
||||
};
|
||||
|
||||
script = mkOption {
|
||||
|
||||
@@ -104,7 +104,7 @@ let
|
||||
|
||||
name = mkOption {
|
||||
# !!! The type should ensure that this could be a filename.
|
||||
type = types.string;
|
||||
type = types.str;
|
||||
example = "sshd";
|
||||
description = ''
|
||||
Name of the Upstart job.
|
||||
@@ -113,7 +113,7 @@ let
|
||||
|
||||
startOn = mkOption {
|
||||
# !!! Re-enable this once we're on Upstart >= 0.6.
|
||||
#type = types.string;
|
||||
#type = types.str;
|
||||
default = "";
|
||||
description = ''
|
||||
The Upstart event that triggers this job to be started.
|
||||
@@ -122,7 +122,7 @@ let
|
||||
};
|
||||
|
||||
stopOn = mkOption {
|
||||
type = types.string;
|
||||
type = types.str;
|
||||
default = "starting shutdown";
|
||||
description = ''
|
||||
The Upstart event that triggers this job to be stopped.
|
||||
@@ -130,7 +130,7 @@ let
|
||||
};
|
||||
|
||||
postStart = mkOption {
|
||||
type = types.string;
|
||||
type = types.lines;
|
||||
default = "";
|
||||
description = ''
|
||||
Shell commands executed after the job is started (i.e. after
|
||||
@@ -140,7 +140,7 @@ let
|
||||
};
|
||||
|
||||
preStop = mkOption {
|
||||
type = types.string;
|
||||
type = types.lines;
|
||||
default = "";
|
||||
description = ''
|
||||
Shell commands executed before the job is stopped
|
||||
@@ -150,7 +150,7 @@ let
|
||||
};
|
||||
|
||||
postStop = mkOption {
|
||||
type = types.string;
|
||||
type = types.lines;
|
||||
default = "";
|
||||
description = ''
|
||||
Shell commands executed after the job has stopped
|
||||
@@ -159,7 +159,7 @@ let
|
||||
};
|
||||
|
||||
exec = mkOption {
|
||||
type = types.string;
|
||||
type = types.str;
|
||||
default = "";
|
||||
description = ''
|
||||
Command to start the job's main process. If empty, the
|
||||
@@ -189,7 +189,7 @@ let
|
||||
};
|
||||
|
||||
daemonType = mkOption {
|
||||
type = types.string;
|
||||
type = types.str;
|
||||
default = "none";
|
||||
description = ''
|
||||
Determines how Upstart detects when a daemon should be
|
||||
@@ -203,8 +203,7 @@ let
|
||||
};
|
||||
|
||||
setuid = mkOption {
|
||||
type = types.string;
|
||||
check = userExists;
|
||||
type = types.addCheck types.str userExists;
|
||||
default = "";
|
||||
description = ''
|
||||
Run the daemon as a different user.
|
||||
@@ -212,8 +211,7 @@ let
|
||||
};
|
||||
|
||||
setgid = mkOption {
|
||||
type = types.string;
|
||||
check = groupExists;
|
||||
type = types.addCheck types.str groupExists;
|
||||
default = "";
|
||||
description = ''
|
||||
Run the daemon as a different group.
|
||||
|
||||
Reference in New Issue
Block a user