diff options
| author | 2026-09-17 11:05:45 +0200 | |
|---|---|---|
| committer | 2026-09-17 11:05:45 +0200 | |
| commit | f793f76e26b461c3228c69926d82bf950aaac671 (patch) | |
| tree | affac98593ff0de3bb24fcd8aa64f6ef8ed9dc19 /README.md | |
| parent | ae3fa667bda75f11881c9209dc67226f98bcfd95 (diff) | |
| download | desktop-flake-f793f76e26b461c3228c69926d82bf950aaac671.tar.gz desktop-flake-f793f76e26b461c3228c69926d82bf950aaac671.tar.bz2 desktop-flake-f793f76e26b461c3228c69926d82bf950aaac671.zip | |
Add scripted host bootstrapping with directory-driven discovery
nixosConfigurations now auto-discovers hosts/<name>/ 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.
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 36 |
1 files changed, 18 insertions, 18 deletions
| @@ -9,33 +9,33 @@ A single Nix flake for provisioning both NixOS hosts and non-NixOS systems (any | |||
| 9 | - `modules/nixos/common.nix` — shared NixOS-only system settings applied to every NixOS host | 9 | - `modules/nixos/common.nix` — shared NixOS-only system settings applied to every NixOS host |
| 10 | - `modules/home/` — the shared, cross-platform home-manager profile (shell, git, editor, CLI tools). The same modules are consumed whether activated via a NixOS host's home-manager module or standalone `home-manager switch` | 10 | - `modules/home/` — the shared, cross-platform home-manager profile (shell, git, editor, CLI tools). The same modules are consumed whether activated via a NixOS host's home-manager module or standalone `home-manager switch` |
| 11 | - `users/tom.nix` — identity/profile file consumed by both `mkNixos` and `mkHome` | 11 | - `users/tom.nix` — identity/profile file consumed by both `mkNixos` and `mkHome` |
| 12 | - `hosts/template/` — a copy-source-only NixOS host skeleton; **never** wired into `flake.nix` outputs directly. Copy it to `hosts/<real-hostname>/` when provisioning a real machine | 12 | - `hosts/template/` — a copy-source-only NixOS host skeleton; **never** wired into `flake.nix` outputs directly (excluded from discovery by name — see below). Copy it via `scripts/bootstrap-host.sh` (or `nix run .#bootstrap-host`) when provisioning a real machine |
| 13 | - `scripts/bootstrap-host.sh` — scaffolds a new `hosts/<hostname>/` from the template; exposed as `apps.<system>.bootstrap-host` | ||
| 14 | |||
| 15 | Any directory under `hosts/` other than `hosts/template` that contains a `system` file automatically becomes a real `nixosConfigurations.<name>` output — adding a host means dropping in a directory, not editing `flake.nix`. | ||
| 13 | 16 | ||
| 14 | ## Installing NixOS on a new machine | 17 | ## Installing NixOS on a new machine |
| 15 | 18 | ||
| 16 | This flake does not partition disks for you — do that first, with the standard NixOS installer or manually. | 19 | This flake does not partition disks for you — do that first, with the standard NixOS installer or manually. |
| 17 | 20 | ||
| 18 | 1. Partition and format disks; mount the target filesystems under `/mnt` (including `/mnt/boot` for the ESP if UEFI). | 21 | 1. Partition and format disks; mount the target filesystems under `/mnt` (including `/mnt/boot` for the ESP if UEFI). |
| 19 | 2. Generate hardware config: `nixos-generate-config --root /mnt`. Keep the generated `hardware-configuration.nix`; discard its `configuration.nix`. | 22 | 2. Get this repo onto the installer: `nix-shell -p git && git clone <your-remote-url> ~/nix-config` (requires the repo already pushed to a remote — see Follow-ups below). |
| 20 | 3. Get this repo onto the installer: `nix-shell -p git && git clone <your-remote-url> ~/nix-config` (requires the repo already pushed to a remote — see Follow-ups below). | 23 | 3. From `~/nix-config`, scaffold the host: |
| 21 | 4. Copy the template into a real host: `cp -r ~/nix-config/hosts/template ~/nix-config/hosts/<real-hostname>`. | 24 | ``` |
| 22 | 5. Edit `hosts/<real-hostname>/configuration.nix`: set `networking.hostName`, pick the correct boot loader stanza, set `system.stateVersion` to the installer's NixOS release. | 25 | nix run .#bootstrap-host -- <real-hostname> --root /mnt --state-version <ver> |
| 23 | 6. Replace the stub hardware config: `cp /mnt/etc/nixos/hardware-configuration.nix ~/nix-config/hosts/<real-hostname>/hardware-configuration.nix`. | ||
| 24 | 7. Add the host to `flake.nix`: | ||
| 25 | ```nix | ||
| 26 | nixosConfigurations.<real-hostname> = lib.mkNixos { | ||
| 27 | hostname = "<real-hostname>"; | ||
| 28 | system = "x86_64-linux"; | ||
| 29 | }; | ||
| 30 | ``` | 26 | ``` |
| 31 | 8. `cd ~/nix-config && git add -A` (flakes only see git-tracked files). | 27 | `--root /mnt` tells the script to read (or generate, via `nixos-generate-config --root /mnt` if needed) `hardware-configuration.nix` from the freshly mounted install target — it never reads the live installer's own `/etc/nixos`, since `--root` has no default and must always be given explicitly. `--state-version` should match the installer's NixOS release (e.g. `24.05`) and should never be changed after the fact. |
| 32 | 9. If needed: `export NIX_CONFIG="experimental-features = nix-command flakes"`. | 28 | 4. Review `hosts/<real-hostname>/configuration.nix` (boot loader choice, etc.) — the script prints this reminder along with the exact next commands. |
| 33 | 10. `nixos-install --root /mnt --flake ~/nix-config#<real-hostname>`. | 29 | 5. `cd ~/nix-config && git add hosts/<real-hostname>` (flakes only see git-tracked files). |
| 34 | 11. Reboot and remove the install media. | 30 | 6. If needed: `export NIX_CONFIG="experimental-features = nix-command flakes"`. |
| 35 | 12. Afterwards, clone the flake to a stable path (e.g. `/etc/nix-config`) so future updates are just `sudo nixos-rebuild switch --flake /etc/nix-config#<real-hostname>`. | 31 | 7. `nixos-install --root /mnt --flake ~/nix-config#<real-hostname>`. |
| 32 | 8. Reboot and remove the install media. | ||
| 33 | 9. Afterwards, clone the flake to a stable path (e.g. `/etc/nix-config`) so future updates are just `sudo nixos-rebuild switch --flake /etc/nix-config#<real-hostname>`. | ||
| 36 | 34 | ||
| 37 | ## Installing on a non-NixOS system (any Linux, or macOS once supported) | 35 | ## Installing on a non-NixOS system (any Linux, or macOS once supported) |
| 38 | 36 | ||
| 37 | Non-NixOS hosts are unaffected by `bootstrap-host` — there's nothing per-host to scaffold, since `homeConfigurations."tom@linux"` is one generic entry shared by every standalone machine. | ||
| 38 | |||
| 39 | 1. Install Nix. Recommended: the [Determinate Systems installer](https://github.com/DeterminateSystems/nix-installer) (flakes enabled by default). The official installer also works, but you'll need to add `experimental-features = nix-command flakes` to `nix.conf` yourself. | 39 | 1. Install Nix. Recommended: the [Determinate Systems installer](https://github.com/DeterminateSystems/nix-installer) (flakes enabled by default). The official installer also works, but you'll need to add `experimental-features = nix-command flakes` to `nix.conf` yourself. |
| 40 | 2. `git clone <your-remote-url> ~/nix-config`. | 40 | 2. `git clone <your-remote-url> ~/nix-config`. |
| 41 | 3. First run: `nix run home-manager/master -- switch --flake ~/nix-config#tom@linux`. After that, `home-manager switch --flake ~/nix-config#tom@linux` works directly. | 41 | 3. First run: `nix run home-manager/master -- switch --flake ~/nix-config#tom@linux`. After that, `home-manager switch --flake ~/nix-config#tom@linux` works directly. |
| @@ -46,7 +46,7 @@ This only touches your home directory — no sudo required. | |||
| 46 | 46 | ||
| 47 | - `nix fmt` — format all `.nix` files with `nixfmt-rfc-style`. | 47 | - `nix fmt` — format all `.nix` files with `nixfmt-rfc-style`. |
| 48 | - `nix develop` — a shell with `statix` and `deadnix` for linting. | 48 | - `nix develop` — a shell with `statix` and `deadnix` for linting. |
| 49 | - `nix flake check` — validates `homeConfigurations."tom@linux"` and the other outputs defined here (there are no `nixosConfigurations` yet — see Follow-ups). | 49 | - `nix flake check` — validates `homeConfigurations."tom@linux"`, `apps.bootstrap-host`, and the other outputs defined here (there are no real `nixosConfigurations` until a host is scaffolded — see Follow-ups). |
| 50 | 50 | ||
| 51 | ## Follow-ups (not covered by this change) | 51 | ## Follow-ups (not covered by this change) |
| 52 | 52 | ||
