diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-10-30 15:33:20 +0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-10-30 15:35:09 +0100 |
commit | 70a2c545274cda238c5eda28b60cfa9dbc6f7ed6 (patch) | |
tree | d3629d90b938f5be866f2977c26976198f4ab014 /nixos/modules/system/boot/systemd-unit-options.nix | |
parent | db2a9afb75abc50497fcde61470c2b83795e4669 (diff) | |
download | nixlib-70a2c545274cda238c5eda28b60cfa9dbc6f7ed6.tar nixlib-70a2c545274cda238c5eda28b60cfa9dbc6f7ed6.tar.gz nixlib-70a2c545274cda238c5eda28b60cfa9dbc6f7ed6.tar.bz2 nixlib-70a2c545274cda238c5eda28b60cfa9dbc6f7ed6.tar.lz nixlib-70a2c545274cda238c5eda28b60cfa9dbc6f7ed6.tar.xz nixlib-70a2c545274cda238c5eda28b60cfa9dbc6f7ed6.tar.zst nixlib-70a2c545274cda238c5eda28b60cfa9dbc6f7ed6.zip |
Strictly check the arguments to mkOption
And fix various instances of bad arguments.
Diffstat (limited to 'nixos/modules/system/boot/systemd-unit-options.nix')
-rw-r--r-- | nixos/modules/system/boot/systemd-unit-options.nix | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/nixos/modules/system/boot/systemd-unit-options.nix b/nixos/modules/system/boot/systemd-unit-options.nix index ac9e636fe1e3..a1faea886f98 100644 --- a/nixos/modules/system/boot/systemd-unit-options.nix +++ b/nixos/modules/system/boot/systemd-unit-options.nix @@ -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 { |