Skip to content

fix(nix): parse Nix versions without a patch component#2866

Open
mikeland73 wants to merge 1 commit into
mainfrom
claude/focused-goldberg-twnb5h
Open

fix(nix): parse Nix versions without a patch component#2866
mikeland73 wants to merge 1 commit into
mainfrom
claude/focused-goldberg-twnb5h

Conversation

@mikeland73

Copy link
Copy Markdown
Collaborator

Summary

Fixes #2766.

Newer Nix releases report versions that omit the patch component, for example:

nix (Nix) 2.33pre20251107_479b6b73

versionRegexp (used by parseInfo) required a major.minor.patch triple, so these versions failed to parse. Info.Version was then left empty, and the nix-version guard aborted every command with the confusing message:

Error: Devbox requires nix of version >= 2.12.0. Your version is . Please upgrade nix and try again.

This made Devbox unusable on machines running recent nixos-unstable / nightly Nix builds.

Fix

  • versionRegexp: make the patch component optional ((?:\.(?P<patch>…))?) so two-component versions like 2.33pre20251107_479b6b73 parse, while 2.21.2 continues to parse as before.
  • Info.AtLeast: extract the version-coercion logic into a new coerceSemver helper and add a missingPatchRegexp that inserts a zero patch (2.33pre…2.33.0-pre.20251107+479b6b73) before comparison. This keeps the existing prerelease handling (2.23.0pre20240526_7de033d6) working and makes patchless versions comparable with golang.org/x/mod/semver.

How was it tested?

  • Added a 2.33pre20251107_479b6b73 case to TestParseVersionInfoShort (parses to name nix, version 2.33pre20251107_479b6b73).
  • Added AtLeast assertions for the patchless prerelease version in TestVersionInfoAtLeast (>= 2.12.0, >= MinVersion, >= 2.33.0-pre.1, < 2.34.0).
  • go test ./nix/ and go vet ./nix/ pass. All pre-existing version tests (including the Lix 2.90.0-beta.1 and prerelease cases) still pass.

cc @Electrenator (issue reporter)


Generated by Claude Code

Newer Nix releases report versions like "2.33pre20251107_479b6b73"
that omit the patch component. The version regexp required
major.minor.patch, so parsing failed and the version was left empty,
causing devbox to abort with:

  Error: Devbox requires nix of version >= 2.12.0. Your version is .

Make the patch component optional in versionRegexp and coerce
patchless / prerelease Nix versions into valid semvers before
comparing in Info.AtLeast.

Fixes #2766
Copilot AI review requested due to automatic review settings June 13, 2026 14:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes Devbox’s Nix version detection and comparison for newer Nix builds that omit the patch component (e.g. 2.33pre20251107_479b6b73), preventing Info.Version from being left empty and avoiding erroneous “Your version is .” guard failures.

Changes:

  • Updated versionRegexp to allow versions with only major.minor (optional patch) while preserving existing prerelease/build parsing.
  • Refactored version comparison by adding coerceSemver, including logic to insert a .0 patch when missing before comparing with golang.org/x/mod/semver.
  • Added unit tests covering parsing and AtLeast behavior for patchless prerelease versions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
nix/nix.go Makes Nix version parsing accept patchless versions and coerces them into valid semver for comparisons.
nix/nix_test.go Adds regression tests for parsing and AtLeast comparisons with patchless prerelease versions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Collaborator Author

The one failing check (test (not-main, ubuntu-latest, project-tests-only, 2.18.0)) failed on an unrelated, environmental flake, not this change:

--- FAIL: TestExamples/development_elixir_elixir_hello_run_test.test
** (Mix) httpc request failed with: {:failed_connect, [{:to_address, {~c"builds.hex.pm", 443}},
   {:tls_alert, {:unsupported_certificate, ...

The elixir_hello example test couldn't complete a TLS handshake to builds.hex.pm (Hex's CDN) from the CI runner. This change only affects parsing of nix --version output, and this job runs nix 2.18.0 — a standard major.minor.patch version that parses identically with and without this patch — so the change is a no-op here. The relevant nix unit tests and the shellenv_node testscript passed.

A re-run of the failed job should clear it (I don't have permission to trigger one via the API).


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Devbox unable to detect version

3 participants