From 7fd91a898b0d61f7c5e2d7c2b1fb5272c9b6d8af Mon Sep 17 00:00:00 2001 From: David Guibert Date: Thu, 16 Aug 2018 13:44:39 +0200 Subject: systemd-networkd: add support for wireguard netdev. --- nixos/modules/system/boot/networkd.nix | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'nixos/modules/system') diff --git a/nixos/modules/system/boot/networkd.nix b/nixos/modules/system/boot/networkd.nix index d6b446e9ac22..2109b0cb1594 100644 --- a/nixos/modules/system/boot/networkd.nix +++ b/nixos/modules/system/boot/networkd.nix @@ -55,6 +55,20 @@ let (assertMacAddress "MACAddress") ]; + checkWireGuard = checkUnitConfig "WireGuard" [ + (assertOnlyFields [ + "PrivateKey" "PrivateKeyFile" "ListenPort" "FwMark" + ]) + #(assertRange "ListenPort" 1 65535) # Or "auto" + ]; + + checkWireGuardPeer = checkUnitConfig "WireGuardPeer" [ + (assertOnlyFields [ + "PublicKey" "PresharedKey" "AllowedIPs" "Endpoint" "PersistentKeepalive" + ]) + # (assertRange "PersistentKeepalive" 1 65535) # defined as "nullOr int" + ]; + checkVlan = checkUnitConfig "VLAN" [ (assertOnlyFields ["Id" "GVRP" "MVRP" "LooseBinding" "ReorderHeader"]) (assertRange "Id" 0 4094) @@ -320,6 +334,29 @@ let ''; }; + wireguardConfig = mkOption { + default = {}; + example = { ListenPort="auto"; }; + type = types.addCheck (types.attrsOf unitOption) checkWireGuard; + description = '' + Each attribute in this set specifies an option in the + [WireGuard] section of the unit. See + systemd.netdev + 5 for details. + ''; + }; + + wireguardPeers = mkOption { + default = [ ]; + type = with types; listOf (submodule wireguardPeerOptions); + description = '' + Each attribute in this set specifies an option in the + [WireGuardPeer] section of the unit. See + systemd.netdev + 5 for details. + ''; + }; + vlanConfig = mkOption { default = {}; example = { Id = "4"; }; @@ -450,6 +487,23 @@ let }; }; + wireguardPeerOptions = { + options = { + wireguardPeerConfig = mkOption { + default = {}; + example = { }; + type = types.addCheck (types.attrsOf unitOption) checkWireGuardPeer; + description = '' + Each attribute in this set specifies an option in the + [WireGuardPeer] section of the unit. See + systemd.network + 5 for details. + ''; + }; + }; + }; + + networkOptions = commonNetworkOptions // { networkConfig = mkOption { @@ -732,6 +786,16 @@ let ${attrsToSection def.bondConfig} ''} + ${optionalString (def.wireguardConfig != { }) '' + [WireGuard] + ${attrsToSection def.wireguardConfig} + + ''} + ${flip concatMapStrings def.wireguardPeers (x: '' + [WireGuardPeer] + ${attrsToSection x.wireguardPeerConfig} + + '')} ${def.extraConfig} ''; }; -- cgit 1.4.1