Better addressing?

This commit is contained in:
Yaro Kasear 2026-05-01 13:07:30 -05:00
parent b5c1a43863
commit f35e402b4d
3 changed files with 394 additions and 261 deletions

View file

@ -10,67 +10,48 @@
outputs = { self, nixpkgs, deploy-rs, disko, nixos-anywhere, ... }:
let
# Default architecture if a system doesnt override it
defaultSystem = "x86_64-linux";
# pkgs per-system so cross-arch doesnt explode later
pkgsFor = system: import nixpkgs { inherit system; };
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;
};
########################
# NixOS configurations
########################
nixosConfigurations =
lib.mapAttrs
(name: sysCfg:
let
# System for this host, fallback to default
system = sysCfg.system or defaultSystem;
pkgs = pkgsFor system;
in
lib.nixosSystem {
inherit system;
# Make meta/addressing/world visible to modules
specialArgs = {
inherit lib pkgs meta addressing system;
modulesPath = builtins.toString <nixpkgs/nixos/modules>;
inherit lib meta addressing system network;
modulesPath = "${nixpkgs}/nixos/modules";
};
modules =
(sysCfg.modules or [ ]) ++ [
# Core Metanix wiring
./modules/metanix/core.nix
./modules/metanix/networkd.nix
# Identity binding: “this box is <name> in Metanix”
{
networking.hostName = sysCfg.hostName or name;
metanix.thisHost = sysCfg.metanixName or name;
}
# Optional Disko integration per host
(if sysCfg ? diskoConfig then
{
imports = [
@ -84,10 +65,6 @@
})
systemsFromMeta;
########################
# deploy-rs
########################
deploy = {
nodes =
lib.mapAttrs
@ -97,7 +74,10 @@
hostInfo = if hasNetworkHost then network.hosts.${name} else null;
defaultHostname =
if hasNetworkHost then hostInfo.fqdn else "${name}.${meta.domain}";
if hasNetworkHost && hostInfo ? fqdn then
hostInfo.fqdn
else
name;
in
{
hostname = sysCfg.deployHost or defaultHostname;
@ -112,12 +92,10 @@
systemsFromMeta;
};
checks.${defaultSystem}.deploy =
deploy-rs.lib.${defaultSystem}.deployChecks self.deploy;
########################
# nixos-anywhere helper
########################
checks =
builtins.mapAttrs
(system: deployLib: deployLib.deployChecks self.deploy)
deploy-rs.lib;
apps.${defaultSystem}.nixos-anywhere = {
type = "app";