How to fix a NAR hash mismatch?

I am getting a NAR hash mismatch while updating my flake lock file. What’s the best way to resolve it?

NAR hash mismatch in input 'github:NixOS/nixpkgs/master' (/nix/store/jc2x6bx1anznhigrvnf3qdc0niq7pjdr-source), expected 'sha256-Gc6jJwMuUPUGLhYaXLQ/fKEyqlPzlIKX7OKtTXRJnBQ=', got 'sha256-gTKeLTOkf6k9kQjUSXC5X34zOrrM8u4BEHds1rCMfzQ='

Can you show the lock file entry in flake.lock for nixpkgs?

Here is the full lock file.

{
  "nodes": {
    "darwin": {
      "inputs": {
        "nixpkgs": [
          "nixpkgs-unstable"
        ]
      },
      "locked": {
        "lastModified": 1634994402,
        "narHash": "sha256-xmlCVVOYGpZoxgOqsDOVF0B0ASrnbNGVAEzID9qh2xo=",
        "owner": "LnL7",
        "repo": "nix-darwin",
        "rev": "44da835ac40dab5fd231298b59d83487382d2fab",
        "type": "github"
      },
      "original": {
        "owner": "LnL7",
        "ref": "master",
        "repo": "nix-darwin",
        "type": "github"
      }
    },
    "flake-compat": {
      "flake": false,
      "locked": {
        "lastModified": 1627913399,
        "narHash": "sha256-hY8g6H2KFL8ownSiFeMOjwPC8P0ueXpCVEbxgda3pko=",
        "owner": "edolstra",
        "repo": "flake-compat",
        "rev": "12c64ca55c1014cdc1b16ed5a804aa8576601ff2",
        "type": "github"
      },
      "original": {
        "owner": "edolstra",
        "repo": "flake-compat",
        "type": "github"
      }
    },
    "flake-compat_2": {
      "flake": false,
      "locked": {
        "lastModified": 1627913399,
        "narHash": "sha256-hY8g6H2KFL8ownSiFeMOjwPC8P0ueXpCVEbxgda3pko=",
        "owner": "edolstra",
        "repo": "flake-compat",
        "rev": "12c64ca55c1014cdc1b16ed5a804aa8576601ff2",
        "type": "github"
      },
      "original": {
        "owner": "edolstra",
        "repo": "flake-compat",
        "type": "github"
      }
    },
    "flake-utils": {
      "locked": {
        "lastModified": 1638122382,
        "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=",
        "owner": "numtide",
        "repo": "flake-utils",
        "rev": "74f7e4319258e287b0f9cb95426c9853b282730b",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "flake-utils",
        "type": "github"
      }
    },
    "flake-utils_2": {
      "locked": {
        "lastModified": 1629481132,
        "narHash": "sha256-JHgasjPR0/J1J3DRm4KxM4zTyAj4IOJY8vIl75v/kPI=",
        "owner": "numtide",
        "repo": "flake-utils",
        "rev": "997f7efcb746a9c140ce1f13c72263189225f482",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "flake-utils",
        "type": "github"
      }
    },
    "home-manager": {
      "inputs": {
        "nixpkgs": [
          "nixpkgs-unstable"
        ]
      },
      "locked": {
        "lastModified": 1638130066,
        "narHash": "sha256-BdrVURx4wUUagLbXJXnJ816Xl2IicDp12Sw6OKZn4ug=",
        "owner": "nix-community",
        "repo": "home-manager",
        "rev": "3ec7f6fb43ff77cff429aba1a2541d28cc44d37c",
        "type": "github"
      },
      "original": {
        "owner": "nix-community",
        "ref": "master",
        "repo": "home-manager",
        "type": "github"
      }
    },
    "neovim-flake": {
      "inputs": {
        "flake-utils": "flake-utils_2",
        "nixpkgs": [
          "neovim-nightly-overlay",
          "nixpkgs"
        ]
      },
      "locked": {
        "dir": "contrib",
        "lastModified": 1638043901,
        "narHash": "sha256-/ptPh9yDIFYik13bOv6nhPWlWaozOI9SVPe7F/nCzrw=",
        "owner": "neovim",
        "repo": "neovim",
        "rev": "07223fae54b5b8095da16c598fc1395ec3677691",
        "type": "github"
      },
      "original": {
        "dir": "contrib",
        "owner": "neovim",
        "repo": "neovim",
        "type": "github"
      }
    },
    "neovim-nightly-overlay": {
      "inputs": {
        "flake-compat": "flake-compat_2",
        "neovim-flake": "neovim-flake",
        "nixpkgs": "nixpkgs"
      },
      "locked": {
        "lastModified": 1638087178,
        "narHash": "sha256-2Z1bFOdtqJz3259xIXaAqu3n0iD0uaKOG53uSCQEr34=",
        "owner": "nix-community",
        "repo": "neovim-nightly-overlay",
        "rev": "e1a53537b1c7ad2a16da1493cd75b773635a9319",
        "type": "github"
      },
      "original": {
        "owner": "nix-community",
        "repo": "neovim-nightly-overlay",
        "type": "github"
      }
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1637841632,
        "narHash": "sha256-QYqiKHdda0EOnLGQCHE+GluD/Lq2EJj4hVTooPM55Ic=",
        "owner": "nixos",
        "repo": "nixpkgs",
        "rev": "73369f8d0864854d1acfa7f1e6217f7d6b6e3fa1",
        "type": "github"
      },
      "original": {
        "owner": "nixos",
        "ref": "nixos-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "nixpkgs-unstable": {
      "locked": {
        "lastModified": 1638097282,
        "narHash": "sha256-EXCzj9b8X/lqDPJapxZThIOKL5ASbpsJZ+8L1LnY1ig=",
        "owner": "nixos",
        "repo": "nixpkgs",
        "rev": "78cb77b29d37a9663e05b61abb4fa09465da4b70",
        "type": "github"
      },
      "original": {
        "owner": "nixos",
        "ref": "nixpkgs-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "nixpkgs_2": {
      "locked": {
        "lastModified": 1638129630,
        "narHash": "sha256-vaYC1DhrR1nao2rQ8fUf4PNhBLfSeCi2LVrDXTxUu1Y=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "9f25a8ac3a985ba213f775b19750efefdecc9974",
        "type": "github"
      },
      "original": {
        "id": "nixpkgs",
        "ref": "master",
        "type": "indirect"
      }
    },
    "root": {
      "inputs": {
        "darwin": "darwin",
        "flake-compat": "flake-compat",
        "flake-utils": "flake-utils",
        "home-manager": "home-manager",
        "neovim-nightly-overlay": "neovim-nightly-overlay",
        "nixpkgs": "nixpkgs_2",
        "nixpkgs-unstable": "nixpkgs-unstable"
      }
    }
  },
  "root": "root",
  "version": 7
}

I thought recreating the lock file would solve the problem, but I still get the same error. Is there a workaround? I pasted below information about my environment just in case it’s useful.

$ nix-info -m
 - system: `"aarch64-darwin"`
 - host os: `Darwin 21.1.0, macOS 12.0.1`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.5pre20211007_844dd90`
 - channels(root): `"nixpkgs-21.11pre325602.51acb65b302"`
 - nixpkgs: `/Users/shinzui/.config/dotfiles.nix/nixpkgs.nix`

I solved my problem by unpinning nixpkgs. Unfortunately, the error message and developer experience are pretty bad. The only reason I have nixpkgs pinned is to search (nix search) without having it download a huge index for each search. As an aside, unpinning by using remove instead of unpin is very unintuitive.

I have pinned nixpkgs as well and never enountered similar errors.

Are you using *.url = "nixpkgs"; or an implicit input even?

I’m not. I’ll paste the output of nix registry list below.

user   flake:nixpkgs github:NixOS/nixpkgs/3c52ea8c9216a0d5b7a7b4d74a9d2e858b06df5c
system flake:my path:/nix/store/v2kvdmzi74cvlrvgfh1fxnmb3vfsmh8q-source?lastModified=1639456207&narHash=sha256-waja1noXM7DAsBQ94Umr5eytl6CR4uSQR4zCOuGMGXY=
global flake:agda github:agda/agda
global flake:blender-bin github:edolstra/nix-warez?dir=blender
global flake:dreampkgs github:nix-community/dreampkgs
global flake:dwarffs github:edolstra/dwarffs
global flake:fenix github:nix-community/fenix
global flake:flake-utils github:flake-utils/numtide
global flake:gemini github:nix-community/flake-gemini
global flake:home-manager github:nix-community/home-manager
global flake:hydra github:NixOS/hydra
global flake:mach-nix github:DavHau/mach-nix
global flake:nimble github:nix-community/flake-nimble
global flake:nix github:NixOS/nix
global flake:nixops github:NixOS/nixops
global flake:nixos-hardware github:NixOS/nixos-hardware
global flake:nixos-homepage github:NixOS/nixos-homepage/flake
global flake:nur github:nix-community/NUR
global flake:nixpkgs github:NixOS/nixpkgs/nixpkgs-unstable
global flake:templates github:NixOS/templates
global flake:patchelf github:NixOS/patchelf
global flake:nix-serve github:edolstra/nix-serve
global flake:nickel github:tweag/nickel

And how does your system flakes input section look like? And the argument set of the outputs function?

The full repo is on github.

Try using github:nixos/nixpkgs/master instead of nixpkgs/master. flake: URLs are looked up through the registry, this might cause issues.

I verified that it broke without your suggested change, then made the change that fixed it. Thank you, @NobbZ.

Can we please forbid using the registry from a flake, but only allow it from the terminal?

1 Like

For shells I like using the registry, and I set my nixpkgs registry entry to the system’s flake version. That way I can create shells that use software that matches my system versions (which means fewer downloads and is repeatable enough for most small environments) by simply not specifying inputs.

If it is done that way, it would be nice to keep that workflow alive somehow.

1 Like

I understand that use case.

Perhaps add a flag like --allow-implicit-input or --allow-flake-scheme?

I don’t see why we should disallow the use of the registry in a flake. The locked flake entry contains the resolved URL so doesn’t depend on the registry.

As you can see it can cause issues when updating. Maybe even recursively? In the meantime I have the suspicion that nixos/nix#5609 (unstable lock file) might be related, as at least one dependency down the road does use an implicit input (naersk/flake.nix at ebde51ec0eec82dc71eaca03bc24cf8eb44a3d74 · nix-community/naersk · GitHub).

Also if someone hands me over a flake file for debugging, but omit the lockfile, then I won’t be able to help them as soon as they either use implicit inputs ore a flake:* URL.

Its annoying for ad-hoc help. Though I admit this probably rarely causes issues when one has access to the full repository during the helping session.