nixos/network-interface: Append -netdev for all device units

Currently, device units are named directly after the name the user
specifies for the device. A bridge device named lan will be defined
within lan.service. This becomes a problem if you want your interface
named nginx but also want to run the nginx service.

This patch fixes the issue by appending netdev to all virtually created
network device units. Therefore, the lan bridge -> lan-netdev.service.
This naming convention is used for all types of network devices in order
to ensure that all network devices are unique.
This commit is contained in:
William A. Kennington III 2014-08-24 15:16:47 -07:00
parent 1c08efb8ab
commit ed6040fc8d

View file

@ -680,7 +680,7 @@ in
'');
};
createTunDevice = i: nameValuePair "${i.name}-tun"
createTunDevice = i: nameValuePair "${i.name}-netdev"
{ description = "Virtual Network Interface ${i.name}";
requires = [ "dev-net-tun.device" ];
after = [ "dev-net-tun.device" ];
@ -701,8 +701,8 @@ in
'';
};
createBridgeDevice = n: v:
let
createBridgeDevice = n: v: nameValuePair "${n}-netdev"
(let
deps = map (i: "sys-subsystem-net-devices-${i}.device") v.interfaces;
in
{ description = "Bridge Interface ${n}";
@ -739,10 +739,10 @@ in
ip link set "${n}" down
brctl delbr "${n}"
'';
};
});
createBondDevice = n: v:
let
createBondDevice = n: v: nameValuePair "${n}-netdev"
(let
deps = map (i: "sys-subsystem-net-devices-${i}.device") v.interfaces;
in
{ description = "Bond Interface ${n}";
@ -778,10 +778,10 @@ in
ifenslave -d "${n}"
ip link delete "${n}"
'';
};
});
createSitDevice = n: v:
let
createSitDevice = n: v: nameValuePair "${n}-netdev"
(let
deps = optional (v.dev != null) "sys-subsystem-net-devices-${v.dev}.device";
in
{ description = "6-to-4 Tunnel Interface ${n}";
@ -804,10 +804,10 @@ in
postStop = ''
ip link delete "${n}"
'';
};
});
createVlanDevice = n: v:
let
createVlanDevice = n: v: nameValuePair "${n}-netdev"
(let
deps = [ "sys-subsystem-net-devices-${v.interface}.device" ];
in
{ description = "Vlan Interface ${n}";
@ -826,15 +826,15 @@ in
postStop = ''
ip link delete "${n}"
'';
};
});
in listToAttrs (
map configureInterface interfaces ++
map createTunDevice (filter (i: i.virtual) interfaces))
// mapAttrs createBridgeDevice cfg.bridges
// mapAttrs createBondDevice cfg.bonds
// mapAttrs createSitDevice cfg.sits
// mapAttrs createVlanDevice cfg.vlans
// mapAttrs' createBridgeDevice cfg.bridges
// mapAttrs' createBondDevice cfg.bonds
// mapAttrs' createSitDevice cfg.sits
// mapAttrs' createVlanDevice cfg.vlans
// { "network-setup" = networkSetup; };
# Set the host and domain names in the activation script. Don't