From f4023c47b04626982b627159904200db482a2359 Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Sat, 29 Nov 2025 14:47:32 -0600 Subject: [PATCH] Anotther flake.nix bump. --- flake.nix | 75 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/flake.nix b/flake.nix index 72e5ef0..d47bda5 100644 --- a/flake.nix +++ b/flake.nix @@ -10,61 +10,92 @@ outputs = { self, nixpkgs, deploy-rs, disko, nixos-anywhere, ... }: let - system = "x86_64-linux"; + # Default architecture if a system doesn’t override it + defaultSystem = "x86_64-linux"; - pkgs = import nixpkgs { inherit system; }; - lib = pkgs.lib; + # pkgs per-system so cross-arch doesn’t explode later + pkgsFor = system: import nixpkgs { inherit system; }; - addressing = import ./lib/addressing { - inherit lib; - }; + lib = nixpkgs.lib; + # World spec & addressing meta = import ./meta.nix; + addressing = import ./lib/addressing { inherit lib; }; + # Optional for now; meta.systems can be {} until the systems submodule lands systemsFromMeta = meta.systems or { }; + + # Precomputed full network view + network = addressing.mkNetworkFromSpec meta; in { + ######################## + # Library exports + ######################## + lib.metanix = { - inherit meta addressing; - network = addressing.mkNetworkFromSpec meta; + inherit meta addressing network; }; + ######################## + # NixOS configurations + ######################## + nixosConfigurations = lib.mapAttrs (name: sysCfg: let - systemForHost = sysCfg.system or system; + # System for this host, fallback to default + system = sysCfg.system or defaultSystem; + pkgs = pkgsFor system; in lib.nixosSystem { - system = systemForHost; + inherit system; - # Make meta + addressing available to all modules + # Make meta/addressing/world visible to modules specialArgs = { - inherit meta addressing; + inherit lib pkgs meta addressing system; + modulesPath = builtins.toString ; }; modules = (sysCfg.modules or [ ]) ++ [ + # Core Metanix wiring ./modules/metanix/core.nix ./modules/metanix/networkd.nix - # Disko wiring if present + # Identity binding: “this box is in Metanix” + { + networking.hostName = sysCfg.hostName or name; + metanix.thisHost = sysCfg.metanixName or name; + } + + # Optional Disko integration per host (if sysCfg ? diskoConfig then - { imports = [ disko.nixosModules.disko sysCfg.diskoConfig ]; } + { + imports = [ + disko.nixosModules.disko + sysCfg.diskoConfig + ]; + } else { }) ]; }) systemsFromMeta; + ######################## + # deploy-rs + ######################## + deploy = { nodes = lib.mapAttrs (name: sysCfg: let - network = addressing.mkNetworkFromSpec meta; hasNetworkHost = builtins.hasAttr name network.hosts; hostInfo = if hasNetworkHost then network.hosts.${name} else null; + defaultHostname = if hasNetworkHost then hostInfo.fqdn else "${name}.${meta.domain}"; in @@ -74,20 +105,24 @@ profiles.system = { user = sysCfg.deployUser or "root"; path = - deploy-rs.lib.${system}.activate.nixos + deploy-rs.lib.${defaultSystem}.activate.nixos self.nixosConfigurations.${name}; }; }) systemsFromMeta; }; - checks.${system}.deploy = - deploy-rs.lib.${system}.deployChecks self.deploy; + checks.${defaultSystem}.deploy = + deploy-rs.lib.${defaultSystem}.deployChecks self.deploy; - apps.${system}.nixos-anywhere = { + ######################## + # nixos-anywhere helper + ######################## + + apps.${defaultSystem}.nixos-anywhere = { type = "app"; program = - "${nixos-anywhere.packages.${system}.nixos-anywhere}/bin/nixos-anywhere"; + "${nixos-anywhere.packages.${defaultSystem}.nixos-anywhere}/bin/nixos-anywhere"; }; }; }