nix/configuration.nix: host option to inject provisioning flake/inventory pointers into the operator environment #10
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Add an option to the host framework module (
nixosModules.host,nix/configuration.nix) that injects the provisioning flake/inventory pointers into the operator's shell environment, so an operator on a host whose pointers differ from the baked defaults runsrebuild-vm-from-host <machine>/provision-vm-from-host <machine>with no per-shell exports.Context
rebuild-vm-from-hostandprovision-vm-from-hostread their provisioning pointers from the operator's shell environment. As of the current master (after issue #5 and issue #6), the contract is:rebuild-vm-from-hostreads onlyDEPLOY_FLAKE(default$HOME/work/allod/profiles) and derives the target IP, username, and host-key pin fromdeploy_flake_vm_facts;provision-vm-from-hostreadsDEPLOY_FLAKEplusINVENTORY_CHECKOUT(default$HOME/work/allod/inventory), where the inventory checkout still backsassert_inventory_worktree_ip_matches_pinand is exported asINVENTORYto thenew-vmchild (DHCP-lease eviction andscripts/vm-specs.json).SECRETS_CHECKOUTis gone (issue #6).The provisioning scripts are installed unwrapped —
nix/provisioning-scripts.nixcopies them and runspatchShebangs— so they resolve both their tool dependencies and these pointers from the system environment. The host framework module (nixosModules.host,nix/configuration.nix) already sets one provisioning-relevant session variable this way,environment.sessionVariables.LIBVIRT_DEFAULT_URI, but has no option for the deploy-flake/inventory pointers. Consequently a host whose pointers differ from the baked$HOME/work/allod/{profiles,inventory}defaults must export them by hand in every shell before invoking the scripts.That per-shell export is host configuration data living in operator memory. Principle 8 (one source of truth per fact; consumers derive): the deploy-flake pointer is a fact the host knows once, so it should be declared in host configuration and rendered into the environment the unwrapped scripts read, not retyped per session.
Direction
Add an option to the host framework module (
nix/configuration.nix/nixosModules.host) that, when set, renders the provisioning pointers into the operator's environment. The natural mechanism isenvironment.sessionVariables, alongside the existingLIBVIRT_DEFAULT_URI; a wrapper around the scripts is an alternative the implementation may weigh, but plain environment injection matches the current unwrapped-script design. Grounded on the current script contract, the option surface is:DEPLOY_FLAKErebuild-vm-from-host,provision-vm-from-hostINVENTORY_CHECKOUTprovision-vm-from-hostonly (inventory-IP pin cross-check plus theINVENTORYexport tonew-vm)provision-vm-from-hoststill reads it; remove its option in the same change that drops that readSECRETS_CHECKOUTThe option should be unset by default and render nothing when unset, so the public template host (which relies on the baked
$HOME/work/allod/{profiles,inventory}defaults) is unchanged and the scripts keep their own fallbacks. A malformed configured value should fail evaluation loudly rather than silently substituting a default (principle 11). Because issue #6 already collapsedrebuildto a single pointer, the steady-state surface isDEPLOY_FLAKEalone;INVENTORY_CHECKOUTis included only for the window whileprovision-vm-from-hoststill reads it.Keep behavior in the public framework and data out of it (principle 3, principle 5): the option lives in the framework module, and a deployment supplies its real deploy-flake and inventory locations by composing
nixosModules.hostand setting the option. This issue is the public option only; wiring real host values is a separate, private concern.Boundaries
Public framework module and its template validation only. Out of scope: the script env-var contract itself (owned by issue #5 / issue #6 and any successor), wrapping the provisioning scripts, weakening
assert_inventory_worktree_ip_matches_pinor the host-key pin preflight, and any private host wiring or private deploy-flake data (tracked and performed privately). Host-side live rebuild/provision remains a human gate.Implementation note: the module is currently a config-only function (
{ pkgs, hostname, agenix, ... }: { ... }), so introducing an option means adding anoptionsblock (or a sibling module) while preserving the existingnixosModules.hostimport interface. Theno-hardcoded-archcheck forbids literal system strings innix/modules; an env-var option satisfies this trivially.Validation
A NixOS module-eval check (new, in the flake
checks, gated bynix flake check) that instantiates a minimal template host composingnixosModules.host: with the option set, assert the renderedenvironment.sessionVariables(or the chosen mechanism) carries the configuredDEPLOY_FLAKE(andINVENTORY_CHECKOUT) value; with the option unset, assert no such variable is forced. The existingprovisioning-contractandno-hardcoded-archchecks must stay green.Classification
Single-repo, single-option change on the operator-convenience seam, with no cross-repo interface change. Residual risk R1-R2: a wrong rendered pointer aims host-side rebuild/provision at the wrong deploy data, recoverable by reverting the host config or unsetting the variable for a manual run. Small enough to land without a standalone dev plan; if a consumer bundles it with a private adoption, that planning happens on the private side.
Sequencing
Public-first and unblocked: builds on issue #5 and issue #6, both landed. Prove the option on a template host. Any private adoption composes this option afterward and is out of scope here.