diff options
author | Mathijs Kwik <mathijs@bluescreen303.nl> | 2013-12-30 00:40:02 -0800 |
---|---|---|
committer | Mathijs Kwik <mathijs@bluescreen303.nl> | 2013-12-30 00:40:02 -0800 |
commit | 9b056e1e3ec4312ffd6043f13aa068da09908335 (patch) | |
tree | c56b9771780b570d962d0064e662b951fe44dc83 /nixos/modules/tasks | |
parent | 0270be1eb65879cbe2d5a35c43b272ad34ac7715 (diff) | |
parent | cabc0647d9555a24689e4d1483537149eab18e42 (diff) | |
download | nixlib-9b056e1e3ec4312ffd6043f13aa068da09908335.tar nixlib-9b056e1e3ec4312ffd6043f13aa068da09908335.tar.gz nixlib-9b056e1e3ec4312ffd6043f13aa068da09908335.tar.bz2 nixlib-9b056e1e3ec4312ffd6043f13aa068da09908335.tar.lz nixlib-9b056e1e3ec4312ffd6043f13aa068da09908335.tar.xz nixlib-9b056e1e3ec4312ffd6043f13aa068da09908335.tar.zst nixlib-9b056e1e3ec4312ffd6043f13aa068da09908335.zip |
Merge pull request #1431 from wkennington/vlan
network-interfaces: Add support for creating vlans
Diffstat (limited to 'nixos/modules/tasks')
-rw-r--r-- | nixos/modules/tasks/network-interfaces.nix | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/nixos/modules/tasks/network-interfaces.nix b/nixos/modules/tasks/network-interfaces.nix index b1ab989f130f..1249fabc309a 100644 --- a/nixos/modules/tasks/network-interfaces.nix +++ b/nixos/modules/tasks/network-interfaces.nix @@ -219,6 +219,45 @@ in }; + networking.vlans = mkOption { + default = { }; + example = { + vlan0 = { + id = 3; + interface = "enp3s0"; + }; + vlan1 = { + id = 1; + interface = "wlan0"; + }; + }; + description = + '' + This option allows you to define vlan devices that tag packets + on top of a physical interface. The value of this option is an + attribute set. Each attribute specifies a vlan, with the name + specifying the name of the vlan interface. + ''; + + type = types.attrsOf types.optionSet; + + options = { + + id = mkOption { + example = 1; + type = types.int; + description = "The vlan identifier"; + }; + + interface = mkOption { + example = "enp4s0"; + type = types.string; + description = "The interface the vlan will transmit packets through."; + }; + + }; + }; + networking.useDHCP = mkOption { type = types.bool; default = true; @@ -421,10 +460,32 @@ in ''; }; + createVlanDevice = n: v: + let + deps = [ "sys-subsystem-net-devices-${v.interface}.device" ]; + in + { + description = "Vlan Interface ${n}"; + wantedBy = [ "network.target" "sys-subsystem-net-devices-${n}.device" ]; + bindsTo = deps; + after = deps; + serviceConfig.Type = "oneshot"; + serviceConfig.RemainAfterExit = true; + path = [ pkgs.iproute ]; + script = '' + ip link add link "${v.interface}" "${n}" type vlan id "${toString v.id}" + ip link set "${n}" up + ''; + postStop = '' + ip link delete "${n}" + ''; + }; + in listToAttrs ( map configureInterface interfaces ++ map createTunDevice (filter (i: i.virtual) interfaces)) // mapAttrs createBridgeDevice cfg.bridges + // mapAttrs createVlanDevice cfg.vlans // { "network-setup" = networkSetup; }; # Set the host and domain names in the activation script. Don't |