Flakes with the submodules flag enabled fail when used in a git worktree #709

Open
opened 2025-03-01 12:39:10 +00:00 by teofilc · 0 comments

Describe the bug

Using a flake style command with the git submodules flag enabled seems to fail when run in a git worktree.
It seems to be trying to read .git/config but this file won't exist in a worktree.

Steps To Reproduce

Here is a full reproducer as a shell script:

mkdir repo
cd repo
git init
nix flake init
git commit -m "Initial commit" flake.lock flake.nix
nix build .?submodules=1 # works fine
git worktree add ../repo-worktree
cd ../repo-worktree
nix build .?submodules=1 # fails

The error we get is:

❯ nix build .?submodules=1
error:
       … while fetching the input 'git+file:///home/teo/scratch/flake-worktree/worktree'

       error: opening file '/home/teo/scratch/flake-worktree/worktree/.git/config': Not a directory

Expected behavior

This should succeed.

nix --version output

❯ nix --version
nix (Lix, like Nix) 2.92.0
System type: x86_64-linux
Additional system types: aarch64-linux, i686-linux
Features: gc, signed-caches
System configuration file: /etc/nix/nix.conf
User configuration files: /home/teo/.config/nix/nix.conf:/etc/xdg/nix/nix.conf:/home/teo/.nix-profile/etc/xdg/nix/nix.conf:/nix/profile/etc/xdg/nix/nix.conf:/home/teo/.local/state/nix/profile/etc/xdg/nix/nix.conf:/etc/profiles/per-user/teo/etc/xdg/nix/nix.conf:/nix/var/nix/profiles/default/etc/xdg/nix/nix.conf:/run/current-system/sw/etc/xdg/nix/nix.conf
Store directory: /nix/store
State directory: /nix/var/nix
Data directory: /nix/store/9vcw1xs4znwaf01mjr7zd3zcxr173qyl-lix-2.92.0/share

Additional context

This seems to work with NixCpp version 2.25.5

Probably related to this code:

writeFile(tmpGitDir + "/config", readFile(repoDir + "/" + gitDir + "/config"));

## Describe the bug Using a flake style command with the git submodules flag enabled seems to fail when run in a git worktree. It seems to be trying to read `.git/config` but this file won't exist in a worktree. ## Steps To Reproduce Here is a full reproducer as a shell script: ```sh mkdir repo cd repo git init nix flake init git commit -m "Initial commit" flake.lock flake.nix nix build .?submodules=1 # works fine git worktree add ../repo-worktree cd ../repo-worktree nix build .?submodules=1 # fails ``` The error we get is: ``` ❯ nix build .?submodules=1 error: … while fetching the input 'git+file:///home/teo/scratch/flake-worktree/worktree' error: opening file '/home/teo/scratch/flake-worktree/worktree/.git/config': Not a directory ``` ## Expected behavior This should succeed. ## `nix --version` output ``` ❯ nix --version nix (Lix, like Nix) 2.92.0 System type: x86_64-linux Additional system types: aarch64-linux, i686-linux Features: gc, signed-caches System configuration file: /etc/nix/nix.conf User configuration files: /home/teo/.config/nix/nix.conf:/etc/xdg/nix/nix.conf:/home/teo/.nix-profile/etc/xdg/nix/nix.conf:/nix/profile/etc/xdg/nix/nix.conf:/home/teo/.local/state/nix/profile/etc/xdg/nix/nix.conf:/etc/profiles/per-user/teo/etc/xdg/nix/nix.conf:/nix/var/nix/profiles/default/etc/xdg/nix/nix.conf:/run/current-system/sw/etc/xdg/nix/nix.conf Store directory: /nix/store State directory: /nix/var/nix Data directory: /nix/store/9vcw1xs4znwaf01mjr7zd3zcxr173qyl-lix-2.92.0/share ``` ## Additional context This seems to work with NixCpp version 2.25.5 Probably related to this code: https://git.lix.systems/lix-project/lix/src/commit/99bc6867e8913ad8f5fa7d63fefd885743eac4c1/lix/libfetchers/git.cc#L740
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#709
No description provided.