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, ... }:
|
||||
let
|
||||
# Default architecture if meta.nix doesn't say otherwise
|
||||
system = "x86_64-linux";
|
||||
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
};
|
||||
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
lib = pkgs.lib;
|
||||
|
||||
# Your mkIp / mkHostsFromSpec / mkSubnetsFromSpec, etc.
|
||||
# This expects: lib/addressing/default.nix
|
||||
addressing = import ./lib/addressing {
|
||||
inherit lib;
|
||||
};
|
||||
|
||||
# User-provided world model.
|
||||
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 { };
|
||||
in
|
||||
{
|
||||
#######################
|
||||
# Library-style exports
|
||||
#######################
|
||||
lib = {
|
||||
metanix = {
|
||||
inherit meta network addressing;
|
||||
};
|
||||
lib.metanix = {
|
||||
inherit meta addressing;
|
||||
network = addressing.mkNetworkFromSpec meta;
|
||||
};
|
||||
|
||||
#############################
|
||||
# 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 =
|
||||
lib.mapAttrs
|
||||
(name: sysCfg:
|
||||
let
|
||||
systemForHost = sysCfg.system or system;
|
||||
in
|
||||
lib.nixosSystem {
|
||||
system = systemForHost;
|
||||
|
||||
pkgsForHost = import nixpkgs {
|
||||
inherit systemForHost;
|
||||
# Make meta + addressing available to all modules
|
||||
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 =
|
||||
(sysCfg.modules or [ ]) ++ [
|
||||
diskoModule
|
||||
({ ... }: {
|
||||
_module.args = {
|
||||
inherit meta network addressing;
|
||||
hostName = name;
|
||||
};
|
||||
})
|
||||
./modules/metanix-core.nix
|
||||
|
||||
# Disko wiring if present
|
||||
(if sysCfg ? diskoConfig then
|
||||
{ imports = [ disko.nixosModules.disko sysCfg.diskoConfig ]; }
|
||||
else
|
||||
{ })
|
||||
];
|
||||
})
|
||||
systemsFromMeta;
|
||||
|
||||
########################################
|
||||
# deploy-rs integration
|
||||
#
|
||||
# Builds deploy.nodes using meta.systems + addressing.
|
||||
########################################
|
||||
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
|
||||
|
|
@ -121,15 +80,9 @@
|
|||
systemsFromMeta;
|
||||
};
|
||||
|
||||
########################################
|
||||
# deploy-rs sanity checks
|
||||
########################################
|
||||
checks.${system}.deploy =
|
||||
deploy-rs.lib.${system}.deployChecks self.deploy;
|
||||
|
||||
########################################
|
||||
# nixos-anywhere convenience app
|
||||
########################################
|
||||
apps.${system}.nixos-anywhere = {
|
||||
type = "app";
|
||||
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