2024-07-26 22:12:48 +02:00
|
|
|
inputs:
|
|
|
|
let
|
2023-09-20 14:37:21 +02:00
|
|
|
inherit (inputs) self;
|
2024-07-26 22:12:48 +02:00
|
|
|
inherit (inputs.nixpkgs.lib)
|
2023-09-20 14:37:21 +02:00
|
|
|
concatMapAttrs
|
|
|
|
filterAttrs
|
|
|
|
flip
|
2024-06-09 20:59:23 +02:00
|
|
|
genAttrs
|
2023-09-20 14:37:21 +02:00
|
|
|
mapAttrs'
|
|
|
|
nameValuePair
|
|
|
|
nixosSystem
|
|
|
|
;
|
|
|
|
|
|
|
|
# Creates a new nixosSystem with the correct specialArgs, pkgs and name definition
|
2024-07-26 22:12:48 +02:00
|
|
|
mkHost =
|
|
|
|
{ minimal }:
|
|
|
|
name:
|
|
|
|
let
|
|
|
|
pkgs = self.pkgs.x86_64-linux;
|
|
|
|
in
|
2023-09-20 14:37:21 +02:00
|
|
|
nixosSystem {
|
|
|
|
specialArgs = {
|
|
|
|
# Use the correct instance lib that has our overlays
|
|
|
|
inherit (pkgs) lib;
|
|
|
|
inherit (self) nodes stateVersion;
|
2023-09-26 22:25:58 +02:00
|
|
|
inherit inputs minimal;
|
2023-09-20 14:37:21 +02:00
|
|
|
};
|
|
|
|
modules = [
|
|
|
|
{
|
|
|
|
# We cannot force the package set via nixpkgs.pkgs and
|
|
|
|
# inputs.nixpkgs.nixosModules.readOnlyPkgs, since some nixosModules
|
|
|
|
# like nixseparatedebuginfod depend on adding packages via nixpkgs.overlays.
|
|
|
|
# So we just mimic the options and overlays defined by the passed pkgs set.
|
|
|
|
nixpkgs.overlays = pkgs.overlays;
|
|
|
|
nixpkgs.config = pkgs.config;
|
|
|
|
node.name = name;
|
2024-03-05 00:34:50 +01:00
|
|
|
node.secretsDir = ../. + "/hosts/${name}/secrets";
|
2023-09-20 14:37:21 +02:00
|
|
|
}
|
|
|
|
../hosts/${name}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
# Load the list of hosts that this flake defines, which
|
|
|
|
# associates the minimum amount of metadata that is necessary
|
|
|
|
# to instanciate hosts correctly.
|
2024-06-09 20:59:23 +02:00
|
|
|
hosts = builtins.attrNames (filterAttrs (_: type: type == "directory") (builtins.readDir ../hosts));
|
2023-09-20 14:37:21 +02:00
|
|
|
# Process each nixosHosts declaration and generatea nixosSystem definitions
|
2024-07-26 22:12:48 +02:00
|
|
|
nixosConfigurations = genAttrs hosts (mkHost {
|
|
|
|
minimal = false;
|
|
|
|
});
|
|
|
|
minimalConfigurations = genAttrs hosts (mkHost {
|
|
|
|
minimal = true;
|
|
|
|
});
|
2023-09-20 14:37:21 +02:00
|
|
|
|
2024-01-11 22:42:03 +01:00
|
|
|
# True NixOS nodes can define additional guest nodes that are built
|
|
|
|
# together with it. We collect all defined guests from each node here
|
|
|
|
# to allow accessing any node via the unified attribute `nodes`.
|
2024-07-26 22:12:48 +02:00
|
|
|
guestConfigurations = flip concatMapAttrs self.nixosConfigurations (
|
|
|
|
_: node:
|
|
|
|
flip mapAttrs' (node.config.guests or { }) (
|
2024-01-11 22:42:03 +01:00
|
|
|
guestName: guestDef:
|
2024-07-26 22:12:48 +02:00
|
|
|
nameValuePair guestDef.nodeName (
|
|
|
|
if guestDef.backend == "microvm" then
|
|
|
|
node.config.microvm.vms.${guestName}.config
|
|
|
|
else
|
|
|
|
node.config.containers.${guestName}.nixosConfiguration
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
in
|
|
|
|
{
|
2023-09-20 14:37:21 +02:00
|
|
|
inherit
|
|
|
|
hosts
|
|
|
|
nixosConfigurations
|
2023-09-26 22:25:58 +02:00
|
|
|
minimalConfigurations
|
2023-12-18 02:11:24 +01:00
|
|
|
guestConfigurations
|
2023-09-20 14:37:21 +02:00
|
|
|
;
|
|
|
|
}
|