NixOS / nix

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

nix flake "searching up" UX overloads behavior, doesn't allow subversion, and doesn't log the chosen flake.nix #6108

Open colemickens opened 2 years ago

colemickens commented 2 years ago

Describe the bug

The "searching up" behavior is odd.

  1. It should produce a better message, particularly telling me which flake.nix it found and is using.
  2. It overloads the "current directory" syntax and doesn't seem to give anyway to override it.

This is problematic and unfortunately feels like more hidden awkward UX.

My expectations would be that:

  1. Only "unqualified" flake references would qualify for "searching up".
  2. There would be some way to say "use a flake.nix from this dir, if it's missing that's an error".

These feel like they align with the fact that a large mono repo may have multiple flake.nix files in it.


❯ nix --version
nix (Nix) 2.7.0pre20220127_558c4ee

# naively try some "unqualfied" flake refs:

❯ nix eval --raw 'toplevels.xeep'
path '/home/cole/code/nixcfg/misc/toplevels.xeep' does not contain a 'flake.nix', searching up
error: getting status of '/home/cole/code/nixcfg/misc/toplevels.xeep': No such file or directory

# I guess that makes sense:
# it's treating 'toplevels.xeep' as the path to a flake where it's going to build the default output

# but let's try a sort of "unqualified" flake-ref:

❯ nix eval '#toplevels.xeep'
error: '#toplevels.xeep' is not a valid URL

# no dice... :(
# but then... let's try to force a local flake.nix:

❯ nix eval --raw '.#toplevels.xeep'
path '/home/cole/code/nixcfg/misc' does not contain a 'flake.nix', searching up
error: interrupted by the user

❯ nix eval --raw './.#toplevels.xeep'
path '/home/cole/code/nixcfg/misc' does not contain a 'flake.nix', searching up
error: interrupted by the user

❯ nix eval --raw "$(pwd)#toplevels.xeep"
path '/home/cole/code/nixcfg/misc' does not contain a 'flake.nix', searching up
error: interrupted by the user
tomberek commented 2 years ago
  1. It should produce a better message, particularly telling me which flake.nix it found and is using.

A notice of what was found can be added here? I can see the "tools are silent" argument and that "git is silent about this". On the other hand, we're printing a notice already and this may be surprising at first for existing users.

  1. It overloads the "current directory" syntax and doesn't seem to give anyway to override it.

nix eval --raw path:.#toplevels.xeep The searching does not happen if an explicit scheme is provided. The tests for this are here: https://github.com/NixOS/nix/blob/master/tests/flake-searching.sh#L26-L27

The design of drawing the line at only unqualified paths was considered (https://github.com/NixOS/nix/pull/5720#issuecomment-985663361) and would require more refactoring.

colemickens commented 2 years ago

I might even be able to try my hand at patching that, and thanks for the link to the previous discussion.

dzmitry-lahoda commented 2 years ago

I observer this

dz@dz-pc-11:~/vm-demo/.devcontainer$ docker run --user vscode -it test
path '/home/vscode/flake.nix' does not contain a 'flake.nix', searching up
path '/home/vscode/flake.nix' does not contain a 'flake.nix', searching up
path '/home/vscode/flake.nix' does not contain a 'flake.nix', searching up
path '/home/vscode/flake.nix' does not contain a 'flake.nix', searching up
..
error: interrupted by the user
vscode ➜ ~ $ ^C
vscode ➜ ~ $ junod
Stargate CosmosHub App

Usage:
...

So really my flake.nix is here and really it was applied, but for some reason nix develop went into recursive.

vscode ➜ ~ $ ls /home/vscode/
devcontainer.json  flake.lock  flake.nix  nix.conf  nixpkgs.nix

i have to exit many times to get into root shell without junod installed