`narHash` doesn't get updated when `rev` changes in flake inputs

Hello,

I have two different private repositories A and B, A referring to B as an input in its flake:

B.url = "git+ssh://git@github.com/company/B?ref=specificBranch";

At first, this was pointing to main, but then we changed the ref to specificBranch that is two commits ahead from main.

After running nix flake update B in A, rev gets correctly updated (along with some other fields) in flake.lock, but the narHash stays the same. This leads to A not having access to the actual newer commits on B’s specificBranch.

I could objectify this by looking at the inputs.B.outPath derivation using nix repl, which doesn’t contain the updates present on the last commit of the branch - although correctly referenced by rev in flake.lock.

This happens on both Nix 2.26.2 and 2.29.1 (Gentoo and NixOS, respectively). My Gentoo colleague could fix the issue by simply using nix-collect-garbage and then nix flake update, however, this fix doesn’t seem to do the trick on my machine (I also removed all .direnv directories that could refer to this derivation, but to no avail - I guess I missed some).

After having fixed the issue on his machine, my colleague issued an update on A’s flake.lock with an updated narHash. Unfortunately, but somehow predictably, I get this output when trying nix develop with this updated flake.lock: error: mismatch in field 'narHash' of input <...>. If I run nix flake update, it goes back to the old (and wrong) narHash.

I would try and use a fixed-output derivation (e.g. fetchFromGitHub), but since they don’t support private repositories (afaik, at least, I couldn’t find information on it), I’m stuck with trying to make this input work with the flake.

Is this an already known issue? I’m surprised by the fact Nix knows it has to change the revision but doesn’t update the narHash accordingly.

Can you make an issue (GitHub · Where software is built)? Ideally with a reproducer. Thanks!