-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 does not interpret -E relative to script dir #4232
Comments
On a related note, relative paths given to |
I ran into this a couple of days ago too, here is my workaround, a Haskell/Bash polyglot #! /usr/bin/env bash
{- 2>/dev/null
# vim: set ft=haskell
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
exec nix-shell \
"$DIR/shell.nix" \
--pure \
--run "runghc $(printf "%q " "$0" "$@")"
-}
-- haskell code... |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/relative-paths-when-using-nix-shell-as-an-interpreter/1180/5 |
@expipiplus1 Neat, but in my case I need to support bash, tcl, perl, python, and ruby scripts, and I need a solution that my non-Nix-savvy coworkers can copy&paste, so the polyglot route is kind of problematic. |
I marked this as stale due to inactivity. → More info |
Still a problem last I checked |
When writing a shebang script, you expect your path to be relative to the script, not the cwd. We previously handled this correctly for relative file paths, but not for expressions. This handles both -p & -E args. My understanding is this should be what we want in any cases I can think of - people run scripts from many different working directories. @edolstra is there any reason to handle -p args differently in this case? Fixes NixOS#4232
PR: #5088 |
I marked this as stale due to inactivity. → More info |
Still an issue in Nix 2.8.0. |
This is also an issue for positional arguments. The existing behavior directly contradicts the documentation here:
|
This comment was marked as outdated.
This comment was marked as outdated.
When writing a shebang script, you expect your path to be relative to the script, not the cwd. We previously handled this correctly for relative file paths, but not for expressions. This handles both -p & -E args. My understanding is this should be what we want in any cases I can think of - people run scripts from many different working directories. @edolstra is there any reason to handle -p args differently in this case? Fixes NixOS#4232
When writing a shebang script, you expect your path to be relative to the script, not the cwd. We previously handled this correctly for relative file paths, but not for expressions. This handles both -p & -E args. My understanding is this should be what we want in any cases I can think of - people run scripts from many different working directories. @edolstra is there any reason to handle -p args differently in this case? Fixes NixOS#4232
Describe the bug
When using
nix-shell
in a shebang, it interprets filenames given to it relative to the script dir, but it interprets the-E
flag relative to the cwd. This is rather problematic. I can't think of any reason to want the-E
flag interpreted relative to the current dir and doing so means I'm forced to write a deps.nix file to disk next to my script if I need to import some other file at a known path.More generally, I should be able to replace
#!nix-shell deps.nix -i bash
with#!nix-shell -E 'import ./deps.nix' -i bash
.Steps To Reproduce
Write a script that looks something like
Expected behavior
It shouldn't matter what my cwd is when I execute this, it should behave the same and import the
deps.nix
file that lives right next to the script.Actual behavior
It tries to import
./deps.nix
from whatever my cwd is.nix-env --version
outputnix-env (Nix) 2.3.7
The text was updated successfully, but these errors were encountered: