fix(nix): don't report a broken install for a freshly mounted /nix volume (#2601) - #2939
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
|
@claude please review this PR for correctness, and flag anything that would block merging. |
|
Claude finished @mikeland73's task in 1m 34s —— View job Review of PR #2939: fix(nix): don't report a broken install for a freshly mounted /nix volume
Note: SummaryThe fix is correct and well-targeted. Confirmed:
No correctness issues, no regressions, no blockers for merging. Nice, minimal fix with good regression test coverage. |
|
Reviewed for correctness and merge-readiness. Correctness — looks good ✅The change swaps the generic
¹ The only intended behavior change is the last row, which is exactly #2601. Blocking merge 🚧
Non-blocking notes
Generated by Claude Code |
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