{"record":{"id":"4b97c9f575d02319","repo":"gastownhall/beads","slug":"could-not-parse-correct-hash-from-nix-output-s","errorCode":null,"errorMessage":"could not parse correct hash from nix output:\n%s","messagePattern":"could not parse correct hash from nix output:\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/preflight.go","lineNumber":804,"sourceCode":"\tnixCmd := exec.CommandContext(ctx, \"nix\", \"build\", \".#default\", \"--no-link\")\n\tnixOut, _ := nixCmd.CombinedOutput()\n\n\t// Nix prints the correct hash in lines like \"got:    sha256-...\"\n\thashRe := regexp.MustCompile(`got:\\s+(sha256-[A-Za-z0-9+/]+=)`)\n\tm := hashRe.FindSubmatch(nixOut)\n\tif m == nil {\n\t\t// Fallback: pick any sha256-... that isn't our sentinel\n\t\taltRe := regexp.MustCompile(`sha256-([A-Za-z0-9+/]+=)`)\n\t\tfor _, am := range altRe.FindAllSubmatch(nixOut, -1) {\n\t\t\th := \"sha256-\" + string(am[1])\n\t\t\tif h != sentinel {\n\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.","sourceCodeStart":786,"sourceCodeEnd":822,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/preflight.go#L786-L822","documentation":"After writing the sentinel hash and running `nix build`, fixNixHash scans the build output for Nix's 'got:' hash line to learn the correct vendorHash. If no hash can be extracted from the nix output (m == nil), it cannot determine the right value and returns this error including the raw nix output for diagnosis.","triggerScenarios":"The regex scan over nix build output finds no 'got:' hash — e.g. `nix build` failed for an unrelated reason (syntax error in default.nix, missing go.mod deps, network failure fetching the store), nix printed an error in an unexpected format, or the output was empty because Output() captured nothing on failure path not using CombinedOutput.","commonSituations":"Nix build breaks on something other than the hash mismatch (so the 'got:' line never appears); Nix version output format changed; sandbox/network errors prevent the build from reaching hash verification; stale flake lock.","solutions":["Read the nix output embedded in the error and fix the actual build failure it reports, then re-run `bd fix`","Manually obtain the hash: set `vendorHash = \"\"` in default.nix (or use lib.fakeSha256), run `nix build .#default`, and copy the 'got:' value from the error into vendorHash","Run `nix build .#default 2>&1 | grep -i got:` yourself to see the full untruncated output","Update locks/fetchers if the failure is network-related (nix with proper sandbox flags or a mirror)"],"exampleFix":"// before\ncould not parse correct hash from nix output:\nerror: ... attribute 'goModules' missing\n// after (fix the nix file error first, then)\nbd fix  # now parses 'got: sha256-...' successfully","handlingStrategy":"try-catch","validationCode":"// sanity: run nix build first and confirm the got: line appears\nnix build .#default 2>&1 | tee /tmp/nix.log && grep -i 'got:' /tmp/nix.log","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"bd\", \"fix\").CombinedOutput()\nif err != nil && strings.Contains(string(out), \"could not parse correct hash from nix output\") {\n    // inspect the embedded nix output in the error and fix the real build failure\n}","preventionTips":["Fix unrelated nix build errors before attempting hash auto-fix","Verify the 'got:' line appears in nix output on your Nix version","Ensure network/sandbox settings allow nix to fetch Go module dependencies"],"tags":["nix","parsing","build-output","vendorhash"],"backgroundTag":"nix-vendor-hash-mismatch","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}