[Nix#9158] circular flake imports using path urls detected in non-circular graphs #107

Open
opened 2024-03-16 06:44:56 +00:00 by lix-bot · 0 comments
Member

Upstream-Issue: NixOS/nix#9158

Describe the bug

a flake that imports a different branch of the (git) repo it lives in is rejected for circular imports, even if the imported branch has no inputs of its own.

Steps To Reproduce

git init .
git config user.name 'foo'
git config user.email '<>'
echo '{
  inputs = {
  };
  outputs = args: {
  };
}' > flake.nix
git add flake.nix
git commit -m init
git switch -c shared
sed -i -e '4 a foo = 1;' flake.nix
git commit -am shared
git switch -
sed -i -e '2 a shared.url = ".?ref=shared";' flake.nix
sed -i -e '5 a foo = args.shared.foo;' flake.nix
git commit -am use
nix eval .#foo

Expected output:

1

nix-env --version output

nix-env (Nix) 2.18.1

Additional context

not sure whether this applies to other repo types. this doesn't happen with git+file:.?ref=shared as the url, which feels very odd considering the amount of magic nix does in the background when run from git repos. either the path input type should be extended to act more like git+file, or there should be some kind of warning for unknown url parameters in flake inputs. (that warning should be there anyway, to be honest)

notably this fails quite horribly if a flake using this method is used as an input to another flake because nix seems to not be smart enough to rewrite the file:. part and running invalid git commands instead:

❯ nix eval git+ssh://remote/tmp/test#foo -vvv --tarball-ttl 1
fetching Git repository 'ssh://remote/tmp/test'...
using revision 811ebc6af9fb983f75b96da802b1cea7e6b25fae of repo 'ssh://remote/tmp/test'
linking '/nix/store/ryva0slqk1r7cxrclly81rgvg43qbqmd-source/flake.nix' to '/nix/store/.links/1bynlamhnjg8540pbcljk2sdmlndbadybgq2rq6l4f52xaim6zvn'
evaluating file '/nix/store/ryva0slqk1r7cxrclly81rgvg43qbqmd-source/flake.nix'
querying info about '/nix/store/3yn5zglmqiqxwzka00nx9m31m9w3fmbl-source' on 'https://cache.nixos.org'...
downloading 'https://cache.nixos.org/3yn5zglmqiqxwzka00nx9m31m9w3fmbl.narinfo'...
fetching Git repository 'file://file:.'...
fatal: no path specified; see 'git help pull' for valid url syntax
error:
       … in the condition of the assert statement

         at «string»:66:13:

Priorities

Add 👍 to issues you find important.

Upstream-Issue: https://git.lix.systems/NixOS/nix/issues/9158 **Describe the bug** a flake that imports a different branch of the (git) repo it lives in is rejected for circular imports, even if the imported branch has no inputs of its own. **Steps To Reproduce** ```sh git init . git config user.name 'foo' git config user.email '<>' echo '{ inputs = { }; outputs = args: { }; }' > flake.nix git add flake.nix git commit -m init git switch -c shared sed -i -e '4 a foo = 1;' flake.nix git commit -am shared git switch - sed -i -e '2 a shared.url = ".?ref=shared";' flake.nix sed -i -e '5 a foo = args.shared.foo;' flake.nix git commit -am use nix eval .#foo ``` **Expected output:** ``` 1 ``` **`nix-env --version` output** ``` nix-env (Nix) 2.18.1 ``` **Additional context** not sure whether this applies to other repo types. this doesn't happen with `git+file:.?ref=shared` as the url, which feels very odd considering the amount of magic nix does in the background when run from git repos. either the path input type should be extended to act more like `git+file`, or there should be some kind of warning for unknown url parameters in flake inputs. (that warning should be there *anyway*, to be honest) notably this fails quite horribly if a flake using this method is used as an input to another flake because nix seems to not be smart enough to rewrite the `file:.` part and running invalid git commands instead: ``` ❯ nix eval git+ssh://remote/tmp/test#foo -vvv --tarball-ttl 1 fetching Git repository 'ssh://remote/tmp/test'... using revision 811ebc6af9fb983f75b96da802b1cea7e6b25fae of repo 'ssh://remote/tmp/test' linking '/nix/store/ryva0slqk1r7cxrclly81rgvg43qbqmd-source/flake.nix' to '/nix/store/.links/1bynlamhnjg8540pbcljk2sdmlndbadybgq2rq6l4f52xaim6zvn' evaluating file '/nix/store/ryva0slqk1r7cxrclly81rgvg43qbqmd-source/flake.nix' querying info about '/nix/store/3yn5zglmqiqxwzka00nx9m31m9w3fmbl-source' on 'https://cache.nixos.org'... downloading 'https://cache.nixos.org/3yn5zglmqiqxwzka00nx9m31m9w3fmbl.narinfo'... fetching Git repository 'file://file:.'... fatal: no path specified; see 'git help pull' for valid url syntax error: … in the condition of the assert statement at «string»:66:13: ``` **Priorities** Add :+1: to [issues you find important](https://github.com/NixOS/nix/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc).
lix-bot added the
bug
imported
labels 2024-03-16 06:44:56 +00:00
jade added the
Area/flakes
label 2024-03-30 00:04:22 +00:00
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#107
No description provided.