93 lines
2.7 KiB
Nix
93 lines
2.7 KiB
Nix
{
|
|
description = "Metanix static flake: meta.nix → addressing, deploy-rs, disko, nixos-anywhere";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
|
|
deploy-rs.url = "github:serokell/deploy-rs";
|
|
disko.url = "github:nix-community/disko";
|
|
nixos-anywhere.url = "github:numtide/nixos-anywhere";
|
|
};
|
|
|
|
outputs = { self, nixpkgs, deploy-rs, disko, nixos-anywhere, ... }:
|
|
let
|
|
system = "x86_64-linux";
|
|
|
|
pkgs = import nixpkgs { inherit system; };
|
|
lib = pkgs.lib;
|
|
|
|
addressing = import ./lib/addressing {
|
|
inherit lib;
|
|
};
|
|
|
|
meta = import ./meta.nix;
|
|
|
|
systemsFromMeta = meta.systems or { };
|
|
in
|
|
{
|
|
lib.metanix = {
|
|
inherit meta addressing;
|
|
network = addressing.mkNetworkFromSpec meta;
|
|
};
|
|
|
|
nixosConfigurations =
|
|
lib.mapAttrs
|
|
(name: sysCfg:
|
|
let
|
|
systemForHost = sysCfg.system or system;
|
|
in
|
|
lib.nixosSystem {
|
|
system = systemForHost;
|
|
|
|
# Make meta + addressing available to all modules
|
|
specialArgs = {
|
|
inherit meta addressing;
|
|
};
|
|
|
|
modules =
|
|
(sysCfg.modules or [ ]) ++ [
|
|
./modules/metanix/core.nix
|
|
./modules/metanix/networkd.nix
|
|
|
|
# Disko wiring if present
|
|
(if sysCfg ? diskoConfig then
|
|
{ imports = [ disko.nixosModules.disko sysCfg.diskoConfig ]; }
|
|
else
|
|
{ })
|
|
];
|
|
})
|
|
systemsFromMeta;
|
|
|
|
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
|
|
{
|
|
hostname = sysCfg.deployHost or defaultHostname;
|
|
|
|
profiles.system = {
|
|
user = sysCfg.deployUser or "root";
|
|
path =
|
|
deploy-rs.lib.${system}.activate.nixos
|
|
self.nixosConfigurations.${name};
|
|
};
|
|
})
|
|
systemsFromMeta;
|
|
};
|
|
|
|
checks.${system}.deploy =
|
|
deploy-rs.lib.${system}.deployChecks self.deploy;
|
|
|
|
apps.${system}.nixos-anywhere = {
|
|
type = "app";
|
|
program =
|
|
"${nixos-anywhere.packages.${system}.nixos-anywhere}/bin/nixos-anywhere";
|
|
};
|
|
};
|
|
}
|