nixos/wireguard-networkd: escape backslashes in systemd credential names

This patch fixes loading issues for pre shared keys for
peers without custom names. In this case the peer's public
key would be used in the name for the corresponding pre
shared key credential, causing a loading error.

The networking.wireguard base module already escapes some
base64 characters of the public key with escape sequences
starting with a backslash. This backslash is now replaced
with an underscore for use in the credential names.

Changed files
+5 -3
nixos
modules
services
+5 -3
nixos/modules/services/networking/wireguard-networkd.nix
···
;
inherit (lib.modules) mkIf;
inherit (lib.options) literalExpression mkOption;
-
inherit (lib.strings) hasInfix;
+
inherit (lib.strings) hasInfix replaceStrings;
inherit (lib.trivial) flip pipe;
removeNulls = filterAttrs (_: v: v != null);
-
privateKeyCredential = interfaceName: "wireguard-${interfaceName}-private-key";
+
escapeCredentialName = input: replaceStrings [ "\\" ] [ "_" ] input;
+
+
privateKeyCredential = interfaceName: escapeCredentialName "wireguard-${interfaceName}-private-key";
presharedKeyCredential =
-
interfaceName: peer: "wireguard-${interfaceName}-${peer.name}-preshared-key";
+
interfaceName: peer: escapeCredentialName "wireguard-${interfaceName}-${peer.name}-preshared-key";
interfaceCredentials =
interfaceName: interface: