Strictly check the arguments to mkOption
And fix various instances of bad arguments.
This commit is contained in:
parent
db2a9afb75
commit
70a2c54527
|
@ -11,17 +11,18 @@ with import ./strings.nix;
|
||||||
rec {
|
rec {
|
||||||
|
|
||||||
isOption = lib.isType "option";
|
isOption = lib.isType "option";
|
||||||
mkOption = attrs: attrs // {
|
mkOption =
|
||||||
_type = "option";
|
{ default ? null # Default value used when no definition is given in the configuration.
|
||||||
# name (this is the name of the attributem it is automatically generated by the traversal)
|
, defaultText ? null # Textual representation of the default, for in the manual.
|
||||||
# default (value used when no definition exists)
|
, example ? null # Example value used in the manual.
|
||||||
# example (documentation)
|
, description ? null # String describing the option.
|
||||||
# description (documentation)
|
, type ? null # Option type, providing type-checking and value merging.
|
||||||
# type (option type, provide a default merge function and ensure type correctness)
|
, apply ? null # Function that converts the option value to something else.
|
||||||
# merge (function used to merge definitions into one definition: [ /type/ ] -> /type/)
|
, internal ? null # Whether the option is for NixOS developers only.
|
||||||
# apply (convert the option value to ease the manipulation of the option result)
|
, visible ? null # Whether the option shows up in the manual.
|
||||||
# options (set of sub-options declarations & definitions)
|
, options ? null # Obsolete, used by types.optionSet.
|
||||||
};
|
} @ attrs:
|
||||||
|
attrs // { _type = "option"; };
|
||||||
|
|
||||||
mkEnableOption = name: mkOption {
|
mkEnableOption = name: mkOption {
|
||||||
default = false;
|
default = false;
|
||||||
|
|
|
@ -201,6 +201,9 @@ rec {
|
||||||
name = /* builtins.trace "types.optionSet is deprecated; use types.submodule instead" */ "option set";
|
name = /* builtins.trace "types.optionSet is deprecated; use types.submodule instead" */ "option set";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Augment the given type with an additional type check function.
|
||||||
|
addCheck = elemType: check: elemType // { check = x: elemType.check x && check x; };
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ with pkgs.lib;
|
||||||
fonts = {
|
fonts = {
|
||||||
|
|
||||||
enableFontConfig = mkOption { # !!! should be enableFontconfig
|
enableFontConfig = mkOption { # !!! should be enableFontconfig
|
||||||
|
type = types.bool;
|
||||||
default = true;
|
default = true;
|
||||||
description = ''
|
description = ''
|
||||||
If enabled, a Fontconfig configuration file will be built
|
If enabled, a Fontconfig configuration file will be built
|
||||||
|
|
|
@ -21,7 +21,8 @@ in
|
||||||
|
|
||||||
language = mkOption {
|
language = mkOption {
|
||||||
default = "English";
|
default = "English";
|
||||||
check = lang: elem lang [ "English" "Spanish" "Russian" "Serbian" "Turkish" ];
|
type = types.addCheck types.str
|
||||||
|
(lang: elem lang [ "English" "Spanish" "Russian" "Serbian" "Turkish" ]);
|
||||||
description = "The language of bot messages: English, Spanish, Russian, Serbian or Turkish.";
|
description = "The language of bot messages: English, Spanish, Russian, Serbian or Turkish.";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ in
|
||||||
|
|
||||||
authMode = mkOption {
|
authMode = mkOption {
|
||||||
default = "Open";
|
default = "Open";
|
||||||
check = authModeCheck;
|
type = types.addCheck types.str authModeCheck;
|
||||||
description = ''
|
description = ''
|
||||||
The following authentication modes are available:
|
The following authentication modes are available:
|
||||||
Open -- Accept connections from anyone, use NickServ for user authentication.
|
Open -- Accept connections from anyone, use NickServ for user authentication.
|
||||||
|
|
|
@ -32,7 +32,7 @@ in
|
||||||
services.minidlna.mediaDirs = mkOption {
|
services.minidlna.mediaDirs = mkOption {
|
||||||
type = types.listOf types.string;
|
type = types.listOf types.string;
|
||||||
default = [];
|
default = [];
|
||||||
examples = [ "/data/media" "V,/home/alice/video" ];
|
example = [ "/data/media" "V,/home/alice/video" ];
|
||||||
description =
|
description =
|
||||||
''
|
''
|
||||||
Directories to be scanned for media files. The prefixes
|
Directories to be scanned for media files. The prefixes
|
||||||
|
|
|
@ -102,7 +102,7 @@ in
|
||||||
|
|
||||||
permitRootLogin = mkOption {
|
permitRootLogin = mkOption {
|
||||||
default = "without-password";
|
default = "without-password";
|
||||||
check = permitRootLoginCheck;
|
type = types.addCheck types.str permitRootLoginCheck;
|
||||||
description = ''
|
description = ''
|
||||||
Whether the root user can login using ssh. Valid values are
|
Whether the root user can login using ssh. Valid values are
|
||||||
<literal>yes</literal>, <literal>without-password</literal>,
|
<literal>yes</literal>, <literal>without-password</literal>,
|
||||||
|
|
|
@ -2,7 +2,19 @@
|
||||||
|
|
||||||
with pkgs.lib;
|
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 = {
|
unitOptions = {
|
||||||
|
|
||||||
|
@ -147,23 +159,13 @@ rec {
|
||||||
{ StartLimitInterval = 10;
|
{ StartLimitInterval = 10;
|
||||||
RestartSec = 5;
|
RestartSec = 5;
|
||||||
};
|
};
|
||||||
type = types.attrs;
|
type = types.addCheck types.attrs checkService;
|
||||||
description = ''
|
description = ''
|
||||||
Each attribute in this set specifies an option in the
|
Each attribute in this set specifies an option in the
|
||||||
<literal>[Service]</literal> section of the unit. See
|
<literal>[Service]</literal> section of the unit. See
|
||||||
<citerefentry><refentrytitle>systemd.service</refentrytitle>
|
<citerefentry><refentrytitle>systemd.service</refentrytitle>
|
||||||
<manvolnum>5</manvolnum></citerefentry> for details.
|
<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 {
|
script = mkOption {
|
||||||
|
|
|
@ -104,7 +104,7 @@ let
|
||||||
|
|
||||||
name = mkOption {
|
name = mkOption {
|
||||||
# !!! The type should ensure that this could be a filename.
|
# !!! The type should ensure that this could be a filename.
|
||||||
type = types.string;
|
type = types.str;
|
||||||
example = "sshd";
|
example = "sshd";
|
||||||
description = ''
|
description = ''
|
||||||
Name of the Upstart job.
|
Name of the Upstart job.
|
||||||
|
@ -113,7 +113,7 @@ let
|
||||||
|
|
||||||
startOn = mkOption {
|
startOn = mkOption {
|
||||||
# !!! Re-enable this once we're on Upstart >= 0.6.
|
# !!! Re-enable this once we're on Upstart >= 0.6.
|
||||||
#type = types.string;
|
#type = types.str;
|
||||||
default = "";
|
default = "";
|
||||||
description = ''
|
description = ''
|
||||||
The Upstart event that triggers this job to be started.
|
The Upstart event that triggers this job to be started.
|
||||||
|
@ -122,7 +122,7 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
stopOn = mkOption {
|
stopOn = mkOption {
|
||||||
type = types.string;
|
type = types.str;
|
||||||
default = "starting shutdown";
|
default = "starting shutdown";
|
||||||
description = ''
|
description = ''
|
||||||
The Upstart event that triggers this job to be stopped.
|
The Upstart event that triggers this job to be stopped.
|
||||||
|
@ -130,7 +130,7 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
postStart = mkOption {
|
postStart = mkOption {
|
||||||
type = types.string;
|
type = types.lines;
|
||||||
default = "";
|
default = "";
|
||||||
description = ''
|
description = ''
|
||||||
Shell commands executed after the job is started (i.e. after
|
Shell commands executed after the job is started (i.e. after
|
||||||
|
@ -140,7 +140,7 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
preStop = mkOption {
|
preStop = mkOption {
|
||||||
type = types.string;
|
type = types.lines;
|
||||||
default = "";
|
default = "";
|
||||||
description = ''
|
description = ''
|
||||||
Shell commands executed before the job is stopped
|
Shell commands executed before the job is stopped
|
||||||
|
@ -150,7 +150,7 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
postStop = mkOption {
|
postStop = mkOption {
|
||||||
type = types.string;
|
type = types.lines;
|
||||||
default = "";
|
default = "";
|
||||||
description = ''
|
description = ''
|
||||||
Shell commands executed after the job has stopped
|
Shell commands executed after the job has stopped
|
||||||
|
@ -159,7 +159,7 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
exec = mkOption {
|
exec = mkOption {
|
||||||
type = types.string;
|
type = types.str;
|
||||||
default = "";
|
default = "";
|
||||||
description = ''
|
description = ''
|
||||||
Command to start the job's main process. If empty, the
|
Command to start the job's main process. If empty, the
|
||||||
|
@ -189,7 +189,7 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
daemonType = mkOption {
|
daemonType = mkOption {
|
||||||
type = types.string;
|
type = types.str;
|
||||||
default = "none";
|
default = "none";
|
||||||
description = ''
|
description = ''
|
||||||
Determines how Upstart detects when a daemon should be
|
Determines how Upstart detects when a daemon should be
|
||||||
|
@ -203,8 +203,7 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
setuid = mkOption {
|
setuid = mkOption {
|
||||||
type = types.string;
|
type = types.addCheck types.str userExists;
|
||||||
check = userExists;
|
|
||||||
default = "";
|
default = "";
|
||||||
description = ''
|
description = ''
|
||||||
Run the daemon as a different user.
|
Run the daemon as a different user.
|
||||||
|
@ -212,8 +211,7 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
setgid = mkOption {
|
setgid = mkOption {
|
||||||
type = types.string;
|
type = types.addCheck types.str groupExists;
|
||||||
check = groupExists;
|
|
||||||
default = "";
|
default = "";
|
||||||
description = ''
|
description = ''
|
||||||
Run the daemon as a different group.
|
Run the daemon as a different group.
|
||||||
|
|
Loading…
Reference in New Issue