Skip to content

nix-shell shebang does not interpret -E relative to script dir #4232

@lilyball

Description

@lilyball

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

#!/usr/bin/env nix-shell
#!nix-shell -i bash -E "with import ./deps.nix {}; mkShell { buildInputs = [bash]; }"
echo it works

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 output

nix-env (Nix) 2.3.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions