Skip to content

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

@spacefrogg

Description

@spacefrogg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions