git.iko.soy/typeable/nixpkgs
on master help sign in
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>

commit4cdb4a4fef93b54dd41aab93d333c703df4d5803 authoraszlig <aszlig@redmoonstudios.org> dateThu 30 Apr 2015, 06:44 (12 years ago) parent49fa00c
4 files changed+69−68
nixos/modules/system/boot/networkd.nix+5 nixos/modules/system/boot/systemd-lib.nix+63 nixos/modules/system/boot/systemd-unit-options.nix+1−50 nixos/modules/system/boot/systemd.nix−18
nixos/modules/system/boot/networkd.nix+5
@@ -482,6 +482,11 @@ let
482482 };
483483 };
484484
485+ commonMatchText = def: ''
486+ [Match]
487+ ${attrsToSection def.matchConfig}
488+ '';
489+
485490 linkToUnit = name: def:
486491 { inherit (def) enable;
487492 text = commonMatchText def +
nixos/modules/system/boot/systemd-lib.nix+63
@@ -25,6 +25,69 @@ rec {
2525 ln -s /dev/null $out/${shellEscape name}
2626 '';
2727
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+
2891 generateUnits = type: units: upstreamUnits: upstreamWants:
2992 pkgs.runCommand "${type}-units" { preferLocalBuild = true; } ''
3093 mkdir -p $out
nixos/modules/system/boot/systemd-unit-options.nix+1−50
@@ -1,58 +1,9 @@
11{ config, lib }:
22
33with lib;
4+with import ./systemd-lib.nix { inherit config lib pkgs; };
45
56let
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−
567 checkService = checkUnitConfig "Service" [
578 (assertValueOneOf "Type" [
589 "simple" "forking" "oneshot" "dbus" "notify" "idle"
nixos/modules/system/boot/systemd.nix−18
@@ -276,19 +276,6 @@ let
276276 };
277277 };
278278
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−
292279 commonUnitText = def: ''
293280 [Unit]
294281 ${attrsToSection def.unitConfig}
@@ -369,11 +356,6 @@ let
369356 '';
370357 };
371358
372− commonMatchText = def: ''
373− [Match]
374− ${attrsToSection def.matchConfig}
375− '';
376−
377359in
378360
379361{