central IP

This commit is contained in:
nora 2024-07-31 20:05:02 +02:00
parent 59ec8ef37b
commit cfe47e65c0
4 changed files with 42 additions and 28 deletions

View file

@ -7,6 +7,29 @@
# - An initialized Nixpkgs attribute set # - An initialized Nixpkgs attribute set
nixpkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/a1cc729dcbc31d9b0d11d86dc7436163548a9665.tar.gz"); # nixos-24.05 2024-07-26 nixpkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/a1cc729dcbc31d9b0d11d86dc7436163548a9665.tar.gz"); # nixos-24.05 2024-07-26
specialArgs = {
networkingConfig = {
dns1 = {
publicIPv4 = "154.38.163.74";
publicIPv6 = null;
};
dns2 = {
publicIPv4 = "128.140.3.7";
publicIPv6 = "2a01:4f8:c2c:d616::";
};
vps1 = {
publicIPv4 = "161.97.165.1";
publicIPv6 = null;
};
vps3 = {
publicIPv4 = "134.255.181.139";
publicIPv6 = null;
};
};
};
# If your Colmena host has nix configured to allow for remote builds # If your Colmena host has nix configured to allow for remote builds
# (for nix-daemon, your user being included in trusted-users) # (for nix-daemon, your user being included in trusted-users)
# you can set a machines file that will be passed to the underlying # you can set a machines file that will be passed to the underlying

View file

@ -1,4 +1,4 @@
{ pkgs, lib, ... }: { { pkgs, lib, networkingConfig, ... }: {
# get the package for the debugging tools # get the package for the debugging tools
environment.systemPackages = with pkgs; [ knot-dns ]; environment.systemPackages = with pkgs; [ knot-dns ];
@ -29,10 +29,10 @@
zone: zone:
- domain: noratrieb.dev - domain: noratrieb.dev
storage: /var/lib/knot/zones/ storage: /var/lib/knot/zones/
file: ${import ./noratrieb.dev.nix { inherit pkgs; inherit lib; }} file: ${import ./noratrieb.dev.nix { inherit pkgs lib networkingConfig; }}
- domain: nilstrieb.dev - domain: nilstrieb.dev
storage: /var/lib/knot/zones/ storage: /var/lib/knot/zones/
file: ${import ./nilstrieb.dev.nix { inherit pkgs; inherit lib; }} file: ${import ./nilstrieb.dev.nix { inherit pkgs lib; }}
log: log:
- target: syslog - target: syslog
any: info any: info

View file

@ -4,15 +4,13 @@ let
data = with pkgs.nix-dns.lib.combinators; data = with pkgs.nix-dns.lib.combinators;
let let
hour1 = 3600; hour1 = 3600;
normalHost = ipv4: ipv6: hostsToDns = builtins.mapAttrs
lib.optionalAttrs (ipv4 != null) { A = [ (ttl hour1 (a ipv4)) ]; } // (name: { publicIPv4, publicIPv6 }:
lib.optionalAttrs (ipv6 != null) { AAAA = [ (ttl hour1 (aaaa ipv6)) ]; }; lib.optionalAttrs (publicIPv4 != null) { A = [ (ttl hour1 (a publicIPv4)) ]; } //
dns1 = normalHost "154.38.163.74" null; lib.optionalAttrs (publicIPv6 != null) { AAAA = [ (ttl hour1 (aaaa publicIPv6)) ]; })
dns2 = normalHost "128.140.3.7" "2a01:4f8:c2c:d616::"; networkingConfig;
vps1 = normalHost "161.97.165.1" null;
vps2 = normalHost "184.174.32.252" null;
in in
with hostsToDns;
{ {
SOA = { SOA = {
nameServer = "ns1.nilstrieb.dev"; nameServer = "ns1.nilstrieb.dev";

View file

@ -1,18 +1,16 @@
# https://github.com/nix-community/dns.nix # https://github.com/nix-community/dns.nix
{ pkgs, lib, ... }: { pkgs, lib, networkingConfig, ... }:
let let
data = with pkgs.nix-dns.lib.combinators; data = with pkgs.nix-dns.lib.combinators;
let let
hour1 = 3600; hour1 = 3600;
normalHost = ipv4: ipv6: hostsToDns = builtins.mapAttrs
lib.optionalAttrs (ipv4 != null) { A = [ (ttl hour1 (a ipv4)) ]; } // (name: { publicIPv4, publicIPv6 }:
lib.optionalAttrs (ipv6 != null) { AAAA = [ (ttl hour1 (aaaa ipv6)) ]; }; lib.optionalAttrs (publicIPv4 != null) { A = [ (ttl hour1 (a publicIPv4)) ]; } //
dns1 = normalHost "154.38.163.74" null; lib.optionalAttrs (publicIPv6 != null) { AAAA = [ (ttl hour1 (aaaa publicIPv6)) ]; })
dns2 = normalHost "128.140.3.7" "2a01:4f8:c2c:d616::"; networkingConfig;
vps1 = normalHost "161.97.165.1" null;
vps3 = normalHost "134.255.181.139" null;
in in
with hostsToDns;
# vps1 contains root noratrieb.dev # vps1 contains root noratrieb.dev
vps1 // { vps1 // {
SOA = { SOA = {
@ -37,17 +35,12 @@ let
localhost.A = [ (a "127.0.0.1") ]; localhost.A = [ (a "127.0.0.1") ];
newtest.TXT = [ "uwu it works" ]; newtest.TXT = [ "uwu it works" ];
# TODO: generate dynamically from IPs... infra.subdomains = hostsToDns;
infra.subdomains = {
inherit dns1;
inherit dns2;
inherit vps1;
inherit vps3;
};
}; };
}; };
in in
pkgs.writeTextFile { pkgs.writeTextFile
{
name = "noratrieb.dev.zone"; name = "noratrieb.dev.zone";
text = pkgs.nix-dns.lib.toString "noratrieb.dev" data; text = pkgs.nix-dns.lib.toString "noratrieb.dev" data;
} }