Skip to content

fleet new-host: a new host's stateVersion is the locked nixpkgs's release - #70

Merged
Savid merged 4 commits into
masterfrom
new-host-state-version
Dec 1, 2026
Merged

Savid merged 4 commits into
masterfrom
new-host-state-version

Conversation

@Savid

@Savid Savid commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

fleet new-host wrote system.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. --from copied the source host's stateVersion, which is the release that host was installed with, not the new one's.

Change

  • lib.mkFleet's .#fleet view 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.
  • A --from source has to set its stateVersion on one uncommented system.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)

  • a new host's default.nix gets the fleet's release;
  • a --from copy of a 25.11 host gets the fleet's release;
  • a --from source in the nested, lib.mkDefault or commented-plus-nested form is refused and leaves no host directory or key;
  • after such a refusal, the same command goes through once the source is fixed;
  • a fleet without nixosRelease gets no host directory and no key.

On the previous new-host.sh each 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.fleet builds (its shellcheck). The check now has openssh and ssh-to-age, which new-host runs. Against a fleet locked to nixos-26.11, nix eval .#fleet.nixosRelease gives 26.11.

Hosts already written keep their line: stateVersion is fixed at install, so a host not yet installed should have it corrected by hand.

…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.
redpandabot[bot]

This comment was marked as outdated.

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.

Savid commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

On the review: the one 🟡 (a --from source whose stateVersion isn't the template's single-line form kept the source's release while the command claimed the fleet's) is fixed — the reply on the comment has the details. A source in another form now fails the command and says to set the copy's stateVersion by hand.

For whoever lands second: this PR adds two cases to the new-host --from section of tests/fleet/test-scripts.sh and answers for the nix eval stub, so it will conflict with #68's additions to the same file; the rebase is short and keeps both sides.

@redpandabot redpandabot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread fleet/new-host.sh Outdated
# 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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 --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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@redpandabot redpandabot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@Savid
Savid merged commit e2eb657 into master Dec 1, 2026
5 checks passed
Savid added a commit that referenced this pull request Dec 1, 2026
Both sides added openssh to fleet-scripts' inputs; it's listed once.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant