diff --git a/nixos/modules/system/boot/networkd.nix b/nixos/modules/system/boot/networkd.nix
index d6b446e9ac2..2109b0cb159 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}
'';
};