summary refs log tree commit diff
path: root/nixos/modules/system/boot/systemd-unit-options.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixos/modules/system/boot/systemd-unit-options.nix')
-rw-r--r--nixos/modules/system/boot/systemd-unit-options.nix51
1 files changed, 1 insertions, 50 deletions
diff --git a/nixos/modules/system/boot/systemd-unit-options.nix b/nixos/modules/system/boot/systemd-unit-options.nix
index 785634cbf66..57831a5e6ef 100644
--- a/nixos/modules/system/boot/systemd-unit-options.nix
+++ b/nixos/modules/system/boot/systemd-unit-options.nix
@@ -1,58 +1,9 @@
 { config, lib }:
 
 with lib;
+with import ./systemd-lib.nix { inherit config lib pkgs; };
 
 let
-
-  boolValues = [true false "yes" "no"];
-
-  assertValueOneOf = name: values: group: attr:
-    optional (attr ? ${name} && !elem attr.${name} values)
-      "Systemd ${group} field `${name}' cannot have value `${attr.${name}}'.";
-
-  assertHasField = name: group: attr:
-    optional (!(attr ? ${name}))
-      "Systemd ${group} field `${name}' must exist.";
-
-  assertOnlyFields = fields: group: attr:
-    let badFields = filter (name: ! elem name fields) (attrNames attr); in
-    optional (badFields != [ ])
-      "Systemd ${group} has extra fields [${concatStringsSep " " badFields}].";
-
-  assertRange = name: min: max: group: attr:
-    optional (attr ? ${name} && !(min <= attr.${name} && max >= attr.${name}))
-      "Systemd ${group} field `${name}' is outside the range [${toString min},${toString max}]";
-
-  digits = map toString (range 0 9);
-
-  isByteFormat = s:
-    let
-      l = reverseList (stringToCharacters s);
-      suffix = head l;
-      nums = tail l;
-    in elem suffix (["K" "M" "G" "T"] ++ digits)
-      && all (num: elem num digits) nums;
-
-  assertByteFormat = name: group: attr:
-    optional (attr ? ${name} && ! isByteFormat attr.${name})
-      "Systemd ${group} field `${name}' must be in byte format [0-9]+[KMGT].";
-
-  hexChars = stringToCharacters "0123456789abcdefABCDEF";
-
-  isMacAddress = s: stringLength s == 17
-    && flip all (splitString ":" s) (bytes:
-      all (byte: elem byte hexChars) (stringToCharacters bytes)
-    );
-
-  assertMacAddress = name: group: attr:
-    optional (attr ? ${name} && ! isMacAddress attr.${name})
-      "Systemd ${group} field `${name}' must be a valid mac address.";
-
-  checkUnitConfig = group: checks: v:
-    let errors = concatMap (c: c group v) checks; in
-    if errors == [] then true
-      else builtins.trace (concatStringsSep "\n" errors) false;
-
   checkService = checkUnitConfig "Service" [
     (assertValueOneOf "Type" [
       "simple" "forking" "oneshot" "dbus" "notify" "idle"