Switch to dns.nix

This commit is contained in:
Sandro - 2024-04-20 22:45:22 +02:00
parent 54c215c320
commit e90f8e7ea6
Signed by: sandro
GPG Key ID: 3AF5A43A3EECC2E5
3 changed files with 62 additions and 21 deletions

View File

@ -1,5 +1,41 @@
{
"nodes": {
"dns-nix": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1703643450,
"narHash": "sha256-EUUF5oxFFPX/etKm0FNQg+7MPHQlNjmM1XhNgyDf7A0=",
"owner": "NickCao",
"repo": "dns.nix",
"rev": "70dcce71560d4253f63812fa36dee994c81ae814",
"type": "github"
},
"original": {
"owner": "NickCao",
"repo": "dns.nix",
"type": "github"
}
},
"flake-utils": {
"locked": {
"lastModified": 1614513358,
"narHash": "sha256-LakhOx3S1dRjnh0b5Dg3mbZyH0ToC9I8Y2wKSkBaTzU=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5466c5bbece17adaab2d82fae80b46e807611bf3",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1713475287,
@ -55,6 +91,7 @@
},
"root": {
"inputs": {
"dns-nix": "dns-nix",
"nixpkgs": "nixpkgs",
"openwrt": "openwrt",
"openwrt-imagebuilder": "openwrt-imagebuilder"

View File

@ -2,6 +2,10 @@
description = "Zentralwerk network";
inputs = {
dns-nix = {
url = "github:NickCao/dns.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs.url = "github:SuperSandro2000/nixpkgs/nixos-23.11";
openwrt = {
url = "git+https://git.openwrt.org/openwrt/openwrt.git?ref=openwrt-23.05";
@ -13,7 +17,7 @@
};
};
outputs = inputs@{ self, nixpkgs, openwrt, openwrt-imagebuilder }:
outputs = inputs@{ self, dns-nix, nixpkgs, openwrt, openwrt-imagebuilder }:
let
system = "x86_64-linux";
systems = [ system ];
@ -26,7 +30,7 @@
specialArgs = {
hostName = name;
inherit (self) lib;
inherit inputs self;
inherit inputs dns-nix self;
};
};
in {

View File

@ -1,26 +1,26 @@
{ hostName, config, lib, pkgs, self, ... }:
{ config, dns-nix, hostName, lib, pkgs, self, ... }:
let
serial = builtins.substring 0 10 self.lastModifiedDate;
generateZoneFile = { name, ns, records, dynamic }:
builtins.toFile "${name}.zone" ''
$ORIGIN ${name}.
$TTL 1h
@ IN SOA ${lib.dns.ns}. astro.spaceboyz.net. (
${serial} ; serial
1h ; refresh
1m ; retry
2h ; expire
1m ; minimum
)
${lib.concatMapStrings (ns: " IN NS ${ns}.\n") ns}
${lib.concatMapStrings ({ name, type, data }:
"${name} IN ${type} ${data}\n"
) records}
'';
generateZoneFile = let
util = dns-nix.util.${pkgs.system};
in { name, ns, records, ... }: util.writeZone name (with dns-nix.lib.combinators; {
TTL = 60*60;
SOA = {
nameServer = lib.dns.ns;
adminEmail = "astro@spaceboyz.net";
serial = lib.toInt serial;
refresh = 60*60;
retry = 60;
expire = 2*60;
minimum = 60;
};
NS = ns;
subdomains = lib.head (map ({ name, type, data }: {
${name}.${type} = [ data ];
}) records ++ [ { } ]);
});
in
{
options =