From f793f76e26b461c3228c69926d82bf950aaac671 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Thu, 17 Sep 2026 11:05:45 +0200 Subject: Add scripted host bootstrapping with directory-driven discovery nixosConfigurations now auto-discovers hosts// directories instead of a hand-maintained attrset, and scripts/bootstrap-host.sh (exposed as `nix run .#bootstrap-host`) scaffolds a new host from the template. The script always requires an explicit --root for hardware-configuration.nix so a live-installer run can never read the live ISO's own /etc/nixos by accident. Also records the belated task-11.1 checkbox update for the prior change's already-committed state. --- flake.nix | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'flake.nix') diff --git a/flake.nix b/flake.nix index 729ab7e..a863509 100644 --- a/flake.nix +++ b/flake.nix @@ -20,11 +20,26 @@ "x86_64-darwin" "aarch64-darwin" ]; + + # Any directory under hosts/ other than hosts/template that contains a + # `system` file becomes a real nixosConfigurations. output — + # adding a host means dropping in a directory, not editing this file. + # hosts/template is excluded by name so it is never built, even though + # it also carries a system file (kept only so it stays a complete, + # consistent copy-source for the bootstrap script). + hostNames = builtins.attrNames + (nixpkgs.lib.filterAttrs + (name: type: type == "directory" && name != "template") + (builtins.readDir ./hosts)); + + mkHostConfig = hostname: + lib.mkNixos { + inherit hostname; + system = builtins.readFile (./hosts + "/${hostname}/system"); + }; in { - # No real NixOS host exists yet. hosts/template/ is copy-source only and - # is deliberately not wired in here — see hosts/template/ and README.md. - nixosConfigurations = { }; + nixosConfigurations = nixpkgs.lib.genAttrs hostNames mkHostConfig; homeConfigurations = { "tom@linux" = lib.mkHome { @@ -44,5 +59,20 @@ packages = [ pkgs.statix pkgs.deadnix pkgs.nixfmt-rfc-style ]; }; }); + + apps = forAllSystems (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + bootstrap-host = { + type = "app"; + program = "${pkgs.writeShellApplication { + name = "bootstrap-host"; + runtimeInputs = [ pkgs.coreutils pkgs.gnused ]; + text = builtins.readFile ./scripts/bootstrap-host.sh; + }}/bin/bootstrap-host"; + }; + }); }; } -- cgit v1.3