-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Straightforward way to determine if inside a nix shell
#6677
Comments
This is part of why I've kept my head in the sand on flakes and the new CLI. I put a bit of work into exposing this state in my prompt: From reading some past related discussions, I get the sense that the general concern is about keeping derivations and their builders and such from behaving differently:
I've wondered if it would be acceptable to just push more information about command invocation into the environment immediately before executing a |
I sometimes nest nix shells (either |
Any updates on this? |
I'd be interested in this as well |
Also interested in this! |
Also interested! |
It'd be nice if there were a label for a shell available in a standard environment variable, too. Shells you get from a If we had a standard More complex cases like |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: |
@turbotimon |
Fixes Granola-Team#574 Nix environment has rustfmt nightly and won't work with +nightly. Non-Nix environment needs nightly toolchain installed and requires +nightly. I ended up checking the rustfmt version instead of checking to see if we are inside the Nix environment. However, I'm leaving a related regarding determining if inside a Nix environment: NixOS/nix#6677
Fixes Granola-Team#574 Nix environment has rustfmt nightly and won't work with +nightly. Non-Nix environment needs nightly toolchain installed and requires +nightly. I ended up checking the rustfmt version instead of checking to see if we are inside the Nix environment. However, I'm leaving related reading about how to determine if inside a Nix environment: NixOS/nix#6677
The only times I run zsh (or bash) nested inside each other is for if [ "$SHLVL" = 1 ] ; then
SHELL_NESTING_DEPTH_STRING=""
else
SHELL_NESTING_DEPTH_STRING="[$SHLVL]"
fi
# use PS1 instead of PROMPT for bash
export PROMPT='bla.bla'${SHELL_DEPTH_STRING}'bla.bla '
unset SHELL_DEPTH_STRING |
I am using these functions in zsh and in p10k prompt to show info related to Shell level, # Show Shell Level
function prompt_shell_level() {
if [[ $SHLVL -gt 1 ]]; then
p10k segment -i '⚡' -f yellow -t "$SHLVL"
fi
}
# Show If In Nix Shell
function prompt_in_nix_shell() {
if echo "$PATH" | grep -qc '/nix/store'; then
p10k segment -i '📦' -f yellow -t "nix"
fi
}
# Show Nix Development Shell Name
function prompt_nix_dev_shell_name() {
if [[ -n $IN_NIX_SHELL ]]; then
p10k segment -i '📦' -f yellow -t $name
fi
}
# Show if Direnv Active
function prompt_in_direnv() {
if [[ -n $DIRENV_ACTIVE ]]; then
p10k segment -i '📂' -f yellow -t "direnv"
fi
}
|
Added a check for the number of sub-shells open in a terminal instance. If the number is over one, display the number in the prompt. Inspired by this comment in a Nix repo issue. NixOS/nix#6677 (comment)
Yo Nixers, before I go to sleep, you can add this to your PS1="${PS1//\\u/"$SHLVL:\\u"}" It will make your bash terminal prompt look e.g. like this: [2:satk0@nixos:/path/to/some/dir]$ , where |
When using
nix shell
, there is no indication available to the shell environment that it is a shell. This results in poor UX, where I have to remember whether or not I've invokednix shell
in a given terminal, and if so, which packages I added.The should, at the very least, be an environment variable like the old
IN_NIX_SHELL
fornix-shell
. Ideally, I'd like some variant onIN_NIX_SHELL
as well as something likeNIX_SHELL_PACKAGES
. With these, users can configure their shells to display this information as part of the prompt.The older
nix-shell
command messed with the shell prompt directly. I'm not really a fan of that approach though, since it gives no flexibility to the user in how they want the context information to be displayed, and destroys any additional prompt configuration that the user has.It's also totally possible that what I'm looking for already exists, and I just couldn't find documentation of it. If that's the case, sorry.
The text was updated successfully, but these errors were encountered: