{"record":{"id":"25e16fbd9736620c","repo":"gastownhall/beads","slug":"cannot-update-default-nix-v","errorCode":null,"errorMessage":"cannot update default.nix: %v","messagePattern":"cannot update default\\.nix: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/preflight.go","lineNumber":816,"sourceCode":"\t\t\t\tm = [][]byte{nil, []byte(h)}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\tif m == nil {\n\t\treturn false, oldHash, \"\", fmt.Errorf(\"could not parse correct hash from nix output:\\n%s\", string(nixOut))\n\t}\n\tnewHash := string(m[1])\n\n\tif newHash == oldHash {\n\t\t_ = os.WriteFile(nixPath, content, nixPerm)\n\t\trestored = true\n\t\treturn false, oldHash, newHash, nil\n\t}\n\n\tupdated := append(append([]byte{}, content[:loc[4]]...), append([]byte(newHash), content[loc[5]:]...)...)\n\tif err := os.WriteFile(nixPath, updated, nixPerm); err != nil {\n\t\treturn false, oldHash, newHash, fmt.Errorf(\"cannot update default.nix: %v\", err)\n\t}\n\trestored = true\n\treturn true, oldHash, newHash, nil\n}\n\n// fixVersionSync updates cmd/bd/version.go to match the version in default.nix.\n// default.nix is the source of truth. Returns (fixed, oldVersion, newVersion, err).\nfunc fixVersionSync() (bool, string, string, error) {\n\tvgoPath := \"cmd/bd/version.go\"\n\tvgoInfo, err := os.Stat(vgoPath)\n\tif err != nil {\n\t\treturn false, \"\", \"\", fmt.Errorf(\"cannot read cmd/bd/version.go: %v\", err)\n\t}\n\tvgoPerm := vgoInfo.Mode().Perm()\n\n\tvgoContent, err := os.ReadFile(vgoPath)\n\tif err != nil {\n\t\treturn false, \"\", \"\", fmt.Errorf(\"cannot read cmd/bd/version.go: %v\", err)","sourceCodeStart":798,"sourceCodeEnd":834,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/preflight.go#L798-L834","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ncannot update default.nix: open default.nix: permission denied\n// after\nchmod u+w default.nix && bd fix   # or manually set vendorHash to the reported new hash","handlingStrategy":"try-catch","validationCode":"[ -w default.nix ] && df -h . | awk 'NR==2{exit ($5+0 >= 99)?1:0}' || exit 1","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"bd\", \"fix\").CombinedOutput()\nif err != nil && strings.Contains(string(out), \"cannot update default.nix\") {\n    // ensure writability/free space, or manually paste the new hash into vendorHash\n}","preventionTips":["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"],"tags":["nix","filesystem","file-write","permissions"],"backgroundTag":"file-write-permission-denied","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}