{"record":{"id":"43a8c741ad77927e","repo":"gastownhall/beads","slug":"cannot-read-default-nix-v","errorCode":null,"errorMessage":"cannot read default.nix: %v","messagePattern":"cannot read default\\.nix: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/preflight.go","lineNumber":761,"sourceCode":"\tif _, err := exec.LookPath(\"nix\"); err != nil {\n\t\treturn false, \"\", \"\", fmt.Errorf(\n\t\t\t\"nix not found in PATH\\n  Manual fix:\\n\" +\n\t\t\t\t\"    1. Edit default.nix: set vendorHash = \\\"sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\\\"\\n\" +\n\t\t\t\t\"    2. Run: nix build .#default\\n\" +\n\t\t\t\t\"    3. Copy the 'got:' hash from the error into default.nix\",\n\t\t)\n\t}\n\n\tnixPath := \"default.nix\"\n\tnixInfo, err := os.Stat(nixPath)\n\tif err != nil {\n\t\treturn false, \"\", \"\", fmt.Errorf(\"cannot stat default.nix: %v\", err)\n\t}\n\tnixPerm := nixInfo.Mode().Perm()\n\n\tcontent, err := os.ReadFile(nixPath)\n\tif err != nil {\n\t\treturn false, \"\", \"\", fmt.Errorf(\"cannot read default.nix: %v\", err)\n\t}\n\n\tre := regexp.MustCompile(`(vendorHash\\s*=\\s*)\"([^\"]+)\"`)\n\tloc := re.FindSubmatchIndex(content)\n\tif loc == nil {\n\t\treturn false, \"\", \"\", fmt.Errorf(\"vendorHash not found in default.nix\")\n\t}\n\toldHash := string(content[loc[4]:loc[5]])\n\n\tconst sentinel = \"sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\"\n\tprobed := append(append([]byte{}, content[:loc[4]]...), append([]byte(sentinel), content[loc[5]:]...)...)\n\tif err := os.WriteFile(nixPath, probed, nixPerm); err != nil {\n\t\treturn false, \"\", \"\", fmt.Errorf(\"cannot write default.nix: %v\", err)\n\t}\n\n\trestored := false\n\tdefer func() {\n\t\tif !restored {","sourceCodeStart":743,"sourceCodeEnd":779,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/preflight.go#L743-L779","documentation":"After stat'ing default.nix, fixNixHash reads its contents with os.ReadFile to locate the vendorHash assignment. If the file exists but cannot be read (permission denied, I/O error, or it is a directory named default.nix), this error wraps the os error and aborts the fix.","triggerScenarios":"os.ReadFile(\"default.nix\") fails during `bd fix` — e.g. file mode denies read for the current user, the file is actually a directory, or a disk/ACL problem prevents reading.","commonSituations":"default.nix checked in with restrictive permissions (e.g. 0600 owned by another user) in a shared CI workspace; a directory accidentally named default.nix; read-only or corrupted mount.","solutions":["Check and fix permissions: `chmod u+r default.nix` (and ownership via chown if needed)","If the path is a directory, remove/rename it and restore the real default.nix from git: `git checkout -- default.nix`","Retry after fixing any underlying disk/mount error reported in the wrapped message"],"exampleFix":"// before\n-rw------- default.nix  (owned by other user) -> cannot read default.nix: ...\n// after\nchmod u+r default.nix && bd fix","handlingStrategy":"validation","validationCode":"[ -r default.nix ] && [ -f default.nix ] || { echo \"default.nix must be a readable file\"; exit 1; }","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"bd\", \"fix\").CombinedOutput()\nif err != nil && strings.Contains(string(out), \"cannot read default.nix\") {\n    // fix permissions/ownership, then retry\n}","preventionTips":["Commit default.nix with world-readable permissions (644)","Avoid storing default.nix with restrictive umask in shared workspaces","Watch for tools that replace default.nix with a directory (artifact collisions)"],"tags":["nix","filesystem","permissions","file-read"],"backgroundTag":"file-read-permission-denied","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}