refactor(guest): assemble guest modules

This commit is contained in:
2026-08-29 17:05:44 -04:00
parent 4f105c81c2
commit 42b1578efa
8 changed files with 68 additions and 80 deletions

View File

@@ -14,27 +14,23 @@ let
root = self + "/modules";
};
guestModules = guests.mkGuests {
root = self + "/guests";
};
#----------------------------------------------------------
guestFiles = util.collectNixFiles (self + "/guests");
collectedRegistry = registryAssembly.collect { hosts = self.nixosConfigurations; };
specialArgs = {
inherit
flake
inputs
self
util
;
registry = collectedRegistry;
};
flake = {
inherit (hosts) mkHosts;
inherit (guests) mkGuest;
inherit util;
};
guests = import ./guest.nix {
inherit
inputs
@@ -51,10 +47,12 @@ let
inputs
lib
specialArgs
guestFiles
guestModules
registryAssembly
;
repositoryModules = modules;
};
in
flake
{
inherit (hosts) mkHosts;
}

View File

@@ -6,12 +6,9 @@
registryAssembly,
util,
}:
{
let
mkGuest =
{
name,
interior ? { },
}:
name:
{ config, lib, ... }:
let
cfg = config.guests.${name};
@@ -131,6 +128,11 @@
Mounts are read-write unless `readOnly` is set.
'';
};
interior = lib.mkOption {
type = lib.types.deferredModule;
default = { };
description = "NixOS module imported into the guest interior.";
};
limits = {
memory = lib.mkOption {
type = lib.types.nullOr lib.types.str;
@@ -246,7 +248,7 @@
repositoryModules
registryAssembly.module
interior
cfg.interior
{
modules.guest.enable = true;
@@ -265,4 +267,16 @@
};
};
};
in
{
mkGuests =
{ root }:
let
files = util.collectNixFiles root;
guestFiles = lib.filterAttrs (file: type: type == "regular" && lib.hasSuffix ".nix" file) (builtins.readDir root);
names = map (file: lib.removeSuffix ".nix" file) (lib.attrNames guestFiles);
in
{
imports = files ++ map mkGuest names;
};
}

View File

@@ -4,8 +4,7 @@
specialArgs,
repositoryModules,
# TODO refactor guests
guestFiles,
guestModules,
# TODO refactor registry
registryAssembly,
}:
@@ -17,24 +16,23 @@ let
}:
lib.nixosSystem {
inherit specialArgs;
modules =
guestFiles
++ [
inputs.chaotic.nixosModules.default
inputs.disko.nixosModules.disko
inputs.sops-nix.nixosModules.sops
inputs.stylix.nixosModules.stylix
modules = [
inputs.chaotic.nixosModules.default
inputs.disko.nixosModules.disko
inputs.sops-nix.nixosModules.sops
inputs.stylix.nixosModules.stylix
repositoryModules
repositoryModules
guestModules
# TODO: refactor
registryAssembly.module (root + "/${name}")
# TODO: refactor
registryAssembly.module (root + "/${name}")
{
networking.hostName = name;
modules.host.enable = true;
}
];
{
networking.hostName = name;
modules.host.enable = true;
}
];
};
in
{