nixos/networking: move network-link-${i.name} to scripted networking
The unit sets MTU and MAC Address even with networkd enabled, which isn't necessary anymore, as networkd handles this by itself.
This commit is contained in:
parent
ca391c8a4f
commit
532528190b
|
@ -237,6 +237,38 @@ let
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
createNetworkLink = i:
|
||||||
|
let
|
||||||
|
deviceDependency = if (config.boot.isContainer || i.name == "lo")
|
||||||
|
then []
|
||||||
|
else [ (subsystemDevice i.name) ];
|
||||||
|
in
|
||||||
|
nameValuePair "network-link-${i.name}"
|
||||||
|
{ description = "Link configuration of ${i.name}";
|
||||||
|
wantedBy = [ "network-interfaces.target" ];
|
||||||
|
before = [ "network-interfaces.target" ];
|
||||||
|
bindsTo = deviceDependency;
|
||||||
|
after = [ "network-pre.target" ] ++ deviceDependency;
|
||||||
|
path = [ pkgs.iproute ];
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
RemainAfterExit = true;
|
||||||
|
};
|
||||||
|
script =
|
||||||
|
''
|
||||||
|
echo "Configuring link..."
|
||||||
|
'' + optionalString (i.macAddress != null) ''
|
||||||
|
echo "setting MAC address to ${i.macAddress}..."
|
||||||
|
ip link set "${i.name}" address "${i.macAddress}"
|
||||||
|
'' + optionalString (i.mtu != null) ''
|
||||||
|
echo "setting MTU to ${toString i.mtu}..."
|
||||||
|
ip link set "${i.name}" mtu "${toString i.mtu}"
|
||||||
|
'' + ''
|
||||||
|
echo -n "bringing up interface... "
|
||||||
|
ip link set "${i.name}" up && echo "done" || (echo "failed"; exit 1)
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
createTunDevice = i: nameValuePair "${i.name}-netdev"
|
createTunDevice = i: nameValuePair "${i.name}-netdev"
|
||||||
{ description = "Virtual Network Interface ${i.name}";
|
{ description = "Virtual Network Interface ${i.name}";
|
||||||
bindsTo = [ "dev-net-tun.device" ];
|
bindsTo = [ "dev-net-tun.device" ];
|
||||||
|
@ -508,6 +540,7 @@ let
|
||||||
});
|
});
|
||||||
|
|
||||||
in listToAttrs (
|
in listToAttrs (
|
||||||
|
map createNetworkLink interfaces ++
|
||||||
map configureAddrs interfaces ++
|
map configureAddrs interfaces ++
|
||||||
map createTunDevice (filter (i: i.virtual) interfaces))
|
map createTunDevice (filter (i: i.virtual) interfaces))
|
||||||
// mapAttrs' createBridgeDevice cfg.bridges
|
// mapAttrs' createBridgeDevice cfg.bridges
|
||||||
|
|
|
@ -1145,38 +1145,7 @@ in
|
||||||
${cfg.localCommands}
|
${cfg.localCommands}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
} // (listToAttrs (forEach interfaces (i:
|
};
|
||||||
let
|
|
||||||
deviceDependency = if (config.boot.isContainer || i.name == "lo")
|
|
||||||
then []
|
|
||||||
else [ (subsystemDevice i.name) ];
|
|
||||||
in
|
|
||||||
nameValuePair "network-link-${i.name}"
|
|
||||||
{ description = "Link configuration of ${i.name}";
|
|
||||||
wantedBy = [ "network-interfaces.target" ];
|
|
||||||
before = [ "network-interfaces.target" ];
|
|
||||||
bindsTo = deviceDependency;
|
|
||||||
after = [ "network-pre.target" ] ++ deviceDependency;
|
|
||||||
path = [ pkgs.iproute ];
|
|
||||||
serviceConfig = {
|
|
||||||
Type = "oneshot";
|
|
||||||
RemainAfterExit = true;
|
|
||||||
};
|
|
||||||
script =
|
|
||||||
''
|
|
||||||
echo "Configuring link..."
|
|
||||||
'' + optionalString (i.macAddress != null) ''
|
|
||||||
echo "setting MAC address to ${i.macAddress}..."
|
|
||||||
ip link set "${i.name}" address "${i.macAddress}"
|
|
||||||
'' + optionalString (i.mtu != null) ''
|
|
||||||
echo "setting MTU to ${toString i.mtu}..."
|
|
||||||
ip link set "${i.name}" mtu "${toString i.mtu}"
|
|
||||||
'' + ''
|
|
||||||
echo -n "bringing up interface... "
|
|
||||||
ip link set "${i.name}" up && echo "done" || (echo "failed"; exit 1)
|
|
||||||
'';
|
|
||||||
})));
|
|
||||||
|
|
||||||
services.mstpd = mkIf needsMstpd { enable = true; };
|
services.mstpd = mkIf needsMstpd { enable = true; };
|
||||||
|
|
||||||
virtualisation.vswitch = mkIf (cfg.vswitches != { }) { enable = true; };
|
virtualisation.vswitch = mkIf (cfg.vswitches != { }) { enable = true; };
|
||||||
|
|
Loading…
Reference in a new issue