{"record":{"id":"acf218f23f479768","repo":"jdx/mise","slug":"nix-returned-an-unexpected-number-of-parsed-flake-references","errorCode":null,"errorMessage":"Nix returned an unexpected number of parsed flake references","messagePattern":"Nix returned an unexpected number of parsed flake references","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/packages/nix.rs","lineNumber":214,"sourceCode":"    let sources = requests\n        .iter()\n        .map(|r| r.source)\n        .chain(\n            elements\n                .iter()\n                .filter_map(|(_, e)| e.original_url.as_deref()),\n        )\n        .map(nix_string)\n        .collect::<Vec<_>>()\n        .join(\" \");\n    let expr = format!(\n        \"{{ system = builtins.currentSystem; refs = map builtins.parseFlakeRef [ {sources} ]; }}\"\n    );\n    let parsed: ParsedReferences = serde_json::from_str(\n        &query(&[\"eval\", \"--json\", \"--impure\", \"--offline\", \"--expr\", &expr]).await?,\n    )?;\n    if parsed.refs.len() != requests.len() + elements.len() {\n        bail!(\"Nix returned an unexpected number of parsed flake references\");\n    }\n    Ok(requests\n        .iter()\n        .enumerate()\n        .map(|(i, request)| {\n            elements\n                .iter()\n                .enumerate()\n                .filter(|(j, (_, e))| {\n                    parsed.refs[i] == parsed.refs[requests.len() + j]\n                        && attribute_matches(\n                            request.attribute,\n                            e.attr_path.as_deref().unwrap(),\n                            &parsed.system,\n                        )\n                })\n                .map(|(_, (name, e))| MatchedEntry {\n                    name: (*name).clone(),","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/packages/nix.rs#L196-L232","documentation":"To match requested packages against installed profile entries, mise asks Nix to `parseFlakeRef` all request sources plus all installed elements' original URLs in one `nix eval --expr`, then cross-compares parsed references. This is an internal invariant check: Nix's `map parseFlakeRef [...]` must return exactly one result per input. A count mismatch means the eval output does not line up with the inputs — a malformed/normalized-away reference or an unexpected Nix behavior.","triggerScenarios":"`matching_entries` evaluates `refs = map builtins.parseFlakeRef [ ... ]` and `parsed.refs.len() != requests.len() + elements.len()`. This can happen if a stored profile `original_url` is empty/duplicated in a way Nix collapses, a future Nix changes eval output shape, or serde silently misparses the JSON structure.","commonSituations":"Profiles written by other tools with unusual original_url values; Nix version changes altering parseFlakeRef/eval JSON behavior; a bug after upgrading either mise or Nix.","solutions":["Upgrade mise (and/or Nix) — this is an invariant violation likely fixed upstream; report it if current versions still trigger it.","Inspect your Nix profile entries (`nix profile list --json`) for entries with empty or malformed original_url and remove/reinstall them.","Recreate the Nix profile so all elements carry normal, modern original_url values.","File a bug with the Nix version and the profile JSON if it reproduces on a clean profile."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match matching_entries(pkgs).await {\n    Err(e) if e.to_string().contains(\"unexpected number of parsed flake references\") => {\n        // upgrade mise/nix or file a bug; do not retry blindly\n        report_invariant_bug(e);\n    }\n    other => other?,\n}","preventionTips":["Keep profile entries created by modern nix profile (normal original_url values)","Upgrade mise and Nix together when either changes","Recreate profiles that were built by third-party tooling if this recurs"],"tags":["nix","internal-invariant","parseflakeref","profile"],"backgroundTag":"internal-invariant-violation","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}