nix icon indicating copy to clipboard operation
nix copied to clipboard

Evaluate nix-shell -i args relative to script

Open matthewbauer opened this issue 3 years ago • 3 comments

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 #4232

matthewbauer avatar Aug 03 '21 20:08 matthewbauer

What about the -I arg (also mentioned in #4232)? E.g. in case:

#!/usr/bin/env nix-shell
#! nix-shell -I nixpkgs=../nix/nixpkgs.nix --pure -p <pkgs...>

Or is there a preferred alternative way to set the search path?

arobertn avatar Nov 29 '21 12:11 arobertn

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

stale[bot] avatar Jun 12 '22 19:06 stale[bot]

Can this get reviewed? This still is an issue in Nix 2.9.1.

lf- avatar Aug 09 '22 22:08 lf-

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-03-03-nix-team-meeting-minutes-37/25998/1

nixos-discourse avatar Mar 03 '23 13:03 nixos-discourse

Fixed conflicts, but this also needs tests.

Ericson2314 avatar Jun 14 '23 17:06 Ericson2314

Please un-draft when ready, this is easier for maintainers to keep overview.

fricklerhandwerk avatar Jun 19 '23 11:06 fricklerhandwerk

@matthewbauer I added tests and notes, let me know if thit is what you intended (also pinging @lf- for visibility )

Fixes: https://github.com/NixOS/nix/issues/5431

I have some hesitation due to the this being a change in behavior for something that has been around for a while. (also, see the new nix-command shebang just released)

tomberek avatar Nov 26 '23 00:11 tomberek

The worry is someone may have started to depend on these being relative to the call-site. Unfortunate, but might need a flag to control the behavior for the legacy CLI, "--relative"?

The new nix-command should not have this design oddity.

tomberek avatar Nov 27 '23 15:11 tomberek

The worry is someone may have started to depend on these being relative to the call-site. Unfortunate, but might need a flag to control the behavior for the legacy CLI, "--relative"?

I think this is improbable and a bit of a bike shed. The workarounds (haskell plus bash polyglot! horrible) that people have had to apply would not be broken by this, as they start nix-shell in the same directory every time. I cannot see any conceivable reason someone would want the old behaviour: somehow you would be evaluating a script with respect to the current directory's default.nix?

That feels like a use case so contrived I doubt anyone has actually tried it, compared to the 99% use case that doesn't work today and I don't believe the new CLI supports at all.

lf- avatar Nov 27 '23 18:11 lf-

It seems that this would break (not difficult to fix): https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/ruby-modules/with-packages/test.rb#L61

I am slightly inclined to merge as-is due the niche nature of the breakage, but the proposal to add "--relative" was mentioned during discussion and I thought it worth bringing up for additional comments.

tomberek avatar Nov 27 '23 20:11 tomberek

Strongly in favor of merging and deferring backwards compatibility hacks to the improbable case of a spacebar heating outcry.

fricklerhandwerk avatar Nov 27 '23 21:11 fricklerhandwerk

I think it's great that we don't dogmatically only work on the new CLI, but we should take the old CLI more seriously when we change it.

roberth avatar Nov 27 '23 22:11 roberth

Agreed on being especially careful about stable commands, but we also quite clearly said that what's obviously a bug (in the sense of an implementation error rather than a flawed design) should be just fixed. This is the case here. The current behavior is unintentionally inconsistent.

fricklerhandwerk avatar Nov 27 '23 22:11 fricklerhandwerk

I'm not opposed to the change, only to the fact that it's currently not opt-in.

Do you want more #9412? Because that's how you get more #9412.

roberth avatar Nov 27 '23 23:11 roberth