Skip to content

fix(nix): don't report a broken install for a freshly mounted /nix volume (#2601) - #2939

Open
mikeland73 wants to merge 1 commit into
mainfrom
claude/focused-goldberg-601ixv
Open

fix(nix): don't report a broken install for a freshly mounted /nix volume (#2601)#2939
mikeland73 wants to merge 1 commit into
mainfrom
claude/focused-goldberg-601ixv

Conversation

@mikeland73

Copy link
Copy Markdown
Collaborator

Summary

Fixes #2601.

When running Devbox in a container (e.g. Docker or Kubernetes) with /nix mounted as a persistent volume, the volume starts out effectively empty. Devbox is supposed to install Nix into it, but instead it fails with:

Error: We found a /nix directory but nix binary is not in your PATH and we were not able to find it in the usual locations. Your nix installation might be broken. [...]

Root cause

EnsureNixInstalled decided whether /nix already contained an installation by checking whether the directory was non-empty:

if dirExistsAndIsNotEmpty("/nix") { ... return "broken installation" error ... }

A truly empty /nix already falls through to the installer, but a freshly mounted volume is usually not truly empty: ext4 (and other filesystems) create a lost+found directory at the root of the mount. So /nix looks 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 /nix as installed. A /nix that contains only those entries is now treated as a fresh install target, so Devbox proceeds to install Nix as expected. A /nix that contains real content (e.g. a store directory) is still treated as an existing installation, preserving the original "broken install" diagnostics.

The generic dirExistsAndIsNotEmpty helper was only used here, so it's replaced by a /nix-specific nixDirIsInstalled helper.

How was it tested?

  • go test ./internal/nix/ -run TestNixDirIsInstalled -v — new table-driven test covering: empty dir, dir with files, dir with a nix store, dir with hidden files, dir with only lost+found (the regression case → treated as not installed), dir with lost+found + store (→ installed), and non-existent dir. All pass.
  • go build ./... / go vet ./internal/nix/ / gofmt clean.

(Pre-existing TestConfigIsUserTrusted failures in the package are unrelated — they require a nix binary that isn't present in the CI sandbox and are not touched by this change.)

cc @ascknx (issue reporter)


Generated by Claude Code

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
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.

Devbox is failing when an empty /nix folder exists

2 participants