Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix <cmd> --update-input ... fails in detached git worktrees #6073

Open
spacefrogg opened this issue Feb 10, 2022 · 2 comments
Open

nix <cmd> --update-input ... fails in detached git worktrees #6073

spacefrogg opened this issue Feb 10, 2022 · 2 comments
Labels

Comments

@spacefrogg
Copy link

Describe the bug

nix <cmd> --update-input ... fails when the following conditions come together:

  1. when called in a git worktree, i.e. when .git is a file (pointing to the real repository) instead of a directory.
  2. when the worktree is clean

It reports the worktree as a shallow clone and that it needs a deep clone to update the inputs.

error: '/path/to/repo' is a shallow Git repository, but a non-shallow repository is needed

       … while fetching the input 'git+file:///path/to/repo'

Steps To Reproduce

  1. Enter a git repo with a flake that has inputs.
  2. Create a worktree with git worktree add ../workree branch
  3. cd ../worktree
  4. nix flake lock --update-input <input> or any other command that accepts the --update-input option

Expected behavior

Updates the input.

nix-env --version output

2.4

Workaround

  1. Run nix <cmd> --update-input <input> path:., which forces nix to interpret the flake URL as a path and avoids the git+file:// codepath.
  2. Modify any tracked file (not necessarily flake.lock) to make the tree dirty, also solves the issue.
@spacefrogg spacefrogg added the bug label Feb 10, 2022
@spacefrogg
Copy link
Author

Update

It is even worse, I am unable to do anything inside a clean ckeckout as described above. Even a simple nix build .#<package> errors.

@stale stale bot added the stale label Aug 12, 2022
@rollf
Copy link

rollf commented Jan 12, 2024

This is still valid and doesn't work as of 2.13.6:

[I] rollf@nixos /tmp/
❯ nix-env --version
nix-env (Nix) 2.13.6

# Shallow copy:
[I] rollf@nixos /tmp
❯ git clone --depth 1 https://github.com/NixOS/nixpkgs.git
...
[I] rollf@nixos /tmp
❯ cd nixpkgs/

# "shallow=1" is provided by default:
[I] rollf@nixos /tmp/nixpkgs (master)
❯ nix build -L --show-trace --keep-failed .#hellow
error: flake 'git+file:///tmp/nixpkgs?shallow=1' does not provide attribute 'packages.x86_64-linux.hellow', 'legacyPackages.x86_64-linux.hellow' or 'hellow'
       Did you mean one of hello, below, halloy or jello?

# Works fine in the repo itself:
[N] rollf@nixos /tmp/nixpkgs (master) [1]
❯ nix build -L --show-trace --keep-failed .#hello
[I] rollf@nixos /tmp/nixpkgs (master)
❯ ./result/bin/hello
Hello, world!

# Doesn't work in a worktree:
[I] rollf@nixos /tmp/nixpkgs (master)
❯ git worktree add ../feature-x
...
[I] rollf@nixos /tmp/nixpkgs (master)
❯ cd ../feature-x/
[N] rollf@nixos /tmp/feature-x (feature-x)
❯ nix build -L --show-trace --keep-failed .#hello
error:
       … while fetching the input 'git+file:///tmp/feature-x'

       error: '/tmp/feature-x' is a shallow Git repository, but shallow repositories are only allowed when `shallow = true;` is specified.

# Works fine with the workaround mentioned in ths PR:
[I] rollf@nixos /tmp/feature-x (feature-x) [1]
❯ nix build -L --show-trace --keep-failed path:.#hello
[I] rollf@nixos /tmp/nixpkgs (master)
❯ ./result/bin/hello
Hello, world!

Relevant issue is #3756 which seems to have fixed in with shallow copies per se, but not in worktrees

@stale stale bot removed the stale label Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants