fix(nix): don't report a broken install for a freshly mounted /nix volume (#2601) - #2939
Open
mikeland73 wants to merge 1 commit into
Open
fix(nix): don't report a broken install for a freshly mounted /nix volume (#2601)#2939mikeland73 wants to merge 1 commit into
mikeland73 wants to merge 1 commit into
Conversation
Mounting an empty /nix volume in Docker/Kubernetes commonly leaves a lost+found directory at the mount root (created by ext4 and other filesystems). Devbox's install check treated any non-empty /nix as an existing installation, so it reported a broken Nix installation instead of installing Nix into the fresh volume. Detect an existing installation by ignoring known filesystem cruft (lost+found, .DS_Store) so a freshly mounted /nix volume proceeds to the Nix installer. Fixes #2601 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Upz2KchxkA6erYatxPzVjg
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 #2601.
When running Devbox in a container (e.g. Docker or Kubernetes) with
/nixmounted as a persistent volume, the volume starts out effectively empty. Devbox is supposed to install Nix into it, but instead it fails with:Root cause
EnsureNixInstalleddecided whether/nixalready contained an installation by checking whether the directory was non-empty:A truly empty
/nixalready falls through to the installer, but a freshly mounted volume is usually not truly empty:ext4(and other filesystems) create alost+founddirectory at the root of the mount. So/nixlooks non-empty, Devbox assumes a pre-existing (broken) install, and refuses to install Nix.Fix
Detect an existing installation by ignoring known filesystem cruft (
lost+found,.DS_Store) rather than treating any non-empty/nixas installed. A/nixthat contains only those entries is now treated as a fresh install target, so Devbox proceeds to install Nix as expected. A/nixthat contains real content (e.g. astoredirectory) is still treated as an existing installation, preserving the original "broken install" diagnostics.The generic
dirExistsAndIsNotEmptyhelper was only used here, so it's replaced by a/nix-specificnixDirIsInstalledhelper.How was it tested?
go test ./internal/nix/ -run TestNixDirIsInstalled -v— new table-driven test covering: empty dir, dir with files, dir with a nixstore, dir with hidden files, dir with onlylost+found(the regression case → treated as not installed), dir withlost+found+store(→ installed), and non-existent dir. All pass.go build ./.../go vet ./internal/nix//gofmtclean.(Pre-existing
TestConfigIsUserTrustedfailures in the package are unrelated — they require anixbinary that isn't present in the CI sandbox and are not touched by this change.)cc @ascknx (issue reporter)
Generated by Claude Code