Repository navigation
fleet new-host: a new host's stateVersion is the locked nixpkgs's release - #70
Conversation
…ease
new-host's template wrote `system.stateVersion = "26.05"` whatever
nixpkgs the fleet locks, so a host installed from a 26.11 lock claimed to
be a 26.05 install, and the line's own comment ("the release the host was
installed with") was wrong from the start. --from copied the source host's
stateVersion, the release that host was installed with, not this one's.
lib.mkFleet's .#fleet view now carries nixosRelease (the locked nixpkgs's
lib.trivial.release). new-host writes it into the template and into a
--from copy, and refuses, before writing anything, when .#fleet doesn't say
it.
Tests: a new host gets the fleet's release; a --from copy of a 25.11 host
gets it too; a fleet without nixosRelease gets no host directory or key.
On the previous new-host.sh all three fail (26.05, 25.11, and a host
written). checks.fleet-scripts gets openssh and ssh-to-age, which
new-host runs.
The sed only rewrites the template's single-line form. A --from source
that nests its stateVersion (system = { stateVersion = ...; }) or writes
lib.mkDefault kept the source's release while the command still reported
the fleet's. The copy is now verified to state the locked release in
whatever form, and the command dies with a set-it-by-hand message
otherwise; a test covers the nested and mkDefault forms and failed on
the previous code.
|
On the review: the one 🟡 (a For whoever lands second: this PR adds two cases to the |
There was a problem hiding this comment.
Summary
The PR makes fleet new-host take the new host's stateVersion from the locked nixpkgs release, for both the template and --from copies, and the earlier silent-keep case now fails loudly. The main logic is sound, but the new --from refusal fires after the host key and directory are already created, leaving a half-created host whose suggested by-hand fix cannot be finished by re-running.
Issues
- 🟡
fleet/new-host.sh:89— --from refusal leaves a host that cannot be finished or re-run — see the thread on that line
Reviewed @ fbf4869a
The word "panda" likely comes from the Nepali "ponya" — and it referred to the red panda first.
| # writes its stateVersion another way keeps the source's release, and | ||
| # must not be reported as this fleet's. | ||
| grep -qF "stateVersion = \"$release\"" "$dir/default.nix" || | ||
| die "$src/default.nix sets its stateVersion in a form the copy can't rewrite; set $dir/default.nix's to \"$release\" by hand" |
There was a problem hiding this comment.
🟡 --from refusal leaves a host that cannot be finished or re-run
The new check at 88-89 runs after the key is made (69), the directory created (78) and default.nix copied (82), so it leaves clusters/<env>/hosts/<node> with the source's stateVersion and install-files/<config> with a key, but writes no host.json or secrets.yaml. The message says to set the copy's line by hand, yet re-running then dies on the existing directory/key, so the user must delete both manually without being told; exit 1's contract (fleet/lib.sh:15) is that the output says what next. Validate the source before creating the key/directory, or clean both up and say so on this path.
There was a problem hiding this comment.
Fixed in 102a17a, the same change as the thread on line 84: the source is read and checked before the host key or the directory is created, so a refusal writes nothing and the same command can simply be run again once the source is fixed. Tests cover a refusal leaving no directory or key and a re-run going through.
There was a problem hiding this comment.
Addressed — the finding was about the old ordering, where the check ran after the key and directory existed. At head the whole --from read/rewrite/verify block is at fleet/new-host.sh:65-81, before the key path is even set (fleet/new-host.sh:83), before mkdir -p "$(dirname "$key")" / ssh-keygen (:85-87) and before mkdir -p "$dir" (:96); the copy is only written at fleet/new-host.sh:98, after every refusal. So a refusal leaves neither clusters/<env>/hosts/<node> nor install-files/<config>/..., and re-running the same command works once the source is fixed.
The tests back both halves: tests/fleet/test-scripts.sh:284, :288 and :293 assert no host directory and no key for the three refusal forms (nested, lib.mkDefault, comment-only match), and tests/fleet/test-scripts.sh:295-298 re-runs the refused command successfully after editing the source. Nothing left to do on this thread from my side.
@ d9c84fdf
…e that sets stateVersion The check after the sed was an unanchored grep for the release anywhere in the copy, so a source with a commented `# system.stateVersion = "26.11";` and a nested real `stateVersion = "25.11"` passed it: the command reported 26.11 and wrote 25.11. And it ran after the host key and the directory were written, so following its "set it by hand" and running the command again hit the existing-directory refusal. The copy is now built and checked before the key or the directory exists: it has to have exactly one uncommented line naming stateVersion, and that line is `system.stateVersion = "<release>";`. Anything else refuses with nothing written. Tests: the commented-plus-nested source refuses and leaves no host directory or key, as do the nested and mkDefault ones; after a refusal, the same command goes through once the source is fixed. On the previous new-host.sh those fail (5 assertions); now test-scripts has 38 cases, 0 failed.
There was a problem hiding this comment.
fleet new-host now takes a new host's system.stateVersion from the fleet's locked nixpkgs (.#fleet.nixosRelease = lib.trivial.release) instead of a hardcoded 26.05 or the --from source's release, refusing before writing anything when the value is missing or the source's stateVersion isn't on the one expected line. Both previously reported --from problems (silently keeping the source's release; leaving a half-written host after refusal) are fixed, and the new tests cover the default host, the --from copy, the nested/mkDefault/commented source forms, a rerun after refusal, and a fleet without the release. I found no new defect.
Reviewed 4 changed file(s) @ 102a17a1 — no blocking issues found.
The word "panda" likely comes from the Nepali "ponya" — and it referred to the red panda first.
The nested and commented cases asserted that a refused --from leaves no host directory or key; the lib.mkDefault case only checked the exit. It fails on fbf4869's new-host.sh and passes now.
Both sides added openssh to fleet-scripts' inputs; it's listed once.
fleet new-hostwrotesystem.stateVersion = "26.05"into every new host whatever nixpkgs the fleet locks, so a host installed from a 26.11 lock claimed to be a 26.05 install.--fromcopied the source host'sstateVersion, which is the release that host was installed with, not the new one's.Change
lib.mkFleet's.#fleetview carriesnixosRelease, the locked nixpkgs'slib.trivial.release.new-hostwrites it into the template and into a--fromcopy, and refuses before writing anything when.#fleetdoesn't say it.--fromsource has to set its stateVersion on one uncommentedsystem.stateVersion = "...";line, the only form the copy can rewrite; any other form (nested,lib.mkDefault, a second line, one in a comment) is refused before the host key or the directory is written, instead of the copy keeping the source's release while the command reports the fleet's.Tests (tests/fleet/test-scripts.sh, new-host section)
--fromcopy of a 25.11 host gets the fleet's release;--fromsource in the nested,lib.mkDefaultor commented-plus-nested form is refused and leaves no host directory or key;nixosReleasegets no host directory and no key.On the previous
new-host.sheach of these fails.nix build .#checks.x86_64-linux.fleet-scripts: test-scripts 38 cases, 0 failed; 3 suites passed;nix build .#packages.x86_64-linux.fleetbuilds (its shellcheck). The check now hasopensshandssh-to-age, which new-host runs. Against a fleet locked to nixos-26.11,nix eval .#fleet.nixosReleasegives26.11.Hosts already written keep their line:
stateVersionis fixed at install, so a host not yet installed should have it corrected by hand.