diff options
author | aszlig <aszlig@redmoonstudios.org> | 2015-04-30 06:44:25 +0200 |
---|---|---|
committer | aszlig <aszlig@redmoonstudios.org> | 2015-04-30 06:49:10 +0200 |
commit | 4cdb4a4fef93b54dd41aab93d333c703df4d5803 (patch) | |
tree | e6845a955d501cfaf197e870bf9593b2923a468c /nixos/modules/system/boot | |
parent | 49fa00cded7bd3da0aa76cd2eb58e197084b820d (diff) | |
download | nixpkgs-4cdb4a4fef93b54dd41aab93d333c703df4d5803.tar nixpkgs-4cdb4a4fef93b54dd41aab93d333c703df4d5803.tar.gz nixpkgs-4cdb4a4fef93b54dd41aab93d333c703df4d5803.tar.bz2 nixpkgs-4cdb4a4fef93b54dd41aab93d333c703df4d5803.tar.lz nixpkgs-4cdb4a4fef93b54dd41aab93d333c703df4d5803.tar.xz nixpkgs-4cdb4a4fef93b54dd41aab93d333c703df4d5803.tar.zst nixpkgs-4cdb4a4fef93b54dd41aab93d333c703df4d5803.zip |
networkd: Fix evaluation of systemd.network units.
During the refactor of the networkd stuff in f8dbe5f, a lot of the options are now needed by systemd.nix as well as networkd.nix but weren't moved by that commit as well. For now, this fixes all networkd VM tests except for the macvlan one and thus it should fix #7505 for at least DHCP-based configuration. Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Diffstat (limited to 'nixos/modules/system/boot')
-rw-r--r-- | nixos/modules/system/boot/networkd.nix | 5 | ||||
-rw-r--r-- | nixos/modules/system/boot/systemd-lib.nix | 63 | ||||
-rw-r--r-- | nixos/modules/system/boot/systemd-unit-options.nix | 51 | ||||
-rw-r--r-- | nixos/modules/system/boot/systemd.nix | 18 |
4 files changed, 69 insertions, 68 deletions
diff --git a/nixos/modules/system/boot/networkd.nix b/nixos/modules/system/boot/networkd.nix index e83aa6e2e2d..b183c0f3236 100644 --- a/nixos/modules/system/boot/networkd.nix +++ b/nixos/modules/system/boot/networkd.nix @@ -482,6 +482,11 @@ let }; }; + commonMatchText = def: '' + [Match] + ${attrsToSection def.matchConfig} + ''; + linkToUnit = name: def: { inherit (def) enable; text = commonMatchText def + diff --git a/nixos/modules/system/boot/systemd-lib.nix b/nixos/modules/system/boot/systemd-lib.nix index e8cfd3395cb..873fff15d38 100644 --- a/nixos/modules/system/boot/systemd-lib.nix +++ b/nixos/modules/system/boot/systemd-lib.nix @@ -25,6 +25,69 @@ rec { ln -s /dev/null $out/${shellEscape name} ''; + boolValues = [true false "yes" "no"]; + + 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."; + + + 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."; + + 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}]"; + + assertOnlyFields = fields: group: attr: + let badFields = filter (name: ! elem name fields) (attrNames attr); in + optional (badFields != [ ]) + "Systemd ${group} has extra fields [${concatStringsSep " " badFields}]."; + + checkUnitConfig = group: checks: v: + let errors = concatMap (c: c group v) checks; in + if errors == [] then true + else builtins.trace (concatStringsSep "\n" errors) false; + + toOption = x: + if x == true then "true" + else if x == false then "false" + else toString x; + + attrsToSection = as: + concatStrings (concatLists (mapAttrsToList (name: value: + map (x: '' + ${name}=${toOption x} + '') + (if isList value then value else [value])) + as)); + generateUnits = type: units: upstreamUnits: upstreamWants: pkgs.runCommand "${type}-units" { preferLocalBuild = true; } '' mkdir -p $out 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" diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix index 78aac7fe96f..0f210d50688 100644 --- a/nixos/modules/system/boot/systemd.nix +++ b/nixos/modules/system/boot/systemd.nix @@ -276,19 +276,6 @@ let }; }; - toOption = x: - if x == true then "true" - else if x == false then "false" - else toString x; - - attrsToSection = as: - concatStrings (concatLists (mapAttrsToList (name: value: - map (x: '' - ${name}=${toOption x} - '') - (if isList value then value else [value])) - as)); - commonUnitText = def: '' [Unit] ${attrsToSection def.unitConfig} @@ -369,11 +356,6 @@ let ''; }; - commonMatchText = def: '' - [Match] - ${attrsToSection def.matchConfig} - ''; - in { |