nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.91k stars 1.8k forks source link

Fish session vars not present as expected #1977

Closed rrrnld closed 3 years ago

rrrnld commented 3 years ago

Issue description

I have a couple of lines in my ~/.config/nixpkgs/home.nix that manipulate session variables. I expected these to be present in my fish terminal sessions (fish is my default shell), but they're not.

I installed foreign-env manually after previously realizing that it wasn't getting installed automatically. My complete fish config looks like this:

{
  # ...
  home.sessionPath = [ "$HOME/.emacs.d/bin" "$HOME/.local/bin" ];
  home.sessionVariables = {
    MOZ_ENABLE_WAYLAND = "1";
    EDITOR = "${pkgs.neovim}/bin/nvim";
  };

  programs = {
    fish = {
      enable = true;
      plugins = [
        {
          # required to manage shell environment through home-manager
          name = "foreign-env";
          src = pkgs.fish-foreign-env;
        }

        {
          name = "bang-bang";
          src = pkgs.fetchFromGitHub {
            owner = "oh-my-fish";
            repo = "plugin-bang-bang";
            rev = "f969c618301163273d0a03d002614d9a81952c1e";
            hash = "sha256-A8ydBX4LORk+nutjHurqNNWFmW6LIiBPQcxS3x4nbeQ=";
          };
        }

        {
          name = "fasd";
          src = pkgs.fetchFromGitHub {
            owner = "oh-my-fish";
            repo = "plugin-fasd";
            rev = "98c4c729780d8bd0a86031db7d51a97d55025cf5";
            hash = "sha256-8JASaNylXAGnWd2IV88juk73b8eJJlVrpyiRZUwHGFQ=";
          };
        }

        {
          name = "pure";
          src = pkgs.fetchFromGitHub {
            owner = "pure-fish";
            repo = "pure";
            rev = "9d17b2780165572bc6c181cd0e7c5d6dd13be5c1";
            hash = "sha256-60NKbQurOxqjnXmluDCh+C/b/z52IYK2g4CeZASWyJk=";
          };
        }
      ];

      functions = {
        mkd = {
          body = "mkdir -p $argv[1]; and cd $argv[1]";
        };
      };

      shellAliases = {
        e = "emacsclient";

        docker = "podman";
        docker-compose = "podman-compose";
        pbcopy = "xsel --clipboard -i";
        pbpaste = "xsel --clipboard -o";
        open = "xdg-open";
        rm = "rm -i";

        dokku = "ssh dokku@arnes.space -t";

        # git aliases
        ga = "git add";
        gc = "git commit";
        "gc!" = "git commit --amend";
        "gc!!" = "git commit --amend --no-edit";
        gco = "git checkout";
        gd = "git diff --ignore-all-space";
        gdw = "git diff --ignore-all-space --color-words";
        glg = "git log --oneline";
        gp = "git push";
        gs = "git status";
        gss = "git status --short";

        urlencode = "jq -sRr @uri";
        benjamins = "nvim +(wc -l ~/ledger/finances-2021.ledger | cut -d' ' -f1) ~/ledger/finances-2021.ledger";
      };

      # tomorrow night theme
      loginShellInit = ''
        set -L
        set -U fish_color_normal normal
        set -U fish_color_command 81a1c1
        set -U fish_color_redirection b48ead
        set -U fish_color_quote a3be8c
        set -U fish_color_end 88c0d0
        set -U fish_color_user brgreen
        set -U fish_color_param eceff4
        set -U fish_pager_color_progress brwhite --background=cyan
        set -U fish_pager_color_prefix white --bold --underline
        set -U fish_pager_color_description B3A06D yellow
        set -U fish_pager_color_completion normal
        set -U fish_color_cancel -r
        set -U fish_color_match --background=brblue
        set -U fish_color_error ebcb8b
        set -U fish_color_selection white --bold --background=brblack
        set -U fish_color_search_match bryellow --background=brblack
        set -U fish_color_history_current --bold
        set -U fish_color_operator 00a6b2
        set -U fish_color_escape 00a6b2
        set -U fish_color_cwd green
        set -U fish_color_cwd_root red
        set -U fish_color_valid_path --underline
        set -U fish_color_autosuggestion 4c566a
        set -U fish_color_comment 434c5e
        set -U fish_color_host normal
      '';

      interactiveShellInit = ''
        # FIXME: Need to explicitly call this to show new lines between prompts
        # in pure
        _pure_prompt_new_line
      '';
    };
  };
}

My ~/.nix-profile/etc/profile.d/hm-session.vars.sh looks like this:

# Only source this once.
if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
export __HM_SESS_VARS_SOURCED=1

export EDITOR="/nix/store/hwh9hdpa75mhq44ra5978459hjyf1y4v-neovim-0.4.4/bin/nvim"
export FZF_CTRL_T_COMMAND="fd --type f"
export FZF_DEFAULT_OPTS="--height 80% --reverse --prompt \"❯ \" --pointer \"❯ \""
export MOZ_ENABLE_WAYLAND="1"
export MSMTP_LOG="/home/arne/.local/share/msmtp/queue.log"
export MSMTP_QUEUE="/home/arne/.local/share/msmtp/queue"
export NMBGIT="/home/arne/.local/share/notmuch/nmbug"
export NOTMUCH_CONFIG="/home/arne/.config/notmuch/notmuchrc"
export PASSWORD_STORE_DIR="/home/arne/.local/share/password-store"
export PATH="$PATH${PATH:+:}$HOME/.emacs.d/bin:$HOME/.local/bin"

Checking these variables in a Fish session gives the following result:

$ echo $__HM_SESS_VARS_SOURCED
1
$ echo $EDITOR
nano
$ # from $FZF_CTRL_T_COMMAND until $PASSWORD_STORE_DIR, all are set as expected
$ echo $PATH
/run/wrappers/bin /home/arne/.nix-profile/bin /etc/profiles/per-user/arne/bin /nix/var/nix/profiles/default/bin /run/current-system/sw/bin

Meta

Maintainer CC

@meck

Technical detail

 - system: `"x86_64-linux"`
 - host os: `Linux 5.4.112, NixOS, 20.09.4025.dc326c78a93 (Nightingale)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.4pre20210326_dd77f71`
 - channels(arne): `"home-manager-20.09"`
 - channels(root): `"nixos-20.09.4025.dc326c78a93, nixos-hardware, nixos-unstable-21.05pre285574.8e4fe32876c"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
rycee commented 3 years ago

Curious. Unfortunately I don't know much about fish but did you log out and back in after changing the configuration?

rrrnld commented 3 years ago

Ha… Just as I said to myself "of course I did!" and rebooted just to make sure, the problem went away. So thanks for the reminder!

rycee commented 3 years ago

Glad it worked out. Also, thanks for making such a detailed report!

meck commented 3 years ago

Any reason you cc'd me as maintainer?

rrrnld commented 3 years ago

Any reason you cc'd me as maintainer?

Yes, the issue template suggested to CC the last person that worked on the module when in doubt. Sorry if that was a mistake!

meck commented 3 years ago

Yes, the issue template suggested to CC the last person that worked on the module when in doubt. Sorry if that was a mistake!

No problem! just wanted to se if I was listed somewhere.

theotheroracle commented 1 year ago

is there a reason that restarting the shell doesn't reload the variables ? if it's sourcing the hm-session.vars.fish file every time, why don't the variables update until logout and login ? having to logout and login while testing variables is pretty tedious, and if possible to avoid, would be nice