Loading nixos/modules/tasks/network-interfaces-scripted.nix +3 −2 Original line number Diff line number Diff line Loading @@ -219,14 +219,15 @@ let cidr = "${route.address}/${toString route.prefixLength}"; via = optionalString (route.via != null) ''via "${route.via}"''; options = concatStrings (mapAttrsToList (name: val: "${name} ${val} ") route.options); type = toString route.type; in '' echo "${cidr}" >> $state echo -n "adding route ${cidr}... " if out=$(ip route add "${cidr}" ${options} ${via} dev "${i.name}" proto static 2>&1); then if out=$(ip route add ${type} "${cidr}" ${options} ${via} dev "${i.name}" proto static 2>&1); then echo "done" elif ! echo "$out" | grep "File exists" >/dev/null 2>&1; then echo "'ip route add "${cidr}" ${options} ${via} dev "${i.name}"' failed: $out" echo "'ip route add ${type} "${cidr}" ${options} ${via} dev "${i.name}"' failed: $out" exit 1 fi '' Loading nixos/modules/tasks/network-interfaces-systemd.nix +3 −0 Original line number Diff line number Diff line Loading @@ -142,6 +142,9 @@ in optionalAttrs (route.via != null) { Gateway = route.via; } // optionalAttrs (route.type != null) { Type = route.type; } // optionalAttrs (route.options ? onlink) { GatewayOnLink = true; } // Loading nixos/modules/tasks/network-interfaces.nix +16 −0 Original line number Diff line number Diff line Loading @@ -90,6 +90,22 @@ let ''; }; type = mkOption { type = types.nullOr (types.enum [ "unicast" "local" "broadcast" "multicast" ]); default = null; description = '' Type of the route. See the <literal>Route types</literal> section in the <literal>ip-route(8)</literal> manual page for the details. Note that <literal>prohibit</literal>, <literal>blackhole</literal>, <literal>unreachable</literal>, and <literal>throw</literal> cannot be configured per device, so they are not available here. Similarly, <literal>nat</literal> hasn't been supported since kernel 2.6. ''; }; via = mkOption { type = types.nullOr types.str; default = null; Loading nixos/tests/ihatemoney/default.nix +1 −8 Original line number Diff line number Diff line Loading @@ -32,14 +32,7 @@ let }; }; # ihatemoney needs a local smtp server otherwise project creation just crashes services.opensmtpd = { enable = true; serverConfiguration = '' listen on lo action foo relay match from any for any action foo ''; }; services.postfix.enable = true; }; testScript = '' machine.wait_for_open_port(8000) Loading nixos/tests/networking.nix +25 −4 Original line number Diff line number Diff line Loading @@ -77,12 +77,14 @@ let testCases = { loopback = { name = "Loopback"; machine.networking.useDHCP = false; machine.networking.useNetworkd = networkd; nodes.client = { pkgs, ... }: with pkgs.lib; { networking.useDHCP = false; networking.useNetworkd = networkd; }; testScript = '' start_all() machine.wait_for_unit("network.target") loopback_addresses = machine.succeed("ip addr show lo") client.wait_for_unit("network.target") loopback_addresses = client.succeed("ip addr show lo") assert "inet 127.0.0.1/8" in loopback_addresses assert "inet6 ::1/128" in loopback_addresses ''; Loading Loading @@ -139,6 +141,25 @@ let client.wait_until_succeeds("ping -c 1 192.168.3.1") ''; }; routeType = { name = "RouteType"; nodes.client = { pkgs, ... }: with pkgs.lib; { networking = { useDHCP = false; useNetworkd = networkd; interfaces.eth1.ipv4.routes = [{ address = "192.168.1.127"; prefixLength = 32; type = "local"; }]; }; }; testScript = '' start_all() client.wait_for_unit("network.target") client.succeed("ip -4 route list table local | grep 'local 192.168.1.127'") ''; }; dhcpDefault = { name = "useDHCP-by-default"; nodes.router = router; Loading Loading
nixos/modules/tasks/network-interfaces-scripted.nix +3 −2 Original line number Diff line number Diff line Loading @@ -219,14 +219,15 @@ let cidr = "${route.address}/${toString route.prefixLength}"; via = optionalString (route.via != null) ''via "${route.via}"''; options = concatStrings (mapAttrsToList (name: val: "${name} ${val} ") route.options); type = toString route.type; in '' echo "${cidr}" >> $state echo -n "adding route ${cidr}... " if out=$(ip route add "${cidr}" ${options} ${via} dev "${i.name}" proto static 2>&1); then if out=$(ip route add ${type} "${cidr}" ${options} ${via} dev "${i.name}" proto static 2>&1); then echo "done" elif ! echo "$out" | grep "File exists" >/dev/null 2>&1; then echo "'ip route add "${cidr}" ${options} ${via} dev "${i.name}"' failed: $out" echo "'ip route add ${type} "${cidr}" ${options} ${via} dev "${i.name}"' failed: $out" exit 1 fi '' Loading
nixos/modules/tasks/network-interfaces-systemd.nix +3 −0 Original line number Diff line number Diff line Loading @@ -142,6 +142,9 @@ in optionalAttrs (route.via != null) { Gateway = route.via; } // optionalAttrs (route.type != null) { Type = route.type; } // optionalAttrs (route.options ? onlink) { GatewayOnLink = true; } // Loading
nixos/modules/tasks/network-interfaces.nix +16 −0 Original line number Diff line number Diff line Loading @@ -90,6 +90,22 @@ let ''; }; type = mkOption { type = types.nullOr (types.enum [ "unicast" "local" "broadcast" "multicast" ]); default = null; description = '' Type of the route. See the <literal>Route types</literal> section in the <literal>ip-route(8)</literal> manual page for the details. Note that <literal>prohibit</literal>, <literal>blackhole</literal>, <literal>unreachable</literal>, and <literal>throw</literal> cannot be configured per device, so they are not available here. Similarly, <literal>nat</literal> hasn't been supported since kernel 2.6. ''; }; via = mkOption { type = types.nullOr types.str; default = null; Loading
nixos/tests/ihatemoney/default.nix +1 −8 Original line number Diff line number Diff line Loading @@ -32,14 +32,7 @@ let }; }; # ihatemoney needs a local smtp server otherwise project creation just crashes services.opensmtpd = { enable = true; serverConfiguration = '' listen on lo action foo relay match from any for any action foo ''; }; services.postfix.enable = true; }; testScript = '' machine.wait_for_open_port(8000) Loading
nixos/tests/networking.nix +25 −4 Original line number Diff line number Diff line Loading @@ -77,12 +77,14 @@ let testCases = { loopback = { name = "Loopback"; machine.networking.useDHCP = false; machine.networking.useNetworkd = networkd; nodes.client = { pkgs, ... }: with pkgs.lib; { networking.useDHCP = false; networking.useNetworkd = networkd; }; testScript = '' start_all() machine.wait_for_unit("network.target") loopback_addresses = machine.succeed("ip addr show lo") client.wait_for_unit("network.target") loopback_addresses = client.succeed("ip addr show lo") assert "inet 127.0.0.1/8" in loopback_addresses assert "inet6 ::1/128" in loopback_addresses ''; Loading Loading @@ -139,6 +141,25 @@ let client.wait_until_succeeds("ping -c 1 192.168.3.1") ''; }; routeType = { name = "RouteType"; nodes.client = { pkgs, ... }: with pkgs.lib; { networking = { useDHCP = false; useNetworkd = networkd; interfaces.eth1.ipv4.routes = [{ address = "192.168.1.127"; prefixLength = 32; type = "local"; }]; }; }; testScript = '' start_all() client.wait_for_unit("network.target") client.succeed("ip -4 route list table local | grep 'local 192.168.1.127'") ''; }; dhcpDefault = { name = "useDHCP-by-default"; nodes.router = router; Loading