Fix Nix version parsing for prereleases that omit the patch component#2872
Fix Nix version parsing for prereleases that omit the patch component#2872mikeland73 wants to merge 3 commits into
Conversation
Modern Nix prerelease versions such as 2.33pre20251107_479b6b73 omit the
patch component (2.33 rather than 2.33.0). versionRegexp required a patch
component, so these versions failed to parse and EnsureNixInstalled
reported an empty version ("Your version is ."), refusing to run.
Make the patch component optional in versionRegexp and inject a ".0"
patch when coercing such prereleases to a valid semver in Info.AtLeast.
Fixes #2766
There was a problem hiding this comment.
Pull request overview
This PR fixes Devbox’s Nix version detection for prerelease version strings that omit the patch component (e.g. 2.33pre20251107_479b6b73), ensuring Info.Version is populated and EnsureNixInstalled no longer fails version checks incorrectly.
Changes:
- Updated
versionRegexpto allow parsingMAJOR.MINORprerelease forms (optional patch component). - Updated
Info.AtLeastto coerce patch-less versions into valid semver by inserting a.0patch before comparing. - Added tests covering parsing and comparisons for the patch-less prerelease format.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| nix/nix.go | Expands Nix version parsing and semver comparison to handle prereleases missing the patch component. |
| nix/nix_test.go | Adds regression tests for parsing and AtLeast comparisons for patch-less prerelease versions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address review feedback: semver always requires MAJOR.MINOR.PATCH, so reword the comment to make clear the .0 insertion works around golang.org/x/mod/semver's parsing requirement.
The previous run's Elixir example test failed on a transient network error downloading Hex from builds.hex.pm (TLS handshake), unrelated to this change.
|
Heads-up on CI: the only failing check ( Mix/Erlang is rejecting Generated by Claude Code |
Summary
Fixes #2766.
Modern Nix prerelease versions report a version string that omits the patch component, e.g.
nix (Nix) 2.33pre20251107_479b6b73(2.33rather than2.33.0). Devbox'sversionRegexprequired aMAJOR.MINOR.PATCHcore, so these versions failed to parse. As a resultInfo.Versioncame back empty andEnsureNixInstalledaborted with:even though the installed Nix was perfectly recent enough.
Changes
versionRegexp: make the patch component optional so2.33pre20251107_479b6b73parses andInfo.Versionis populated correctly.Info.AtLeast: when coercing a patch-less Nix prerelease to a valid semver for comparison, inject a.0patch (2.33-pre.20251107+479b6b73→2.33.0-pre.20251107+479b6b73), sincegolang.org/x/mod/semverrequires a patch component when a prerelease is present. A newmissingPatchRegexphandles this.nix/nix_test.gofor both parsing andAtLeastcomparisons of the patch-less prerelease format.Testing
Both pass.
cc @Electrenator (issue reporter)
Generated by Claude Code