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

ZSH does not export darwin in NIX_PATH #151

Closed
AlexeyRaga opened this issue Jun 28, 2019 · 4 comments
Closed

ZSH does not export darwin in NIX_PATH #151

AlexeyRaga opened this issue Jun 28, 2019 · 4 comments

Comments

@AlexeyRaga
Copy link

I am trying to configure zsh as my main shell.

So far I have it configured as:

environment.shells = with pkgs; [ bashInteractive zsh ];
programs.zsh.enable = true;
environment.loginShell = "/run/current-system/sw/bin/zsh";

I also had to do chsh to actually switch to zsh.

But nix-darwin doesn't appear to be working in zsh. The reason seems to be that NIX_PATH is not set correctly:

Bash/Fish:

$ echo $NIX_PATH
darwin-config=/Users/araga/.nixpkgs/darwin-configuration.nix:/nix/var/nix/profiles/per-user/root/channels:/Users/araga/.nix-defexpr/channels

ZSH:

% echo $NIX_PATH
nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixpkgs:/nix/var/nix/profiles/per-user/root/channels

Setting nix.nixPath in darwin-configuration.nix doesn't help :(

/etc/zshenv does contain everything that is necessary:

if [ -n "$__ETC_ZSHENV_SOURCED" ]; then return; fi
export __ETC_ZSHENV_SOURCED=1

# Don't execute this file when running in a pure nix-shell.
if test -n "$IN_NIX_SHELL"; then return; fi

if [ -z "$__NIX_DARWIN_SET_ENVIRONMENT_DONE" ]; then
  . /nix/store/hz8ya45g8s21hi9vwvwi2g0krmxl8i5q-set-environment
fi

And when I source /nix/store/hz8ya45g8s21hi9vwvwi2g0krmxl8i5q-set-environment directly and manually it sets NIX_PATH as expected.

This (running in a new shell) suggests that this file has been sourced:

% echo $__ETC_ZSHENV_SOURCED
1
echo $__NIX_DARWIN_SET_ENVIRONMENT_DONE
1

However, NIX_PATH is not set. It looks like it has been reset, or as if __NIX_DARWIN_SET_ENVIRONMENT_DONE has been set before sourcing /etc/zshenv happened for the 1st time...

Am I doing anything wrong?

@AlexeyRaga
Copy link
Author

Hmm, is this expected?

$ echo $NIX_PATH
darwin-config=/Users/araga/.nixpkgs/darwin-configuration.nix:/nix/var/nix/profiles/per-user/root/channels:/Users/araga/.nix-defexpr/channels

$ bash

$ echo $NIX_PATH
nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixpkgs:/nix/var/nix/profiles/per-user/root/channels

But at the same time:

$ fish
Welcome to fish, the friendly interactive shell

araga@INTLRagaMac ~/s/a/agora> echo $NIX_PATH
darwin-config=/Users/araga/.nixpkgs/darwin-configuration.nix:/nix/var/nix/profiles/per-user/root/channels:/Users/araga/.nix-defexpr/channels

Something makes it work for fish always, for bash partially and for zsh never. :-/

@LnL7
Copy link
Owner

LnL7 commented Jun 28, 2019

The NIX_PATH in zsh is the default of the nix installer, if you override variables in ~/.zshrc or other dotfiles instead of extending the values you will get this behavour.

@gtklocker
Copy link

Sorry for necrobumping, but this caught my eye:

I also had to do chsh to actually switch to zsh.

While I had users.users.myuser.shell = pkgs.fish set, I also had to resort to chsh. Is this to be expected?

@Enzime
Copy link
Collaborator

Enzime commented Oct 31, 2024

Going to close this issue as a lot of the logic surrounding NIX_PATH and environment variables has changed over time, for anyone who runs into this issue, please open a new issue

Manually using chsh shouldn't be required after #1120 but you'll also need to add your user to users.knownUsers

@Enzime Enzime closed this as completed Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants