{"record":{"id":"c034b4bdc128f738","repo":"jdx/mise","slug":"nix-cannot-install-package-version-pin-pkg-pin-the-flake","errorCode":null,"errorMessage":"Nix cannot install package version pin '{pkg}'; pin the flake source revision instead","messagePattern":"Nix cannot install package version pin '(.+?)'; pin the flake source revision instead","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/packages/nix.rs","lineNumber":270,"sourceCode":"    let status = tokio::process::Command::new(\"nix\")\n        .args(&args)\n        .stdin(Stdio::null())\n        .stdout(Stdio::inherit())\n        .stderr(Stdio::inherit())\n        .status()\n        .await?;\n    if !status.success() {\n        bail!(\n            \"nix {} failed; see Nix's diagnostic above. Ensure nix-command and flakes are enabled and the profile uses modern `nix profile` format\",\n            shell_words::join(&args)\n        );\n    }\n    Ok(())\n}\n\nfn reject_pins(pkgs: &[PackageRequest]) -> Result<()> {\n    if let Some(pkg) = pkgs.iter().find(|p| p.version.is_some()) {\n        bail!(\n            \"Nix cannot install package version pin '{pkg}'; pin the flake source revision instead\"\n        );\n    }\n    Ok(())\n}\n\n#[async_trait(?Send)]\nimpl SystemPackageManager for NixManager {\n    fn name(&self) -> &str {\n        \"nix\"\n    }\n\n    fn is_available(&self) -> bool {\n        cfg!(unix) && crate::file::which(\"nix\").is_some()\n    }\n\n    fn unavailable_reason(&self) -> String {\n        if cfg!(unix) {","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/packages/nix.rs#L252-L288","documentation":"Nix installs whatever revision the flake reference resolves to; there is no `pkg@version` concept in flake attribute paths, so the Nix manager declares `supports_version_pins() == false` and `reject_pins` pre-checks every request before install/upgrade. If any request carries a version, mise fails fast with guidance to encode the version as a pinned flake source revision instead of silently ignoring it.","triggerScenarios":"A package entry resolves to the Nix manager with a version set — e.g. `packages = [{ name = \"nixpkgs#ripgrep\", version = \"14.1.0\" }]` or a tool-versions-style pin — and `install`/`upgrade` calls `reject_pins`.","commonSituations":"Users copying version-pin syntax from apt/npm/pip workflows into Nix-managed packages; shared mise.toml where the same package is version-pinned for other managers; tool files carrying versions that get mapped onto the nix backend.","solutions":["Drop the version field and let the flake's locked revision determine the version.","Pin a specific commit by embedding the revision in the flake URL: `github:NixOS/nixpkgs/<rev>#ripgrep`.","Manage that package with a different backend that supports version pins if exact versions are required.","Use a flake.lock or your own flake to control versions declaratively."],"exampleFix":"// before\n{\"name\": \"nixpkgs#ripgrep\", \"version\": \"14.1.0\"}\n\n// after\n{\"name\": \"github:NixOS/nixpkgs/9b5328b7f76a91aef6c0f1e5c1d0f2f1b0c1f8ab#ripgrep\"}","handlingStrategy":"validation","validationCode":"// strip versions before handing requests to the nix manager\nlet filtered: Vec<_> = requests.into_iter()\n    .map(|mut r| { debug_assert!(r.version.is_none(), \"nix ignores versions\"); r.version = None; r })\n    .collect();","typeGuard":null,"tryCatchPattern":"match manager.install(&pkgs, &opts).await {\n    Err(e) if e.to_string().contains(\"version pin\") => {\n        eprintln!(\"re-run without version, or pin the flake revision in the name\");\n    }\n    other => other?,\n}","preventionTips":["Never set version fields on nix:-managed packages","Encode versions as flake URL revisions (github:owner/repo/<rev>#pkg)","Use flake.lock / your own flake for version control","If exact versions are required, choose a backend with supports_version_pins() == true"],"tags":["nix","version-pinning","unsupported-operation","flake"],"backgroundTag":"unsupported-operation","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"}