about summary refs log tree commit diff
path: root/nixos/modules/services/networking
diff options
context:
space:
mode:
authorSandro <sandro.jaeckel@gmail.com>2024-03-01 00:33:36 +0100
committerGitHub <noreply@github.com>2024-03-01 00:33:36 +0100
commitdaa33a4bf72d5311b550b5dfc473a8860686ab06 (patch)
tree6b312c0abccd158ff0cd3412fd90bcd4709d84df /nixos/modules/services/networking
parentfb0f4579cd687c585e26631515e13c3b5fe6f68d (diff)
parent80e79ded15d1fc954de36e3e7c77725ea3fb3489 (diff)
downloadnixlib-daa33a4bf72d5311b550b5dfc473a8860686ab06.tar
nixlib-daa33a4bf72d5311b550b5dfc473a8860686ab06.tar.gz
nixlib-daa33a4bf72d5311b550b5dfc473a8860686ab06.tar.bz2
nixlib-daa33a4bf72d5311b550b5dfc473a8860686ab06.tar.lz
nixlib-daa33a4bf72d5311b550b5dfc473a8860686ab06.tar.xz
nixlib-daa33a4bf72d5311b550b5dfc473a8860686ab06.tar.zst
nixlib-daa33a4bf72d5311b550b5dfc473a8860686ab06.zip
Merge pull request #287299 from SuperSandro2000/unbound-checkconf
nixos/unbound: check validity of config file
Diffstat (limited to 'nixos/modules/services/networking')
-rw-r--r--nixos/modules/services/networking/unbound.nix25
1 files changed, 24 insertions, 1 deletions
diff --git a/nixos/modules/services/networking/unbound.nix b/nixos/modules/services/networking/unbound.nix
index 616b32f11797..8438e472e11e 100644
--- a/nixos/modules/services/networking/unbound.nix
+++ b/nixos/modules/services/networking/unbound.nix
@@ -24,12 +24,24 @@ let
   confNoServer = concatStringsSep "\n" ((mapAttrsToList (toConf "") (builtins.removeAttrs cfg.settings [ "server" ])) ++ [""]);
   confServer = concatStringsSep "\n" (mapAttrsToList (toConf "  ") (builtins.removeAttrs cfg.settings.server [ "define-tag" ]));
 
-  confFile = pkgs.writeText "unbound.conf" ''
+  confFileUnchecked = pkgs.writeText "unbound.conf" ''
     server:
     ${optionalString (cfg.settings.server.define-tag != "") (toOption "  " "define-tag" cfg.settings.server.define-tag)}
     ${confServer}
     ${confNoServer}
   '';
+  confFile = if cfg.checkconf then pkgs.runCommandLocal "unbound-checkconf" { } ''
+    cp ${confFileUnchecked} unbound.conf
+
+    # fake stateDir which is not accesible in the sandbox
+    mkdir -p $PWD/state
+    sed -i unbound.conf \
+      -e '/auto-trust-anchor-file/d' \
+      -e "s|${cfg.stateDir}|$PWD/state|"
+    ${cfg.package}/bin/unbound-checkconf unbound.conf
+
+    cp ${confFileUnchecked} $out
+  '' else confFileUnchecked;
 
   rootTrustAnchorFile = "${cfg.stateDir}/root.key";
 
@@ -62,6 +74,17 @@ in {
         description = lib.mdDoc "Directory holding all state for unbound to run.";
       };
 
+      checkconf = mkOption {
+        type = types.bool;
+        default = !cfg.settings ? include;
+        defaultText = "!config.services.unbound.settings ? include";
+        description = lib.mdDoc ''
+          Wether to check the resulting config file with unbound checkconf for syntax errors.
+
+          If settings.include is used, then this options is disabled, as the import can likely not be resolved at build time.
+        '';
+      };
+
       resolveLocalQueries = mkOption {
         type = types.bool;
         default = true;