jdx/mise · error

Nix returned an unexpected number of parsed flake references

Error message

Nix returned an unexpected number of parsed flake references

What it means

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.

Solutions

  1. Upgrade mise (and/or Nix) — this is an invariant violation likely fixed upstream; report it if current versions still trigger it.
  2. Inspect your Nix profile entries (`nix profile list --json`) for entries with empty or malformed original_url and remove/reinstall them.
  3. Recreate the Nix profile so all elements carry normal, modern original_url values.
  4. File a bug with the Nix version and the profile JSON if it reproduces on a clean profile.
Defensive patterns

Strategy: try-catch

Try / catch

match matching_entries(pkgs).await {
    Err(e) if e.to_string().contains("unexpected number of parsed flake references") => {
        // upgrade mise/nix or file a bug; do not retry blindly
        report_invariant_bug(e);
    }
    other => other?,
}

Prevention

When it happens

Trigger: `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.

Common situations: 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.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/acf218f23f479768. Report an issue: GitHub.

Appendix: source

Thrown at src/system/packages/nix.rs:214

    let sources = requests
        .iter()
        .map(|r| r.source)
        .chain(
            elements
                .iter()
                .filter_map(|(_, e)| e.original_url.as_deref()),
        )
        .map(nix_string)
        .collect::<Vec<_>>()
        .join(" ");
    let expr = format!(
        "{{ system = builtins.currentSystem; refs = map builtins.parseFlakeRef [ {sources} ]; }}"
    );
    let parsed: ParsedReferences = serde_json::from_str(
        &query(&["eval", "--json", "--impure", "--offline", "--expr", &expr]).await?,
    )?;
    if parsed.refs.len() != requests.len() + elements.len() {
        bail!("Nix returned an unexpected number of parsed flake references");
    }
    Ok(requests
        .iter()
        .enumerate()
        .map(|(i, request)| {
            elements
                .iter()
                .enumerate()
                .filter(|(j, (_, e))| {
                    parsed.refs[i] == parsed.refs[requests.len() + j]
                        && attribute_matches(
                            request.attribute,
                            e.attr_path.as_deref().unwrap(),
                            &parsed.system,
                        )
                })
                .map(|(_, (name, e))| MatchedEntry {
                    name: (*name).clone(),

View on GitHub (pinned to 533346cc37)