gastownhall/beads · error
cannot update default.nix: %v
Error message
cannot update default.nix: %v
What it means
Once the correct hash is parsed, fixNixHash splices the new hash into the original default.nix content and writes it back with os.WriteFile. If that final write fails, this error wraps the os error; note the old (pre-probe) content is restored by the deferred handler only while `restored` is false, so a failed final write leaves the original file restored via defer.
Source
Thrown at cmd/bd/preflight.go:816
m = [][]byte{nil, []byte(h)}
break
}
}
}
if m == nil {
return false, oldHash, "", fmt.Errorf("could not parse correct hash from nix output:\n%s", string(nixOut))
}
newHash := string(m[1])
if newHash == oldHash {
_ = os.WriteFile(nixPath, content, nixPerm)
restored = true
return false, oldHash, newHash, nil
}
updated := append(append([]byte{}, content[:loc[4]]...), append([]byte(newHash), content[loc[5]:]...)...)
if err := os.WriteFile(nixPath, updated, nixPerm); err != nil {
return false, oldHash, newHash, fmt.Errorf("cannot update default.nix: %v", err)
}
restored = true
return true, oldHash, newHash, nil
}
// fixVersionSync updates cmd/bd/version.go to match the version in default.nix.
// default.nix is the source of truth. Returns (fixed, oldVersion, newVersion, err).
func fixVersionSync() (bool, string, string, error) {
vgoPath := "cmd/bd/version.go"
vgoInfo, err := os.Stat(vgoPath)
if err != nil {
return false, "", "", fmt.Errorf("cannot read cmd/bd/version.go: %v", err)
}
vgoPerm := vgoInfo.Mode().Perm()
vgoContent, err := os.ReadFile(vgoPath)
if err != nil {
return false, "", "", fmt.Errorf("cannot read cmd/bd/version.go: %v", err)View on GitHub (pinned to 71377f2769)
Solutions
- Fix write permissions on default.nix (`chmod u+w default.nix`) and re-run `bd fix`
- Free disk space / check quota if the wrapped error indicates ENOSPC
- Alternatively apply the hash manually: paste the new hash reported alongside the error into default.nix's vendorHash line
Example fix
// before cannot update default.nix: open default.nix: permission denied // after chmod u+w default.nix && bd fix # or manually set vendorHash to the reported new hash
Defensive patterns
Strategy: try-catch
Validate before calling
[ -w default.nix ] && df -h . | awk 'NR==2{exit ($5+0 >= 99)?1:0}' || exit 1 Try / catch
out, err := exec.Command("bd", "fix").CombinedOutput()
if err != nil && strings.Contains(string(out), "cannot update default.nix") {
// ensure writability/free space, or manually paste the new hash into vendorHash
} Prevention
- Keep sufficient disk space and avoid quota-limited workspaces for hash fixing
- Stop editors/formatters from locking or churning default.nix during bd fix
- As a fallback, apply the printed new hash manually
When it happens
Trigger: The final os.WriteFile of the updated default.nix fails — permissions revoked between probe and write, read-only filesystem, disk full, or another process (editor/linter) holding conflicting locks or making the path unwritable mid-run.
Common situations: File watched/locked by an IDE or formatter that temporarily flips permissions; disk quota exceeded after the probe write consumed space; running under a security policy (e.g. Landlock/SELinux) that allowed one write but not the second.
Related errors
- cannot write default.nix: %v
- cannot read default.nix: %v
- dolt path is not executable
- failed to create backup directory: %w
- failed to create temp file: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/25e16fbd9736620c.
Report an issue: GitHub.