refactor(flake): pass assembly namespace to modules

This commit is contained in:
2026-08-28 11:09:13 -04:00
parent 3f24669f78
commit 64d22473c3
11 changed files with 35 additions and 36 deletions

View File

@@ -51,9 +51,9 @@ Use the simplest accurate word when a term is not listed.
| forge | Git | A web service that hosts Git repositories, pull requests, issues, and code review comments. Use when the exact provider does not matter. | | forge | Git | A web service that hosts Git repositories, pull requests, issues, and code review comments. Use when the exact provider does not matter. |
| flake | Nix | A Nix project with pinned inputs and declared outputs. Use for the repository-level build unit defined by `flake.nix`. | | flake | Nix | A Nix project with pinned inputs and declared outputs. Use for the repository-level build unit defined by `flake.nix`. |
| assembly file | Nix | A Nix file under `flake/` that constructs flake outputs or arguments passed to NixOS modules. | | assembly file | Nix | A Nix file under `flake/` that constructs flake outputs or arguments passed to NixOS modules. |
| assembly function | Nix | A project function exposed under `dotfiles` because it creates modules, systems, or assembly values. | | assembly function | Nix | A project function exposed under `flake` because it creates modules, systems, or assembly values. |
| library file | Nix | A Nix file that defines reusable project functions instead of a NixOS module or flake output. | | library file | Nix | A Nix file that defines reusable project functions instead of a NixOS module or flake output. |
| library function | Nix | A pure project function exposed under `dotfiles.lib`. | | library function | Nix | A pure project function exposed under `flake.lib`. |
| NixOS module | Nix | A Nix file evaluated by `nixosSystem` for a NixOS configuration. | | NixOS module | Nix | A Nix file evaluated by `nixosSystem` for a NixOS configuration. |
| overlay | Nix | A function that modifies a Nix package set by adding or replacing packages. | | overlay | Nix | A function that modifies a Nix package set by adding or replacing packages. |
| workspace | Window management | A named or numbered group of windows in a graphical session. Some desktop environments call this a virtual desktop. | | workspace | Window management | A named or numbered group of windows in a graphical session. Some desktop environments call this a virtual desktop. |

View File

@@ -10,14 +10,14 @@ Read this document with `docs/dictionary.md`.
Use `lib` only for the base `nixpkgs.lib` value. Use `lib` only for the base `nixpkgs.lib` value.
Do not use `lib` for project functions. Do not use `lib` for project functions.
Use `dotfiles.lib` for library functions passed through module arguments. Use `flake.lib` for library functions passed through module arguments.
Use `dotfiles.mk<Name>` for assembly functions passed through module arguments. Use `flake.mk<Name>` for assembly functions passed through module arguments.
Avoid: Avoid:
```nix ```nix
{ {
lib = dotfilesFunctions; lib = projectFunctions;
} }
``` ```
@@ -26,26 +26,26 @@ Use:
```nix ```nix
{ {
lib = nixpkgs.lib; lib = nixpkgs.lib;
dotfiles.lib = dotfilesFunctions; flake.lib = projectFunctions;
} }
``` ```
### Name project function namespaces by role ### Name project function namespaces by role
Put pure project functions under `dotfiles.lib`. Put pure project functions under `flake.lib`.
Put functions that create modules, systems, or assembly values under `dotfiles`. Put functions that create modules, systems, or assembly values under `flake`.
This keeps data-only functions separate from functions that carry flake context. This keeps data-only functions separate from functions that carry flake context.
Avoid: Avoid:
```nix ```nix
dotfiles.lib.mkGuest { name = "sample"; } flake.lib.mkGuest { name = "sample"; }
``` ```
Use: Use:
```nix ```nix
dotfiles.mkGuest { name = "sample"; } flake.mkGuest { name = "sample"; }
``` ```
## File Placement ## File Placement

View File

@@ -6,7 +6,7 @@
let let
registryAssembly = import ./registry.nix { inherit lib self; }; registryAssembly = import ./registry.nix { inherit lib self; };
modules = import ./modules.nix { inherit lib; }; modules = import ./modules.nix { inherit lib; };
dotfilesLib = import ../lib { inherit lib; }; flakeLib = import ../lib { inherit lib; };
moduleFiles = modules.mkModules (self + "/modules"); moduleFiles = modules.mkModules (self + "/modules");
guestFiles = modules.mkModules (self + "/guests"); guestFiles = modules.mkModules (self + "/guests");
@@ -15,17 +15,18 @@ let
specialArgs = { specialArgs = {
inherit inherit
dotfiles flake
inputs inputs
self self
; ;
registry = collectedRegistry; registry = collectedRegistry;
}; };
dotfiles = { flake = {
inherit (hosts) mkHosts;
inherit (guests) mkGuest; inherit (guests) mkGuest;
lib = dotfilesLib; lib = flakeLib;
}; };
guests = import ./guests.nix { guests = import ./guests.nix {
@@ -36,7 +37,7 @@ let
specialArgs specialArgs
moduleFiles moduleFiles
registryAssembly registryAssembly
dotfilesLib flakeLib
; ;
}; };
@@ -52,6 +53,4 @@ let
; ;
}; };
in in
{ flake
inherit (hosts) mkHosts;
}

View File

@@ -5,7 +5,7 @@
specialArgs, specialArgs,
moduleFiles, moduleFiles,
registryAssembly, registryAssembly,
dotfilesLib, flakeLib,
}: }:
let let
mkGuest = mkGuest =
@@ -103,7 +103,7 @@ let
}; };
mac = lib.mkOption { mac = lib.mkOption {
type = lib.types.str; type = lib.types.str;
default = dotfilesLib.deriveMac name; default = flakeLib.deriveMac name;
defaultText = lib.literalMD "a stable address derived from the guest's namespace path"; defaultText = lib.literalMD "a stable address derived from the guest's namespace path";
example = "bc:24:11:00:00:01"; example = "bc:24:11:00:00:01";
description = '' description = ''
@@ -306,7 +306,7 @@ let
} }
(lib.mkIf networked ( (lib.mkIf networked (
let let
bridgeDevice = "sys-subsystem-net-devices-${lib.replaceStrings [ "-" ] [ "\\x2d" ] (dotfilesLib.bridgeName cfg.vlan)}.device"; bridgeDevice = "sys-subsystem-net-devices-${lib.replaceStrings [ "-" ] [ "\\x2d" ] (flakeLib.bridgeName cfg.vlan)}.device";
in in
{ {
after = [ bridgeDevice ]; after = [ bridgeDevice ];
@@ -319,7 +319,7 @@ let
containers.${machineName} = lib.mkIf (cfg.backend == "container") { containers.${machineName} = lib.mkIf (cfg.backend == "container") {
autoStart = cfg.autoStart; autoStart = cfg.autoStart;
privateNetwork = lib.mkDefault true; privateNetwork = lib.mkDefault true;
hostBridge = lib.mkIf networked (dotfilesLib.bridgeName cfg.vlan); hostBridge = lib.mkIf networked (flakeLib.bridgeName cfg.vlan);
privateUsers = lib.mkDefault "no"; privateUsers = lib.mkDefault "no";
additionalCapabilities = lib.optionals cfg.nesting [ "CAP_NET_ADMIN" ]; additionalCapabilities = lib.optionals cfg.nesting [ "CAP_NET_ADMIN" ];
allowedDevices = lib.optionals cfg.nesting [ allowedDevices = lib.optionals cfg.nesting [

View File

@@ -1,7 +1,7 @@
{ {
config, config,
lib, lib,
dotfiles, flake,
... ...
}: }:
let let
@@ -10,7 +10,7 @@ let
in in
{ {
imports = [ imports = [
(dotfiles.mkGuest { (flake.mkGuest {
name = "actualbudget"; name = "actualbudget";
interior = { interior = {
modules.services.actualbudget = { modules.services.actualbudget = {

View File

@@ -1,7 +1,7 @@
{ {
config, config,
lib, lib,
dotfiles, flake,
... ...
}: }:
let let
@@ -35,7 +35,7 @@ let
in in
{ {
imports = [ imports = [
(dotfiles.mkGuest { (flake.mkGuest {
name = "copyparty"; name = "copyparty";
interior = { interior = {
modules.services.copyparty = { modules.services.copyparty = {

View File

@@ -1,7 +1,7 @@
args@{ dotfiles, ... }: args@{ flake, ... }:
# A sample guest whose interior runs an OCI container on Podman. # A sample guest whose interior runs an OCI container on Podman.
# The image is pulled at runtime, so the guest builds with no build-time fetch. # The image is pulled at runtime, so the guest builds with no build-time fetch.
dotfiles.mkGuest { flake.mkGuest {
name = "nesting-sample"; name = "nesting-sample";
interior = { interior = {
virtualisation.oci-containers.containers.hello = { virtualisation.oci-containers.containers.hello = {

View File

@@ -1,7 +1,7 @@
{ {
config, config,
lib, lib,
dotfiles, flake,
... ...
}: }:
let let
@@ -9,7 +9,7 @@ let
in in
{ {
imports = [ imports = [
(dotfiles.mkGuest { (flake.mkGuest {
name = "reverse-proxy"; name = "reverse-proxy";
interior = { interior = {
modules.services.reverse-proxy.enable = true; modules.services.reverse-proxy.enable = true;

View File

@@ -1,5 +1,5 @@
args@{ dotfiles, ... }: args@{ flake, ... }:
# The tracer-bullet guest: the thinnest complete path from discovery to a # The tracer-bullet guest: the thinnest complete path from discovery to a
# running nested container. Its interior is just the guest-base — the baseline # running nested container. Its interior is just the guest-base — the baseline
# toolset and SSH access — so it proves the concept without carrying a service. # toolset and SSH access — so it proves the concept without carrying a service.
dotfiles.mkGuest { name = "sample"; } args flake.mkGuest { name = "sample"; } args

View File

@@ -1,7 +1,7 @@
{ {
config, config,
lib, lib,
dotfiles, flake,
pkgs, pkgs,
inputs, inputs,
... ...
@@ -64,7 +64,7 @@ in
useGlobalPkgs = true; useGlobalPkgs = true;
useUserPackages = true; useUserPackages = true;
extraSpecialArgs = { extraSpecialArgs = {
inherit dotfiles inputs; inherit flake inputs;
}; };
users.${user.name} = { users.${user.name} = {
home.username = user.name; home.username = user.name;

View File

@@ -1,14 +1,14 @@
{ {
config, config,
lib, lib,
dotfiles, flake,
... ...
}: }:
# The host networking foundation: per-VLAN bridges over a tagged trunk. # The host networking foundation: per-VLAN bridges over a tagged trunk.
let let
cfg = config.modules.network.vlans; cfg = config.modules.network.vlans;
inherit (dotfiles.lib) bridgeName; inherit (flake.lib) bridgeName;
vlanName = id: "${cfg.trunk}.${toString id}"; vlanName = id: "${cfg.trunk}.${toString id}";
in in