DeterminateSystems / nix-installer

Install Nix and flakes with the fast and reliable Determinate Nix Installer, with over 2 million installs.
GNU Lesser General Public License v2.1
1.99k stars 50 forks source link

Switching to fish shell after running installer with zsh breaks PATH? #1053

Open victorhooi opened 1 month ago

victorhooi commented 1 month ago

I have a macOS system, and am using this Nix template, which uses the Determinate Systems Nix installer =). (Disclaimer: I'm a Nix newbie - but I really wanted a declarative configuration for my machine, so here I am =)...)

However, I use fish as my shell, and am having all manner of issues getting the fish path to work correctly with Nix.

I ran the installer was run with the default macOS zsh shell (since the plan was to install fish using Nix - so that all of the installation of packages and configuration could be done deterministically with Nix - so I basically wanted to run the installer from a basically untouched macOS system).

However, I'm now trying to use home-manager to configure fish, with atuin etc - and I get the following error messages whenever I open a new terminal with fish as the default shell. (Calling fish from within a zsh shell works - but I'm guessing that's because fish is inheriting the PATH environment variables from zsh).

Last login: Tue Jul 16 22:17:15 on ttys004
fish: Unknown command: atuin
- (line 1): 
atuin uuid
^~~~^
in command substitution
    called on line 1 of file -
from sourcing file -
    called on line 43 of file ~/.config/fish/config.fish
from sourcing file ~/.config/fish/config.fish
    called during startup
- (line 1): Unknown command
set -gx ATUIN_SESSION (atuin uuid)
                      ^~~~~~~~~~~^
from sourcing file -
    called on line 43 of file ~/.config/fish/config.fish
from sourcing file ~/.config/fish/config.fish
    called during startup
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish

I did try adding the following to my home-manager configuration - however, this did not fix the errors:

fish = {
  enable = true;
    loginShellInit = ''
      if [[ -f /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.fish ]]; then
        source /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.fish
        source /nix/var/nix/profiles/default/etc/profile.d/nix.fish
      fi
    '';
    };

I saw from these earlier issues that fish support was added to both the NixOS official installer, and the Determinate Systems Nix installer quite some time back:

However, I'm guessing possibly my issue is caused by invoking the Nix installer from the default zsh shell, rather than installing fish first, is that right?

Is there some way of fixing it, so that the fish shell works properly with Nix?

cole-h commented 1 month ago

Does anything change if you run fish via env __HM_SESS_VARS_SOURCED= fish? What about env __ETC_PROFILE_DONE= fish? What about combining them to get env __HM_SESS_VARS_SOURCED= __ETC_PROFILE_DONE= fish?

victorhooi commented 1 month ago

Thanks for getting back to me!

If fish is set as my default shell - when I try to run those commands - it complains about fish not being in my path...lol:

❯ env __ETC_PROFILE_DONE= fish
fish: Unknown command: atuin
- (line 1): 
atuin history start -- "$argv[1]"
^~~~^
in command substitution
    called on line 6 of file -
in function '_atuin_preexec' with arguments 'env\ __ETC_PROFILE_DONE=\ fish'
in event handler: handler for generic event “fish_preexec”
- (line 6): Unknown command
        set -g ATUIN_HISTORY_ID (atuin history start -- "$argv[1]")
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
in function '_atuin_preexec' with arguments 'env\ __ETC_PROFILE_DONE=\ fish'
in event handler: handler for generic event “fish_preexec”
env: fish: No such file or directory

However, I gave it the full path to the fish shell - hopefully this is still useful - and then printed the PATH variable:

❯ env __HM_SESS_VARS_SOURCED= /Users/foobar/.nix-profile/bin/fish
fish: Unknown command: atuin
- (line 1): 
atuin history start -- "$argv[1]"
^~~~^
in command substitution
    called on line 6 of file -
in function '_atuin_preexec' with arguments 'env\ __HM_SESS_VARS_SOURCED=\ /Users/foobar/.nix-profile/bin/fish'
in event handler: handler for generic event “fish_preexec”
- (line 6): Unknown command
        set -g ATUIN_HISTORY_ID (atuin history start -- "$argv[1]")
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
in function '_atuin_preexec' with arguments 'env\ __HM_SESS_VARS_SOURCED=\ /Users/foobar/.nix-profile/bin/fish'
in event handler: handler for generic event “fish_preexec”
PATH before initialisation > /usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/sbin:/opt/puppetlabs/bin:/Applications/Wireshark.app/Contents/MacOS
fish: Unknown command: atuin
- (line 1): 
atuin uuid
^~~~^
in command substitution
    called on line 1 of file -
from sourcing file -
    called on line 43 of file ~/.config/fish/config.fish
from sourcing file ~/.config/fish/config.fish
    called during startup
- (line 1): Unknown command
set -gx ATUIN_SESSION (atuin uuid)
                      ^~~~~~~~~~~^
from sourcing file -
    called on line 43 of file ~/.config/fish/config.fish
from sourcing file ~/.config/fish/config.fish
    called during startup
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish

~ 
❯ env | grep PATH
fish: Unknown command: atuin
- (line 1): 
atuin history start -- "$argv[1]"
^~~~^
in command substitution
    called on line 6 of file -
in function '_atuin_preexec' with arguments 'env\ \|\ grep\ PATH'
in event handler: handler for generic event “fish_preexec”
- (line 6): Unknown command
        set -g ATUIN_HISTORY_ID (atuin history start -- "$argv[1]")
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
in function '_atuin_preexec' with arguments 'env\ \|\ grep\ PATH'
in event handler: handler for generic event “fish_preexec”
PATH=/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/sbin:/opt/puppetlabs/bin:/Applications/Wireshark.app/Contents/MacOS

And here is the second command, with the PATH:

❯ env __ETC_PROFILE_DONE= /Users/foobar/.nix-profile/bin/fish
fish: Unknown command: atuin
- (line 1): 
atuin history start -- "$argv[1]"
^~~~^
in command substitution
    called on line 6 of file -
in function '_atuin_preexec' with arguments 'env\ __ETC_PROFILE_DONE=\ /Users/foobar/.nix-profile/bin/fish'
in event handler: handler for generic event “fish_preexec”
- (line 6): Unknown command
        set -g ATUIN_HISTORY_ID (atuin history start -- "$argv[1]")
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
in function '_atuin_preexec' with arguments 'env\ __ETC_PROFILE_DONE=\ /Users/foobar/.nix-profile/bin/fish'
in event handler: handler for generic event “fish_preexec”
PATH before initialisation > /usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/sbin:/opt/puppetlabs/bin:/Applications/Wireshark.app/Contents/MacOS
fish: Unknown command: atuin
- (line 1): 
atuin uuid
^~~~^
in command substitution
    called on line 1 of file -
from sourcing file -
    called on line 43 of file ~/.config/fish/config.fish
from sourcing file ~/.config/fish/config.fish
    called during startup
- (line 1): Unknown command
set -gx ATUIN_SESSION (atuin uuid)
                      ^~~~~~~~~~~^
from sourcing file -
    called on line 43 of file ~/.config/fish/config.fish
from sourcing file ~/.config/fish/config.fish
    called during startup
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish

~ 
❯ env | grep PATH
fish: Unknown command: atuin
- (line 1): 
atuin history start -- "$argv[1]"
^~~~^
in command substitution
    called on line 6 of file -
in function '_atuin_preexec' with arguments 'env\ \|\ grep\ PATH'
in event handler: handler for generic event “fish_preexec”
- (line 6): Unknown command
        set -g ATUIN_HISTORY_ID (atuin history start -- "$argv[1]")
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
in function '_atuin_preexec' with arguments 'env\ \|\ grep\ PATH'
in event handler: handler for generic event “fish_preexec”
PATH=/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/sbin:/opt/puppetlabs/bin:/Applications/Wireshark.app/Contents/MacOS

And then combining the two of them:

❯ env __HM_SESS_VARS_SOURCED= __ETC_PROFILE_DONE= /Users/foobar/.nix-profile/bin/fish
fish: Unknown command: atuin
- (line 1): 
atuin history start -- "$argv[1]"
^~~~^
in command substitution
    called on line 6 of file -
in function '_atuin_preexec' with arguments 'env\ __HM_SESS_VARS_SOURCED=\ __ETC_PROFILE_DONE=\ /Users/foobar/.nix-profile/bin/fish'
in event handler: handler for generic event “fish_preexec”
- (line 6): Unknown command
        set -g ATUIN_HISTORY_ID (atuin history start -- "$argv[1]")
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
in function '_atuin_preexec' with arguments 'env\ __HM_SESS_VARS_SOURCED=\ __ETC_PROFILE_DONE=\ /Users/foobar/.nix-profile/bin/fish'
in event handler: handler for generic event “fish_preexec”
PATH before initialisation > /usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/sbin:/opt/puppetlabs/bin:/Applications/Wireshark.app/Contents/MacOS
fish: Unknown command: atuin
- (line 1): 
atuin uuid
^~~~^
in command substitution
    called on line 1 of file -
from sourcing file -
    called on line 43 of file ~/.config/fish/config.fish
from sourcing file ~/.config/fish/config.fish
    called during startup
- (line 1): Unknown command
set -gx ATUIN_SESSION (atuin uuid)
                      ^~~~~~~~~~~^
from sourcing file -
    called on line 43 of file ~/.config/fish/config.fish
from sourcing file ~/.config/fish/config.fish
    called during startup
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish

~ 
❯ env | grep PATH
fish: Unknown command: atuin
- (line 1): 
atuin history start -- "$argv[1]"
^~~~^
in command substitution
    called on line 6 of file -
in function '_atuin_preexec' with arguments 'env\ \|\ grep\ PATH'
in event handler: handler for generic event “fish_preexec”
- (line 6): Unknown command
        set -g ATUIN_HISTORY_ID (atuin history start -- "$argv[1]")
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
in function '_atuin_preexec' with arguments 'env\ \|\ grep\ PATH'
in event handler: handler for generic event “fish_preexec”
PATH=/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/sbin:/opt/puppetlabs/bin:/Applications/Wireshark.app/Contents/MacOS

Does the above tell you anything useful?