diff --git a/flake.nix b/flake.nix index 9f07826..2e300f4 100644 --- a/flake.nix +++ b/flake.nix @@ -68,9 +68,7 @@ nixosConfigurations = (import ./hosts inputs); colmenaHive = colmena.lib.makeHive self.outputs.colmena; - colmena = lib.recursiveUpdate (builtins.mapAttrs (k: v: { - imports = v._module.args.modules; - }) self.nixosConfigurations) hosts; + colmena = hosts; devShells.${system}.default = pkgs.mkShell { buildInputs = with pkgs; [ diff --git a/hosts/default.nix b/hosts/default.nix index 66c1ee0..239f702 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -12,10 +12,7 @@ let agenixOverlay = final: prev: { agenix = agenix.packages.${prev.system}.default; }; - customOverlays = ( - final: prev: { - } - ); + customOverlays = (final: prev: { }); mkPkgs = nixpkgsSrc: system: @@ -61,8 +58,29 @@ let inherit specialArgs; }; + # Import the unified host definitions + hostDefs = import ./hosts.nix; + + # Generate nixosConfigurations from host definitions + lxcHosts = nixpkgs.lib.mapAttrs ( + name: cfg: + mkLXC { + hostModule = cfg.module; + unstable = cfg.unstable or false; + extraModules = cfg.extraModules or [ ]; + specialArgs = cfg.specialArgs or { }; + } + ) hostDefs; + in -{ +lxcHosts +// { + # Special hosts that don't use mkLXC pattern + baseLXC = mkLXC { + hostModule = ./base-lxc.nix; + specialArgs = { inherit self; }; + }; + # deadbeef = nixpkgs.lib.nixosSystem { # pkgs = mkPkgs nixpkgs "x86_64-linux"; # modules = [ @@ -72,41 +90,4 @@ in # agenix.nixosModules.default # ]; # }; - - baseLXC = mkLXC { - hostModule = ./base-lxc.nix; - specialArgs = { inherit self; }; - }; - - arr = mkLXC { hostModule = ./arr; }; - caddy = mkLXC { hostModule = ./caddy; }; - colmena = mkLXC { hostModule = ./colmena; }; - dns01 = mkLXC { hostModule = ./dns/dns-01.nix; }; - dns02 = mkLXC { hostModule = ./dns/dns-02.nix; }; - firefly-iii = mkLXC { hostModule = ./firefly-iii; }; - forgejo = mkLXC { hostModule = ./forgejo; }; - immich = mkLXC { hostModule = ./immich; }; - metrics = mkLXC { hostModule = ./metrics; }; - n8n = mkLXC { hostModule = ./n8n; }; - nextcloud = mkLXC { hostModule = ./nextcloud; }; - plex = mkLXC { hostModule = ./plex; }; - portainer = mkLXC { hostModule = ./portainer; }; - shadowsocks = mkLXC { hostModule = ./shadowsocks; }; - vaultwarden = mkLXC { hostModule = ./vaultwarden; }; - - # Hosts requiring nixpkgs-unstable - authentik = mkLXC { - hostModule = ./authentik; - unstable = true; - }; - - paperless = mkLXC { - hostModule = ./paperless; - unstable = true; - }; - - zigbee2mqtt = mkLXC { - hostModule = ./zigbee2mqtt; - unstable = true; - }; } diff --git a/hosts/deployments.nix b/hosts/deployments.nix index 83617cc..57d49e0 100644 --- a/hosts/deployments.nix +++ b/hosts/deployments.nix @@ -2,10 +2,21 @@ let p = import ./parameters.nix; hosts = p.hosts; + hostDefs = import ./hosts.nix; + + # Generate complete colmena host configs (imports + deployment) + mkColmenaHosts = builtins.mapAttrs (name: cfg: { + imports = inputs.self.nixosConfigurations.${name}._module.args.modules; + deployment = { + targetHost = hosts.${name} or null; + tags = cfg.tags; + }; + }) hostDefs; + in -{ +mkColmenaHosts +// { meta = { - # Configuration used by colmena to build nixpkgs = import inputs.nixpkgs { system = "x86_64-linux"; overlays = [ ]; @@ -15,179 +26,20 @@ in nodeSpecialArgs = builtins.mapAttrs (_: v: v._module.specialArgs) inputs.self.nixosConfigurations; }; - arr.deployment = { - targetHost = hosts.arr; - tags = [ - "lxc" - "bacco" - "arr" - ]; + # Special hosts not defined in hosts.nix + baseLXC = { + imports = inputs.self.nixosConfigurations.baseLXC._module.args.modules; + deployment = { + targetHost = null; + tags = [ "template" ]; + }; }; - caddy.deployment = { - targetHost = hosts.caddy; - tags = [ - "lxc" - "bacco" - "arr" - "auth" - "metrics" - "nextcloud" - "portainer" - "vaultwarden" - "immich" - "firefly-iii" - "paperless" - ]; + deadbeef = { + deployment = { + allowLocalDeployment = true; + targetHost = null; + tags = [ "local" ]; + }; }; - - metrics.deployment = { - targetHost = hosts.metrics; - tags = [ - "lxc" - "bacco" - "metrics" - ]; - }; - - nextcloud.deployment = { - targetHost = hosts.nextcloud; - tags = [ - "lxc" - "bacco" - "nextcloud" - ]; - }; - - vaultwarden.deployment = { - targetHost = hosts.vaultwarden; - tags = [ - "lxc" - "bacco" - "vaultwarden" - ]; - }; - - plex.deployment = { - targetHost = hosts.plex; - tags = [ - "lxc" - "node" - ]; - }; - - portainer.deployment = { - targetHost = hosts.portainer; - tags = [ - "lxc" - "bacco" - "portainer" - ]; - }; - - authentik.deployment = { - targetHost = hosts.authentik; - tags = [ - "lxc" - "bacco" - "auth" - ]; - }; - - colmena.deployment = { - targetHost = hosts.colmena; - tags = [ - "lxc" - "bacco" - "colmena" - ]; - }; - - dns01.deployment = { - targetHost = hosts.dns01; - tags = [ - "lxc" - "bacco" - "dns" - ]; - }; - - dns02.deployment = { - targetHost = hosts.dns02; - tags = [ - "lxc" - "bacco" - "dns" - ]; - }; - - shadowsocks.deployment = { - targetHost = hosts.shadowsocks; - tags = [ - "lxc" - "bacco" - "shadowsocks" - ]; - }; - - immich.deployment = { - targetHost = hosts.immich; - tags = [ - "lxc" - "bacco" - "immich" - ]; - }; - - firefly-iii.deployment = { - targetHost = hosts.firefly-iii; - tags = [ - "lxc" - "bacco" - "firefly-iii" - ]; - }; - - paperless.deployment = { - targetHost = hosts.paperless; - tags = [ - "lxc" - "bacco" - "paperless" - ]; - }; - - zigbee2mqtt.deployment = { - targetHost = hosts.zigbee2mqtt; - tags = [ - "lxc" - "bacco" - "zigbee2mqtt" - ]; - }; - - forgejo.deployment = { - targetHost = hosts.forgejo; - tags = [ - "lxc" - "bacco" - "forgejo" - ]; - }; - - n8n.deployment = { - targetHost = hosts.n8n; - tags = [ - "lxc" - "bacco" - "n8n" - ]; - }; - - deadbeef.deployment = { - allowLocalDeployment = true; - targetHost = null; - tags = [ "local" ]; - }; - } diff --git a/hosts/hosts.nix b/hosts/hosts.nix new file mode 100644 index 0000000..69e96bb --- /dev/null +++ b/hosts/hosts.nix @@ -0,0 +1,183 @@ +# Single source of truth for all host definitions +# Each host specifies its module path, deployment tags, and optional flags +{ + arr = { + module = ./arr; + tags = [ + "lxc" + "bacco" + "arr" + ]; + }; + + authentik = { + module = ./authentik; + unstable = true; + tags = [ + "lxc" + "bacco" + "auth" + ]; + }; + + caddy = { + module = ./caddy; + tags = [ + "lxc" + "bacco" + "arr" + "auth" + "metrics" + "nextcloud" + "portainer" + "vaultwarden" + "immich" + "firefly-iii" + "paperless" + ]; + }; + + colmena = { + module = ./colmena; + tags = [ + "lxc" + "bacco" + "colmena" + ]; + }; + + dns01 = { + module = ./dns/dns-01.nix; + tags = [ + "lxc" + "bacco" + "dns" + ]; + }; + + dns02 = { + module = ./dns/dns-02.nix; + tags = [ + "lxc" + "bacco" + "dns" + ]; + }; + + firefly-iii = { + module = ./firefly-iii; + tags = [ + "lxc" + "bacco" + "firefly-iii" + ]; + }; + + forgejo = { + module = ./forgejo; + tags = [ + "lxc" + "bacco" + "forgejo" + ]; + }; + + immich = { + module = ./immich; + tags = [ + "lxc" + "bacco" + "immich" + ]; + }; + + metrics = { + module = ./metrics; + tags = [ + "lxc" + "bacco" + "metrics" + ]; + }; + + n8n = { + module = ./n8n; + tags = [ + "lxc" + "bacco" + "n8n" + ]; + }; + + nextcloud = { + module = ./nextcloud; + tags = [ + "lxc" + "bacco" + "nextcloud" + ]; + }; + + paperless = { + module = ./paperless; + unstable = true; + tags = [ + "lxc" + "bacco" + "paperless" + ]; + }; + + plex = { + module = ./plex; + tags = [ + "lxc" + "node" + ]; + }; + + portainer = { + module = ./portainer; + tags = [ + "lxc" + "bacco" + "portainer" + ]; + }; + + shadowsocks = { + module = ./shadowsocks; + tags = [ + "lxc" + "bacco" + "shadowsocks" + ]; + }; + + vaultwarden = { + module = ./vaultwarden; + tags = [ + "lxc" + "bacco" + "vaultwarden" + ]; + }; + + zigbee2mqtt = { + module = ./zigbee2mqtt; + unstable = true; + tags = [ + "lxc" + "bacco" + "zigbee2mqtt" + ]; + }; + + # Special hosts (non-LXC or local deployment) + # deadbeef = { + # module = ./deadbeef; + # type = "workstation"; # Not an LXC + # localDeployment = true; + # tags = [ "local" ]; + # }; +}