diff options
author | Paul Schyska <paul@schyska.net> | 2021-05-19 00:59:33 +0200 |
---|---|---|
committer | Paul Schyska <paul@schyska.net> | 2021-05-19 18:21:10 +0200 |
commit | 69202853ea8ae2d92c0d6344cd9446421cc2a4bd (patch) | |
tree | 6dee5b5bf116ac3b56fb3c0e167d8b951e87b79c /nixos/modules/services/networking/nsd.nix | |
parent | a4a35cdb0de5b278499df95fe827903ebf707a64 (diff) | |
download | nixpkgs-69202853ea8ae2d92c0d6344cd9446421cc2a4bd.tar nixpkgs-69202853ea8ae2d92c0d6344cd9446421cc2a4bd.tar.gz nixpkgs-69202853ea8ae2d92c0d6344cd9446421cc2a4bd.tar.bz2 nixpkgs-69202853ea8ae2d92c0d6344cd9446421cc2a4bd.tar.lz nixpkgs-69202853ea8ae2d92c0d6344cd9446421cc2a4bd.tar.xz nixpkgs-69202853ea8ae2d92c0d6344cd9446421cc2a4bd.tar.zst nixpkgs-69202853ea8ae2d92c0d6344cd9446421cc2a4bd.zip |
nixos/nsd: make nsd-checkconf work when configuration contains keys
Diffstat (limited to 'nixos/modules/services/networking/nsd.nix')
-rw-r--r-- | nixos/modules/services/networking/nsd.nix | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/nixos/modules/services/networking/nsd.nix b/nixos/modules/services/networking/nsd.nix index f33c350a257..2ac0a8c7922 100644 --- a/nixos/modules/services/networking/nsd.nix +++ b/nixos/modules/services/networking/nsd.nix @@ -20,6 +20,15 @@ let mkZoneFileName = name: if name == "." then "root" else name; + # replaces include: directives for keys with fake keys for nsd-checkconf + injectFakeKeys = keys: concatStrings + (mapAttrsToList + (keyName: keyOptions: '' + fakeKey="$(${pkgs.bind}/bin/tsig-keygen -a ${escapeShellArgs [ keyOptions.algorithm keyName ]} | grep -oP "\s*secret \"\K.*(?=\";)")" + sed "s@^\s*include:\s*\"${stateDir}/private/${keyName}\"\$@secret: $fakeKey@" -i $out/nsd.conf + '') + keys); + nsdEnv = pkgs.buildEnv { name = "nsd-env"; @@ -34,9 +43,9 @@ let echo "|- checking zone '$out/zones/$zoneFile'" ${nsdPkg}/sbin/nsd-checkzone "$zoneFile" "$zoneFile" || { if grep -q \\\\\\$ "$zoneFile"; then - echo zone "$zoneFile" contains escaped dollar signes \\\$ - echo Escaping them is not needed any more. Please make shure \ - to unescape them where they prefix a variable name + echo zone "$zoneFile" contains escaped dollar signs \\\$ + echo Escaping them is not needed any more. Please make sure \ + to unescape them where they prefix a variable name. fi exit 1 @@ -44,7 +53,14 @@ let done echo "checking configuration file" + # Save original config file including key references... + cp $out/nsd.conf{,.orig} + # ...inject mock keys into config + ${injectFakeKeys cfg.keys} + # ...do the checkconf ${nsdPkg}/sbin/nsd-checkconf $out/nsd.conf + # ... and restore original config file. + mv $out/nsd.conf{.orig,} ''; }; |