From 047bd73c5e05e8f60abb0ea2a3b22c845404f9cd Mon Sep 17 00:00:00 2001 From: pennae Date: Mon, 13 Feb 2023 10:34:28 +0100 Subject: [PATCH] nixos/wireguard: make publicKeys singleLineStrs using readFile instead of fileContents (or using indented strings) can leave a trailing newline that causes build errors in systemd units and has previously caused runtime errors in wireguard scripts. use singleLineStr to strip a trailing newline if it exists, and to fail if more than one is present. --- nixos/modules/services/networking/wireguard.nix | 2 +- nixos/tests/wireguard/snakeoil-keys.nix | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/networking/wireguard.nix b/nixos/modules/services/networking/wireguard.nix index 1d6556f626be..b08f1015e8b8 100644 --- a/nixos/modules/services/networking/wireguard.nix +++ b/nixos/modules/services/networking/wireguard.nix @@ -176,7 +176,7 @@ let publicKey = mkOption { example = "xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg="; - type = types.str; + type = types.singleLineStr; description = lib.mdDoc "The base64 public key of the peer."; }; diff --git a/nixos/tests/wireguard/snakeoil-keys.nix b/nixos/tests/wireguard/snakeoil-keys.nix index 55ad582d4059..c979f0e0c8a9 100644 --- a/nixos/tests/wireguard/snakeoil-keys.nix +++ b/nixos/tests/wireguard/snakeoil-keys.nix @@ -6,6 +6,7 @@ peer1 = { privateKey = "uO8JVo/sanx2DOM0L9GUEtzKZ82RGkRnYgpaYc7iXmg="; - publicKey = "Ks9yRJIi/0vYgRmn14mIOQRwkcUGBujYINbMpik2SBI="; + # readFile'd keys may have trailing newlines, emulate this + publicKey = "Ks9yRJIi/0vYgRmn14mIOQRwkcUGBujYINbMpik2SBI=\n"; }; }