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

How to use setupHook/shellHook in the new cli (nix shell) #10571

Open
2 tasks done
Et7f3 opened this issue Apr 20, 2024 · 2 comments
Open
2 tasks done

How to use setupHook/shellHook in the new cli (nix shell) #10571

Et7f3 opened this issue Apr 20, 2024 · 2 comments

Comments

@Et7f3
Copy link
Contributor

Et7f3 commented Apr 20, 2024

Problem

$ nix shell nixpkgs#python3Packages.diagrams nixpkgs#python3
$ python3 -c 'import diagrams'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'diagrams'
$ ^D
exit
$ nix-shell -p python3Packages.diagrams python3
[nix-shell:/tmp]$ python3 -c 'import diagrams'
[nix-shell:/tmp]$ 

I can't find this behavior in v2 cli. In nix develop the hooks are called. I tried the mkShell technique (used by nix-shell):
nix-shell -p abcd <=> {...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (abcd) ]; } ""
So I tried nix shell nixpkgs#runCommand --argstr name shell to set the first parameter but I got:

$ nix shell nixpkgs#runCommand --argstr name shell
error: '--arg' and '--argstr' are incompatible with flakes
Try 'nix --help' for more information.

Should I use -E ? then it would become relly fat expression and then writing a proper flake.nix is more concise.

Proposal

None I need help

Checklist

Priorities

Add 👍 to issues you find important.

@Qyriad
Copy link
Member

Qyriad commented Apr 21, 2024

Shells created by nix shell are, confusingly, entirely different from those created by nix-shell and nix develop. The latter two create development shells, aka "the shell for building X package", the former creates "the shell for using X package"

Try using nix develop

See also: #4715

@Et7f3
Copy link
Contributor Author

Et7f3 commented Apr 21, 2024

Thanks I forgot to mention this thread (I have read before opening this issue). IIRC it also mentioned shellHooks that was not called so I opened this issue to track it. I understand the difference between the three:

  • nix develop nixpkgs#X and then genericBuild build package X in the env in the sandbox without sandbox limitations
  • nix-shell ./shell.nix with often mkShell put us in the building shell (but since mkShell is a fake builder it doesn build)
  • nix shell nixpkgs#python3 does add python3 binary in path but it only import binary without hook to expose library.

with nix-shell we could do nix-shell -p 'python3.withPackages(p:[p.diagrams])' and it create a python with a usable library. It is not a syntax usable with flake (that expect only attribute and not a function with args: we can't use --args/--argstr)

Here is the issue:
The documentation explain "the shell for using X package" but should be "the shell for using X binary package" or allow to also use library.

Try using nix develop

nix shell nixpkgs#python3Packages.diagrams only a non-existent path:

$ nix shell nixpkgs#python3Packages.diagrams --command sh -c 'env | grep diagrams'
PATH=/nix/store/ilnk4wsnfppadn74apcfbbcpj4a1f3zi-python3.11-diagrams-0.23.4/bin:...
$ ls /nix/store/ilnk4wsnfppadn74apcfbbcpj4a1f3zi-python3.11-diagrams-0.23.4/bin
ls: cannot access '/nix/store/ilnk4wsnfppadn74apcfbbcpj4a1f3zi-python3.11-diagrams-0.23.4/bin': No such file or directory

only python3: I get callable python
and both:

$ nix shell nixpkgs#python3 nixpkgs#python3Packages.diagrams --command sh -c 'env | grep diagrams; python3 -c "import diagrams"'
PATH=/nix/store/ilnk4wsnfppadn74apcfbbcpj4a1f3zi-python3.11-diagrams-0.23.4/bin:/nix/store/7wz6hm9i8wljz0hgwz1wqmn2zlbgavrq-python3-3.11.8/bin:...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'diagrams'

I have tried hard before opening issue (but since I did many test I didn't put them all because I forgot)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants