NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.73k stars 1.52k forks source link

Git config `safe.bareRepository=explicit` interferes with nix git operations #11358

Open jfly opened 2 months ago

jfly commented 2 months ago

Describe the bug

nix flake update fails for me with the git config safe.bareRepository=explicit.

@mightyiam and I checked all the nix versions available in nixpkgs#nixVersions, the earliest in which this occurs is nix 2.20.8.

Steps To Reproduce

In a new directory, create a flake.nix that looks like this:

$ cat flake.nix
{
  inputs.nmd.url = "git+https://git.sr.ht/~rycee/nmd";
  outputs = _: {};
}

Then try to update inputs, note how this fails:

$ GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=safe.bareRepository GIT_CONFIG_VALUE_0=explicit nix flake update
fatal: cannot use bare repository '/home/jeremy/.cache/nix/gitv3/187d2nqx8ha2q2vzr2q6by2plja74p4dd2xg4rkswavanxvz5jqc' (safe.bareRepository is 'explicit')
warning: could not update mtime for file '/home/jeremy/.cache/nix/gitv3/187d2nqx8ha2q2vzr2q6by2plja74p4dd2xg4rkswavanxvz5jqc/refs/heads/master': error: changing modification time of '"/home/jeremy/.cache/nix/gitv3/187d2nqx8ha2q2vzr2q6by2plja74p4dd2xg4rkswavanxvz5jqc/refs/heads/master"': No such file or directory
error:
       … while updating the lock file of flake 'path:/tmp/tmp.X6deoqiq3K?lastModified=1724374035&narHash=sha256-PjN1yc5T4d3BAkqdQCyoKPGnF8s/OFMDwbQAxWDL%2BLs%3D'

       … while updating the flake input 'nmd'

       … while fetching the input 'git+https://git.sr.ht/~rycee/nmd'

       error: resolving Git reference 'refs/heads/master': revspec 'refs/heads/master' not found

Expected behavior

I expect the above command to update my lockfile.

nix-env --version output

nix (Nix) 2.24.3

mightyiam commented 2 months ago

Here's how I workaround: https://github.com/mightyiam/infra/commit/decb228230472dc23bd1936f12b084a5d51ae187