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] unset shellHook? #8257

Open
2 tasks done
toraritte opened this issue Apr 24, 2023 · 2 comments
Open
2 tasks done

[nix-shell] unset shellHook? #8257

toraritte opened this issue Apr 24, 2023 · 2 comments
Assignees
Labels
bug documentation nix-shell nix-shell, nix develop, nix print-dev-env, etc

Comments

@toraritte
Copy link
Contributor

toraritte commented Apr 24, 2023

Problem

Calling nix-shell inside a "nix-shell" (a shell that is the result of a Nix expression setting shellHook) will inherit the parent's shellHook, but this is never mentioned in the nix-shell man page.

For example:

$ nix-shell -E '(import <nixpkgs> {}).mkShell { shellHook = "echo \"\n========\nWELCOME!\n========\""; }'

========
WELCOME!
========

[nix-shell:~]$ nix-shell -p jq

========
WELCOME!
========

@abathur has more examples in this Discourse thread and also mentions commit 0135fd6 for nix develop to avoid this exact issue.

Checklist

Proposal

I was vacillating between opening this documentation issue and filing a bug report, but I don't know if this is considered a bug. Personally, I prefer the nix develop approach for the shellHook only affecting a particular nix-shell invocation and not subsequent ones, but it is certainly not documented (or, at least, not in the nix-shell manual) so adding a note or a warning would definitely help.

$ nix-shell -E '(import <nixpkgs> {}).mkShell { shellHook = "echo \"\n========\nWELCOME!\n=======\"; unset shellHook;"; }'

========
WELCOME!
=======

[nix-shell:~]$ nix-shell -p jq
[nix-shell:~]$ 

Priorities

Add 👍 to issues you find important.

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/how-to-avoid-embedded-nix-shell-to-re-use-parent-nix-shells-shellhook/27541/6

@roberth roberth added the nix-shell nix-shell, nix develop, nix print-dev-env, etc label May 19, 2023
@roberth
Copy link
Member

roberth commented May 19, 2023

The documentation says

If the derivation defines the variable shellHook,

which I think would be more than reasonable to interpret as "if and only if".

I would consider this to be a long standing bug that is still worth fixing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug documentation nix-shell nix-shell, nix develop, nix print-dev-env, etc
Projects
Status: No status
Development

No branches or pull requests

3 participants