Skip to content

fix(generate): drop nix-store --optimise from generated dev Dockerfile#2933

Open
mikeland73 wants to merge 2 commits into
mainfrom
claude/focused-goldberg-btzkzf
Open

fix(generate): drop nix-store --optimise from generated dev Dockerfile#2933
mikeland73 wants to merge 2 commits into
mainfrom
claude/focused-goldberg-btzkzf

Conversation

@mikeland73

Copy link
Copy Markdown
Collaborator

Summary

Fixes #2616.

The dev Dockerfile produced by devbox generate dockerfile / devbox generate devcontainer runs:

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 a stale file handle, which aborts the image build:

error: filesystem error: cannot rename: Stale file handle
  [/nix/store/.tmp-link-...] [/nix/store/...-aws-c-common-0.9.27/nix-support/setup-hook]
------
 13 | >>> RUN devbox run -- echo "Installed Packages." && nix-store --gc && nix-store --optimise
ERROR: failed to solve: ... did not complete successfully: exit code: 1

So the Dockerfile that devbox generate emits does not build out of the box, and the reporter confirmed that removing nix-store --optimise fixes it.

Fix

Drop the nix-store --optimise step from dev.Dockerfile.tmpl, keeping nix-store --gc:

  • nix-store --gc is the pass that actually shrinks the image — it drops the build-time closure (.drv files, bootstrap tools, source tarballs). That part already completes successfully in the failing build log.
  • nix-store --optimise provides negligible benefit here: in a freshly built, single-purpose image there is little to no duplication to reclaim, and Nix itself reports note: currently hard linking saves -0.00 MiB right 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?

  • Added internal/devbox/generate/devcontainer_util_test.go, which renders the dev Dockerfile (for both root and non-root users) and asserts it no longer contains nix-store --optimise while still running nix-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, and gofmt are clean.
  • Rendered the generated Dockerfile to confirm the output is well-formed and the RUN line is now RUN 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

claude added 2 commits July 25, 2026 14:14
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
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.

generated devbox dockerfile will not build

2 participants