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

nix-shell shebang doesn't load shell.nix depending on working directory #2279

Closed
roberth opened this issue Jul 6, 2018 · 3 comments · Fixed by #11057
Closed

nix-shell shebang doesn't load shell.nix depending on working directory #2279

roberth opened this issue Jul 6, 2018 · 3 comments · Fixed by #11057
Labels
nix-shell nix-shell, nix develop, nix print-dev-env, etc

Comments

@roberth
Copy link
Member

roberth commented Jul 6, 2018

When using a nix-shell shebang in a script, nix-shell doesn't load shell.nix if it is not in the working directory.

This contradicts the nix-shell manpage:

If path is not given, nix-shell defaults to shell.nix if it exists, and default.nix otherwise.

user@xps ~/bug/nix-shell/subdir $ echo i-am-shell-nix >shell.nix
user@xps ~/bug/nix-shell/subdir $ echo i-am-default-nix >default.nix
user@xps ~/bug/nix-shell/subdir $ echo '#!/usr/bin/env nix-shell' >tool
user@xps ~/bug/nix-shell/subdir $ chmod a+x tool
user@xps ~/bug/nix-shell/subdir $ ./tool 
error: undefined variable 'i-am-shell-nix' at /home/user/bug/nix-shell/subdir/shell.nix:1:1
user@xps ~/bug/nix-shell/subdir $ cd ..
user@xps ~/bug/nix-shell $ ./subdir/tool 
error: undefined variable 'i-am-default-nix' at /home/user/bug/nix-shell/subdir/default.nix:1:1
user@xps ~/bug/nix-shell $ rm subdir/default.nix 
user@xps ~/bug/nix-shell $ ./subdir/tool 
error: getting status of '/home/user/bug/nix-shell/subdir/default.nix': No such file or directory

The latter invocations should use shell.nix.

This is related to #496 but doesn't involve .

A workaround:

#!/usr/bin/env nix-shell
#!nix-shell ./shell.nix
@stale
Copy link

stale bot commented Feb 23, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Feb 23, 2021
@roberth
Copy link
Member Author

roberth commented Feb 23, 2021

Still broken on December's nixUnstable.

@stale stale bot removed the stale label Feb 23, 2021
@stale
Copy link

stale bot commented Aug 24, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Aug 24, 2021
@roberth roberth added the nix-shell nix-shell, nix develop, nix print-dev-env, etc label Jul 6, 2024
@stale stale bot removed the stale label Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nix-shell nix-shell, nix develop, nix print-dev-env, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant