diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c4a847d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/result diff --git a/flake.nix b/flake.nix index b79301a..095f269 100644 --- a/flake.nix +++ b/flake.nix @@ -6,22 +6,29 @@ dns.url = "github:nix-community/dns.nix"; }; - outputs = { nixpkgs, dns, ... }@inputs: - let - inherit (nixpkgs) lib; - systems = [ - "x86_64-linux" - "aarch64-linux" - "aarch64-darwin" - ]; - forAllSystems = f: lib.genAttrs systems f; - in { - packages = forAllSystems (system: rec { - zoneConfig = nixpkgs.legacyPackages.${system}.callPackage ./zoneConfig.nix { - inherit dns; - }; - default = zoneConfig; - }); - }; + outputs = + { nixpkgs, dns, ... }@inputs: + let + inherit (nixpkgs) lib; + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + ]; + forAllSystems = f: lib.genAttrs systems f; + in + { + packages = forAllSystems ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + rec { + zoneConfig = pkgs.callPackage ./zoneConfig.nix { + inherit dns; + }; + default = zoneConfig; + } + ); + }; } - diff --git a/zoneConfig.nix b/zoneConfig.nix index 7f2a91f..00f5e93 100644 --- a/zoneConfig.nix +++ b/zoneConfig.nix @@ -1,14 +1,27 @@ { lib, - stdenvNoCC, dns, + + stdenvNoCC, + writeText, }: +let + zoneConfigs = + lib.mapAttrs + (name: path: writeText "${name}.zone" (dns.lib.toString name (import path { inherit dns; }))) + { + "pvv.ntnu.no" = ./zones/pvv.ntnu.no.nix; + }; +in stdenvNoCC.mkDerivation { name = "zoneConfig"; dontUnpack = true; - installPhase = '' - mkdir $out - ''; + installPhase = + '' + mkdir -p $out/zones + + '' + + (lib.concatMapAttrsStringSep "\n" (name: path: "cp ${path} $out/zones/${name}.zone") zoneConfigs); } diff --git a/zones/pvv.ntnu.no.nix b/zones/pvv.ntnu.no.nix new file mode 100644 index 0000000..3ddb2df --- /dev/null +++ b/zones/pvv.ntnu.no.nix @@ -0,0 +1,23 @@ +{ dns, ... }: + +with dns.lib.combinators; +{ + SOA = { + nameServer = "ns1.pvv.ntnu.no"; + adminEmail = "drift@pvv.ntnu.no"; + serial = 2025021701; # TODO: Automate + }; + NS = [ + "ns1.pvv.ntnu.no" + "ns2.pvv.ntnu.no" + ]; + + CNAME = [ "www.pvv.ntnu.no" ]; + + subdomains = rec { + foobar = host "203.0.113.2" "4321:0:1:2:3:4:567:89bb"; + + ns1 = foobar; + ns2 = host "203.0.113.3" "4321:0:1:2:3:4:567:89cc"; + }; +}