fix(generate): drop nix-store --optimise from generated dev Dockerfile#2933
Open
mikeland73 wants to merge 2 commits into
Open
fix(generate): drop nix-store --optimise from generated dev Dockerfile#2933mikeland73 wants to merge 2 commits into
nix-store --optimise from generated dev Dockerfile#2933mikeland73 wants to merge 2 commits into
Conversation
The dev Dockerfile generated by `devbox generate dockerfile` (and
`devbox generate devcontainer`) ran:
RUN devbox run -- echo "Installed Packages." && nix-store --gc && nix-store --optimise
`nix-store --optimise` deduplicates the Nix store by hard-linking identical
files. On Docker's default overlay2 storage driver the rename it performs on
the temporary link fails with:
error: filesystem error: cannot rename: Stale file handle
[/nix/store/.tmp-link-...] [/nix/store/...-aws-c-common-.../nix-support/setup-hook]
which aborts the image build. In a freshly built, single-purpose image there
is little to no duplication to reclaim (Nix itself reports "hard linking saves
-0.00 MiB"), so the optimise pass provides negligible benefit while reliably
breaking `docker build`.
Remove the optimise step and keep `nix-store --gc`, which is what actually
shrinks the image by dropping build-time dependencies. Add a regression test
that renders the dev Dockerfile and asserts it no longer contains
`nix-store --optimise` while still running `nix-store --gc`.
Fixes #2616
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W6BX9jAviSLnWk93YUeD6W
golangci-lint's `usetesting` linter flagged context.Background() in the new test; switch to t.Context(). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W6BX9jAviSLnWk93YUeD6W
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2616.
The dev Dockerfile produced by
devbox generate dockerfile/devbox generate devcontainerruns:nix-store --optimisededuplicates the Nix store by hard-linking identical files. On Docker's default overlay2 storage driver the rename it performs on the temporary link fails with a stale file handle, which aborts the image build:So the Dockerfile that
devbox generateemits does not build out of the box, and the reporter confirmed that removingnix-store --optimisefixes it.Fix
Drop the
nix-store --optimisestep fromdev.Dockerfile.tmpl, keepingnix-store --gc:nix-store --gcis the pass that actually shrinks the image — it drops the build-time closure (.drvfiles, bootstrap tools, source tarballs). That part already completes successfully in the failing build log.nix-store --optimiseprovides negligible benefit here: in a freshly built, single-purpose image there is little to no duplication to reclaim, and Nix itself reportsnote: currently hard linking saves -0.00 MiBright before it errors out.A template comment documents why the optimise pass is intentionally omitted (with a link back to the issue) so it isn't reintroduced later.
How was it tested?
internal/devbox/generate/devcontainer_util_test.go, which renders the dev Dockerfile (for both root and non-root users) and asserts it no longer containsnix-store --optimisewhile still runningnix-store --gc. Verified the test fails when the optimise step is present and passes with the fix.go test ./internal/devbox/generate/...,go build ./internal/...,go vet, andgofmtare clean.RUNline is nowRUN devbox run -- echo "Installed Packages." && nix-store --gc.cc @jDmacD (issue reporter) — thanks for the detailed build log and root-cause.
Community Contribution License
All community contributions in this pull request are licensed to the project
maintainers under the terms of the
Apache 2 License.
By creating this pull request, I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 License as stated in
the
Community Contribution License.
Generated by Claude Code