diff --git a/flake.nix b/flake.nix index 5661800..a5ab660 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ }; outputs = - { nixpkgs, dns, ... }@inputs: + { self, nixpkgs, dns, ... }@inputs: let inherit (nixpkgs) lib; systems = [ @@ -27,7 +27,7 @@ inherit dns; }; - nsdConfig = pkgs.callPackage ./nsd.conf.nix { inherit pkgs; }; + nsdConfig = pkgs.callPackage ./nsd.conf.nix { }; default = pkgs.runCommand "pvv-dns" { } '' mkdir -p $out/zones @@ -37,5 +37,10 @@ cp -r ${nsdConfig} $out/etc/nsd/nsd.conf ''; }); + + checks = forAllSystems (system: _: rec { + zoneFiles = self.packages.${system}.zoneFiles.overrideAttrs { doCheck = true; }; + nsdConfig = self.packages.${system}.nsdConfig.override { doCheck = true; }; + }); }; } diff --git a/nsd.conf.nix b/nsd.conf.nix index 6b4b3bf..3c13724 100644 --- a/nsd.conf.nix +++ b/nsd.conf.nix @@ -1,9 +1,15 @@ -{ pkgs, ... }: +{ + lib, + writeTextFile, + doCheck ? false, + nsd, +}: let sourceIP = "129.241.210.211"; # dvask.pvv.ntnu.no in -pkgs.writeText "nsd.conf" ( - '' +writeTextFile { + name = "nsd.conf"; + text = '' # Generated by https://git.pvv.ntnu.no/felixalb/PVV-DNS # See man 5 nsd.conf @@ -56,5 +62,7 @@ pkgs.writeText "nsd.conf" ( "pvv.ntnu.no" "pvv.org" ] - )) -) + )); + + checkPhase = lib.optionalString doCheck "${lib.getExe' nsd "nsd-checkconf"} $target"; +} diff --git a/zoneConfig.nix b/zoneConfig.nix index c6a2b37..331cc05 100644 --- a/zoneConfig.nix +++ b/zoneConfig.nix @@ -4,6 +4,7 @@ stdenvNoCC, writeText, + nsd, }: let @@ -33,4 +34,14 @@ stdenvNoCC.mkDerivation { mkdir -p $out '' + (lib.concatMapAttrsStringSep "\n" (name: path: "cp ${path} $out/${name}.zone") zoneConfigs); + + doCheck = false; + nativeCheckInputs = [ nsd ]; + checkPhase = '' + runHook preCheck + + ${lib.concatMapAttrsStringSep "\n" (name: zonefile: "nsd-checkzone '${name}' '${zonefile}'") zoneConfigs} + + runHook postCheck + ''; }