From 35bfc55356b19a4555597e583035f70ac19a9265 Mon Sep 17 00:00:00 2001 From: Kalle Struik Date: Mon, 3 Feb 2025 16:58:33 +0100 Subject: [PATCH] Different hosts config layout + use IPs --- flake.nix | 9 ++++++--- hosts.nix | 45 ++++++++++++++------------------------------- hosts/base.nix | 15 +++++++++++++++ hosts/nix-test.nix | 19 +++++++++++++++++++ roles/sonarr.nix | 2 +- 5 files changed, 55 insertions(+), 35 deletions(-) create mode 100644 hosts/base.nix create mode 100644 hosts/nix-test.nix diff --git a/flake.nix b/flake.nix index 34cb0cb..b6ecb61 100644 --- a/flake.nix +++ b/flake.nix @@ -18,14 +18,17 @@ homelabConfig = import ./config.nix; roles = import ./roles { inherit utils; }; - hosts = import ./hosts.nix { inherit homelabConfig roles; }; + hosts = import ./hosts.nix { + inherit homelabConfig roles; + lib = nixpkgs.lib; + }; in { nixosConfigurations = nixpkgs.lib.mapAttrs ( - hostname: value: + _: value: (utils.mkSystem { inherit hosts; - hostConfig = (value // { inherit hostname; }); + hostConfig = value; }) ) hosts; }; diff --git a/hosts.nix b/hosts.nix index a5d316a..b196c5e 100644 --- a/hosts.nix +++ b/hosts.nix @@ -1,37 +1,20 @@ { roles, homelabConfig, + lib, ... }: -let - hlConfig = homelabConfig; -in -{ - base = { - roles = [ ]; - config = { }; - stateVersion = "24.05"; - }; - - nix-test = { - roles = with roles; [ - traefik - sonarr - ]; - config = { - sonarr.domain = "sonarr2.${hlConfig.domain}"; - traefik.wildcardDomains = [ hlConfig.domain ]; +lib.attrsets.mapAttrs' ( + name: _: + let + cfg = import (./hosts + "/${name}") { + inherit roles; + hlConfig = homelabConfig; }; - stateVersion = "24.05"; - }; - - nix-test2 = { - roles = with roles; [ - sonarr - ]; - config = { - sonarr.domain = "sonarr.${hlConfig.domain}"; - }; - stateVersion = "24.05"; - }; -} + hostname = cfg.hostname; + in + { + name = hostname; + value = cfg; + } +) (builtins.readDir ./hosts) diff --git a/hosts/base.nix b/hosts/base.nix new file mode 100644 index 0000000..2d18d85 --- /dev/null +++ b/hosts/base.nix @@ -0,0 +1,15 @@ +{ + roles, + hlConfig, +}: +{ + hostname = "base"; + managed = true; + ip = "192.168.10.98"; + + roles = with roles; [ + ]; + config = { + }; + stateVersion = "24.05"; +} diff --git a/hosts/nix-test.nix b/hosts/nix-test.nix new file mode 100644 index 0000000..6578d36 --- /dev/null +++ b/hosts/nix-test.nix @@ -0,0 +1,19 @@ +{ + roles, + hlConfig, +}: +{ + hostname = "nix-test"; + managed = true; + ip = "192.168.10.99"; + + roles = with roles; [ + traefik + sonarr + ]; + config = { + sonarr.domain = "sonarr2.${hlConfig.domain}"; + traefik.wildcardDomains = [ hlConfig.domain ]; + }; + stateVersion = "24.05"; +} diff --git a/roles/sonarr.nix b/roles/sonarr.nix index 6d19d77..b07e964 100644 --- a/roles/sonarr.nix +++ b/roles/sonarr.nix @@ -14,7 +14,7 @@ { name = "${hostname}-sonarr"; rule = "Host(`${config.sonarr.domain}`)"; - target = "http://${hostname}.lan:8989"; + target = "http://${config.ip}:8989"; } ];