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>

aszlig 4cdb4a4f 49fa00cd

+69 -68
+5
nixos/modules/system/boot/networkd.nix
··· 482 482 }; 483 483 }; 484 484 485 + commonMatchText = def: '' 486 + [Match] 487 + ${attrsToSection def.matchConfig} 488 + ''; 489 + 485 490 linkToUnit = name: def: 486 491 { inherit (def) enable; 487 492 text = commonMatchText def +
+63
nixos/modules/system/boot/systemd-lib.nix
··· 25 25 ln -s /dev/null $out/${shellEscape name} 26 26 ''; 27 27 28 + boolValues = [true false "yes" "no"]; 29 + 30 + digits = map toString (range 0 9); 31 + 32 + isByteFormat = s: 33 + let 34 + l = reverseList (stringToCharacters s); 35 + suffix = head l; 36 + nums = tail l; 37 + in elem suffix (["K" "M" "G" "T"] ++ digits) 38 + && all (num: elem num digits) nums; 39 + 40 + assertByteFormat = name: group: attr: 41 + optional (attr ? ${name} && ! isByteFormat attr.${name}) 42 + "Systemd ${group} field `${name}' must be in byte format [0-9]+[KMGT]."; 43 + 44 + hexChars = stringToCharacters "0123456789abcdefABCDEF"; 45 + 46 + isMacAddress = s: stringLength s == 17 47 + && flip all (splitString ":" s) (bytes: 48 + all (byte: elem byte hexChars) (stringToCharacters bytes) 49 + ); 50 + 51 + assertMacAddress = name: group: attr: 52 + optional (attr ? ${name} && ! isMacAddress attr.${name}) 53 + "Systemd ${group} field `${name}' must be a valid mac address."; 54 + 55 + 56 + assertValueOneOf = name: values: group: attr: 57 + optional (attr ? ${name} && !elem attr.${name} values) 58 + "Systemd ${group} field `${name}' cannot have value `${attr.${name}}'."; 59 + 60 + assertHasField = name: group: attr: 61 + optional (!(attr ? ${name})) 62 + "Systemd ${group} field `${name}' must exist."; 63 + 64 + assertRange = name: min: max: group: attr: 65 + optional (attr ? ${name} && !(min <= attr.${name} && max >= attr.${name})) 66 + "Systemd ${group} field `${name}' is outside the range [${toString min},${toString max}]"; 67 + 68 + assertOnlyFields = fields: group: attr: 69 + let badFields = filter (name: ! elem name fields) (attrNames attr); in 70 + optional (badFields != [ ]) 71 + "Systemd ${group} has extra fields [${concatStringsSep " " badFields}]."; 72 + 73 + checkUnitConfig = group: checks: v: 74 + let errors = concatMap (c: c group v) checks; in 75 + if errors == [] then true 76 + else builtins.trace (concatStringsSep "\n" errors) false; 77 + 78 + toOption = x: 79 + if x == true then "true" 80 + else if x == false then "false" 81 + else toString x; 82 + 83 + attrsToSection = as: 84 + concatStrings (concatLists (mapAttrsToList (name: value: 85 + map (x: '' 86 + ${name}=${toOption x} 87 + '') 88 + (if isList value then value else [value])) 89 + as)); 90 + 28 91 generateUnits = type: units: upstreamUnits: upstreamWants: 29 92 pkgs.runCommand "${type}-units" { preferLocalBuild = true; } '' 30 93 mkdir -p $out
+1 -50
nixos/modules/system/boot/systemd-unit-options.nix
··· 1 1 { config, lib }: 2 2 3 3 with lib; 4 + with import ./systemd-lib.nix { inherit config lib pkgs; }; 4 5 5 6 let 6 - 7 - boolValues = [true false "yes" "no"]; 8 - 9 - assertValueOneOf = name: values: group: attr: 10 - optional (attr ? ${name} && !elem attr.${name} values) 11 - "Systemd ${group} field `${name}' cannot have value `${attr.${name}}'."; 12 - 13 - assertHasField = name: group: attr: 14 - optional (!(attr ? ${name})) 15 - "Systemd ${group} field `${name}' must exist."; 16 - 17 - assertOnlyFields = fields: group: attr: 18 - let badFields = filter (name: ! elem name fields) (attrNames attr); in 19 - optional (badFields != [ ]) 20 - "Systemd ${group} has extra fields [${concatStringsSep " " badFields}]."; 21 - 22 - assertRange = name: min: max: group: attr: 23 - optional (attr ? ${name} && !(min <= attr.${name} && max >= attr.${name})) 24 - "Systemd ${group} field `${name}' is outside the range [${toString min},${toString max}]"; 25 - 26 - digits = map toString (range 0 9); 27 - 28 - isByteFormat = s: 29 - let 30 - l = reverseList (stringToCharacters s); 31 - suffix = head l; 32 - nums = tail l; 33 - in elem suffix (["K" "M" "G" "T"] ++ digits) 34 - && all (num: elem num digits) nums; 35 - 36 - assertByteFormat = name: group: attr: 37 - optional (attr ? ${name} && ! isByteFormat attr.${name}) 38 - "Systemd ${group} field `${name}' must be in byte format [0-9]+[KMGT]."; 39 - 40 - hexChars = stringToCharacters "0123456789abcdefABCDEF"; 41 - 42 - isMacAddress = s: stringLength s == 17 43 - && flip all (splitString ":" s) (bytes: 44 - all (byte: elem byte hexChars) (stringToCharacters bytes) 45 - ); 46 - 47 - assertMacAddress = name: group: attr: 48 - optional (attr ? ${name} && ! isMacAddress attr.${name}) 49 - "Systemd ${group} field `${name}' must be a valid mac address."; 50 - 51 - checkUnitConfig = group: checks: v: 52 - let errors = concatMap (c: c group v) checks; in 53 - if errors == [] then true 54 - else builtins.trace (concatStringsSep "\n" errors) false; 55 - 56 7 checkService = checkUnitConfig "Service" [ 57 8 (assertValueOneOf "Type" [ 58 9 "simple" "forking" "oneshot" "dbus" "notify" "idle"
-18
nixos/modules/system/boot/systemd.nix
··· 276 276 }; 277 277 }; 278 278 279 - toOption = x: 280 - if x == true then "true" 281 - else if x == false then "false" 282 - else toString x; 283 - 284 - attrsToSection = as: 285 - concatStrings (concatLists (mapAttrsToList (name: value: 286 - map (x: '' 287 - ${name}=${toOption x} 288 - '') 289 - (if isList value then value else [value])) 290 - as)); 291 - 292 279 commonUnitText = def: '' 293 280 [Unit] 294 281 ${attrsToSection def.unitConfig} ··· 368 355 ${attrsToSection def.automountConfig} 369 356 ''; 370 357 }; 371 - 372 - commonMatchText = def: '' 373 - [Match] 374 - ${attrsToSection def.matchConfig} 375 - ''; 376 358 377 359 in 378 360