Adding more structure.
This commit is contained in:
parent
551b401efa
commit
896c5ff939
2 changed files with 89 additions and 65 deletions
83
flake.nix
83
flake.nix
|
|
@ -10,101 +10,60 @@
|
||||||
|
|
||||||
outputs = { self, nixpkgs, deploy-rs, disko, nixos-anywhere, ... }:
|
outputs = { self, nixpkgs, deploy-rs, disko, nixos-anywhere, ... }:
|
||||||
let
|
let
|
||||||
# Default architecture if meta.nix doesn't say otherwise
|
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
|
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs { inherit system; };
|
||||||
inherit system;
|
|
||||||
};
|
|
||||||
|
|
||||||
lib = pkgs.lib;
|
lib = pkgs.lib;
|
||||||
|
|
||||||
# Your mkIp / mkHostsFromSpec / mkSubnetsFromSpec, etc.
|
|
||||||
# This expects: lib/addressing/default.nix
|
|
||||||
addressing = import ./lib/addressing {
|
addressing = import ./lib/addressing {
|
||||||
inherit lib;
|
inherit lib;
|
||||||
};
|
};
|
||||||
|
|
||||||
# User-provided world model.
|
|
||||||
meta = import ./meta.nix;
|
meta = import ./meta.nix;
|
||||||
|
|
||||||
# Uses your rewritten mkNetworkFromSpec that understands meta.nix shape.
|
|
||||||
network = addressing.mkNetworkFromSpec meta;
|
|
||||||
|
|
||||||
# Optional: meta.systems = { hostName = { system = "..."; modules = [ ... ]; ... }; ...; }
|
|
||||||
systemsFromMeta = meta.systems or { };
|
systemsFromMeta = meta.systems or { };
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
#######################
|
lib.metanix = {
|
||||||
# Library-style exports
|
inherit meta addressing;
|
||||||
#######################
|
network = addressing.mkNetworkFromSpec meta;
|
||||||
lib = {
|
|
||||||
metanix = {
|
|
||||||
inherit meta network addressing;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#############################
|
|
||||||
# Per-host NixOS configs
|
|
||||||
#
|
|
||||||
# Driven by meta.systems if present. Shape example:
|
|
||||||
# meta.systems = {
|
|
||||||
# deimos = {
|
|
||||||
# system = "x86_64-linux";
|
|
||||||
# modules = [ ./hosts/deimos.nix ];
|
|
||||||
# diskoConfig = ./disko/deimos.nix; # optional
|
|
||||||
# deployHost = "deimos.kasear.net"; # optional
|
|
||||||
# deployUser = "root"; # optional
|
|
||||||
# };
|
|
||||||
# };
|
|
||||||
#############################
|
|
||||||
nixosConfigurations =
|
nixosConfigurations =
|
||||||
lib.mapAttrs
|
lib.mapAttrs
|
||||||
(name: sysCfg:
|
(name: sysCfg:
|
||||||
let
|
let
|
||||||
systemForHost = sysCfg.system or system;
|
systemForHost = sysCfg.system or system;
|
||||||
|
in
|
||||||
|
lib.nixosSystem {
|
||||||
|
system = systemForHost;
|
||||||
|
|
||||||
pkgsForHost = import nixpkgs {
|
# Make meta + addressing available to all modules
|
||||||
inherit systemForHost;
|
specialArgs = {
|
||||||
|
inherit meta addressing;
|
||||||
};
|
};
|
||||||
|
|
||||||
hostLib = pkgsForHost.lib;
|
|
||||||
|
|
||||||
# Optional disko module wiring if sysCfg.diskoConfig exists.
|
|
||||||
diskoModule =
|
|
||||||
if sysCfg ? diskoConfig then
|
|
||||||
{ imports = [ disko.nixosModules.disko sysCfg.diskoConfig ]; }
|
|
||||||
else
|
|
||||||
{ };
|
|
||||||
in
|
|
||||||
hostLib.nixosSystem {
|
|
||||||
system = systemForHost;
|
|
||||||
modules =
|
modules =
|
||||||
(sysCfg.modules or [ ]) ++ [
|
(sysCfg.modules or [ ]) ++ [
|
||||||
diskoModule
|
./modules/metanix-core.nix
|
||||||
({ ... }: {
|
|
||||||
_module.args = {
|
# Disko wiring if present
|
||||||
inherit meta network addressing;
|
(if sysCfg ? diskoConfig then
|
||||||
hostName = name;
|
{ imports = [ disko.nixosModules.disko sysCfg.diskoConfig ]; }
|
||||||
};
|
else
|
||||||
})
|
{ })
|
||||||
];
|
];
|
||||||
})
|
})
|
||||||
systemsFromMeta;
|
systemsFromMeta;
|
||||||
|
|
||||||
########################################
|
|
||||||
# deploy-rs integration
|
|
||||||
#
|
|
||||||
# Builds deploy.nodes using meta.systems + addressing.
|
|
||||||
########################################
|
|
||||||
deploy = {
|
deploy = {
|
||||||
nodes =
|
nodes =
|
||||||
lib.mapAttrs
|
lib.mapAttrs
|
||||||
(name: sysCfg:
|
(name: sysCfg:
|
||||||
let
|
let
|
||||||
|
network = addressing.mkNetworkFromSpec meta;
|
||||||
hasNetworkHost = builtins.hasAttr name network.hosts;
|
hasNetworkHost = builtins.hasAttr name network.hosts;
|
||||||
hostInfo = if hasNetworkHost then network.hosts.${name} else null;
|
hostInfo = if hasNetworkHost then network.hosts.${name} else null;
|
||||||
|
|
||||||
defaultHostname =
|
defaultHostname =
|
||||||
if hasNetworkHost then hostInfo.fqdn else "${name}.${meta.domain}";
|
if hasNetworkHost then hostInfo.fqdn else "${name}.${meta.domain}";
|
||||||
in
|
in
|
||||||
|
|
@ -121,15 +80,9 @@
|
||||||
systemsFromMeta;
|
systemsFromMeta;
|
||||||
};
|
};
|
||||||
|
|
||||||
########################################
|
|
||||||
# deploy-rs sanity checks
|
|
||||||
########################################
|
|
||||||
checks.${system}.deploy =
|
checks.${system}.deploy =
|
||||||
deploy-rs.lib.${system}.deployChecks self.deploy;
|
deploy-rs.lib.${system}.deployChecks self.deploy;
|
||||||
|
|
||||||
########################################
|
|
||||||
# nixos-anywhere convenience app
|
|
||||||
########################################
|
|
||||||
apps.${system}.nixos-anywhere = {
|
apps.${system}.nixos-anywhere = {
|
||||||
type = "app";
|
type = "app";
|
||||||
program =
|
program =
|
||||||
|
|
|
||||||
71
modules/metanix-core.nix
Normal file
71
modules/metanix-core.nix
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
{ lib, meta, addressing, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
inherit (lib) mkOption types;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.metanix = {
|
||||||
|
# Raw world spec, straight from meta.nix
|
||||||
|
meta = mkOption {
|
||||||
|
type = types.attrs;
|
||||||
|
readOnly = true;
|
||||||
|
default = { };
|
||||||
|
description = "Raw Metanix world spec loaded from meta.nix.";
|
||||||
|
};
|
||||||
|
|
||||||
|
domain = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
readOnly = true;
|
||||||
|
description = "Base DNS domain for this Metanix world.";
|
||||||
|
};
|
||||||
|
|
||||||
|
locations = mkOption {
|
||||||
|
type = types.attrs;
|
||||||
|
readOnly = true;
|
||||||
|
description = "Location tree from meta.nix.";
|
||||||
|
};
|
||||||
|
|
||||||
|
systems = mkOption {
|
||||||
|
type = types.attrs;
|
||||||
|
readOnly = true;
|
||||||
|
description = "System definitions from meta.nix.";
|
||||||
|
};
|
||||||
|
|
||||||
|
# Computed addressing
|
||||||
|
network = mkOption {
|
||||||
|
type = types.attrs;
|
||||||
|
readOnly = true;
|
||||||
|
description = "Computed addressing (hosts, subnets, etc.) from meta.nix.";
|
||||||
|
};
|
||||||
|
|
||||||
|
hosts = mkOption {
|
||||||
|
type = types.attrs;
|
||||||
|
readOnly = true;
|
||||||
|
description = "Shortcut for metanix.network.hosts.";
|
||||||
|
};
|
||||||
|
|
||||||
|
subnets = mkOption {
|
||||||
|
type = types.attrs;
|
||||||
|
readOnly = true;
|
||||||
|
description = "Shortcut for metanix.network.subnets.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config.metanix =
|
||||||
|
let
|
||||||
|
world = meta;
|
||||||
|
network = addressing.mkNetworkFromSpec world;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
meta = world;
|
||||||
|
|
||||||
|
domain = world.domain;
|
||||||
|
locations = world.locations or { };
|
||||||
|
systems = world.systems or { };
|
||||||
|
policy = world.policy or { };
|
||||||
|
|
||||||
|
inherit network;
|
||||||
|
hosts = network.hosts;
|
||||||
|
subnets = network.subnets;
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue