Fish error through SSH

I’ve just enabled SSH so that I can remotely connect to my Nixos machine.

From my other non-nixos machine, I do :

ssh 192.168.14.20 -o PreferredAuthentications=password -l jalil

I get

Last login: Tue Apr  5 23:11:45 2022
error: Votre historique ne sera pas sauvegardé.
warning-path: Impossible de localiser le dossier data obtenu de $XDG_DATA_HOME: '/.local/share/fish'.
warning-path: L’erreur était 'Permission denied'
warning-path: Veuillez paramétrer $XDG_DATA_HOME à un dossier dans lequel vous avez un accès en écriture.

error: Vos paramètres personnels ne seront pas sauvegardés.
warning-path: Impossible de localiser le dossier config obtenu de $XDG_CONFIG_HOME: '/.config/fish'.
warning-path: L’erreur était 'Permission denied'
warning-path: Veuillez paramétrer $XDG_CONFIG_HOME à un dossier dans lequel vous avez un accès en écriture.

/nix/store/khkhvvmsfy8ysq3rd3lvanql1w9xp2m4-coreutils-9.0/bin/mkdir: cannot create directory ‘/generated_completions’: Permission denied
Bienvenue dans fish, le shell amical et interactif
Type help for instructions on how to use fish
mkdir: impossible de créer le répertoire « /completions »: Permission denied
mkdir: impossible de créer le répertoire « /conf.d »: Permission denied
mkdir: impossible de créer le répertoire « /functions »: Permission denied
warning: An error occurred while redirecting file '/config.fish'
open: Permission denied

(Sorry for the french parts)

I’ve checked that I own the mentionned folders and have rw rights on them …

Strange thing is that when I start fish command in the opened SSH session, it works well then :

Linux tq2 5.10.105 x86_64
 23:24:30  actif  0:42,  2 utilisateurs,  charge moyenne : 0,30, 0,38, 0,32
 jalil@tq2  ~                                                                   

I don’t know if it’s more a problem with Nixos or Fish … ?

Of course, local terminal works fine. I only experience this with SSH. I have the same issue if I connect ssh locally.

Hi again,

I’ve opened an issue on fish Github ( Error initializing fish though ssh · Issue #9251 · fish-shell/fish-shell · GitHub ), but I feel like it’s a Nixos issue :

 ~ > ssh localhost 'echo $USER $HOME $XDG_CONFIG_HOME'
error: can not save history
warning-path: Impossible de localiser le dossier data obtenu de $XDG_DATA_HOME: '/.local/share/fish'.
warning-path: L’erreur était 'Permission denied'
warning-path: Veuillez paramétrer $XDG_DATA_HOME à un dossier dans lequel vous avez un accès en écriture.

error: can not save universal variables or functions
warning-path: Impossible de localiser le dossier config obtenu de $XDG_CONFIG_HOME: '/.config/fish'.
warning-path: L’erreur était 'Permission denied'
warning-path: Veuillez paramétrer $XDG_CONFIG_HOME à un dossier dans lequel vous avez un accès en écriture.

Jalil
jalil /home/jalil /.config
 ~ >

Yes, it seems that despite $HOME is right $XDG_CONFIG_HOME et not correct … not sure why …

My Nixos config states :

environment.sessionVariables = rec {
      XDG_CACHE_HOME  = "\${HOME}/.cache";
      XDG_CONFIG_HOME = "\${HOME}/.config";
      XDG_BIN_HOME    = "\${HOME}/.local/bin";
      XDG_DATA_HOME   = "\${HOME}/.local/share";

      PATH = [
        "\${XDG_BIN_HOME}"
      ];
    };

Hi,

I see your fish shell prompt seems customized, could you try to disable some plugins and see if you still have the error?

I expect some shell code to be loaded / or not loaded due to a plugin.

Could you temporary switch the shell to bash or zsh and see if they have the same behavior?

Something looks wrong during the shell setup, it’s missing variables like HOME.

I’ve disabled omf but without success :

jalil@g ~> ssh localhost
Last login: Wed Oct  5 14:25:02 2022 from ::1
error: can not save history
warning-path: Impossible de localiser le dossier data obtenu de $XDG_DATA_HOME: '/.local/share/fish'.
warning-path: L’erreur était 'Permission denied'
warning-path: Veuillez paramétrer $XDG_DATA_HOME à un dossier dans lequel vous avez un accès en écriture.

error: can not save universal variables or functions
warning-path: Impossible de localiser le dossier config obtenu de $XDG_CONFIG_HOME: '/.config/fish'.
warning-path: L’erreur était 'Permission denied'
warning-path: Veuillez paramétrer $XDG_CONFIG_HOME à un dossier dans lequel vous avez un accès en écriture.

/nix/store/qarssrazji0q9xp80xg8shsm2crckfr0-coreutils-9.0/bin/mkdir: cannot create directory ‘/generated_completions’: Permission denied
Bienvenue dans fish, le shell amical et interactif
Type help for instructions on how to use fish
mkdir: impossible de créer le répertoire « /completions »: Permission denied
mkdir: impossible de créer le répertoire « /conf.d »: Permission denied
mkdir: impossible de créer le répertoire « /functions »: Permission denied
warning: An error occurred while redirecting file '/config.fish'
open: Permission denied
jalil@g ~> 

what about temporary trying with bash and zsh to see if they have the same kind of issue?

I’ve tried to check my Nixos configuration but now it’s even worse !

My config :

programs.fish.enable = true;
users.defaultUserShell = pkgs.fish;
users.extraUsers.jalil.shell = pkgs.fish;

The result :

jalil@g ~> ssh localhost
Last login: Wed Oct  5 14:59:53 2022 from ::1
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
/nix/store/qarssrazji0q9xp80xg8shsm2crckfr0-coreutils-9.0/bin/mkdir: cannot create directory ‘/.local/share/fish/generated_completions’: Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
Bienvenue dans fish, le shell amical et interactif
Type help for instructions on how to use fish
error: Unable to open universal variable file '/': Permission denied
mkdir: impossible de créer le répertoire « /.config/fish »: Permission denied
mkdir: impossible de créer le répertoire « /.config/fish »: Permission denied
mkdir: impossible de créer le répertoire « /.config/fish »: Permission denied
error: Unable to open universal variable file '/': Permission denied
warning: An error occurred while redirecting file '/.config/fish/config.fish'
open: Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
error: Unable to open universal variable file '/': Permission denied
jalil@g ~> fish
Bienvenue dans fish, le shell amical et interactif
Type help for instructions on how to use fish
jalil@g ~> 

I’ve juste switched to zsh … no issue :

jalil@g:~/ > ssh localhost
Last login: Wed Oct  5 15:12:13 2022 from ::1
jalil@g:~/ > 

do you have something special in ~/.config/fish/config.fish or ~/.config/fish/conf.d/* ?

Sadly I don’t speak french so I can’t read the error messages and I might therefore be completely wrong, but:

Can’t link to it directly, but the docs for strings are here: Data Types

They mention that the escape for antiquotation ("${}" stuff) is this:

      XDG_CACHE_HOME  = "''${HOME}/.cache";
      XDG_CONFIG_HOME = "''${HOME}/.config";
      XDG_BIN_HOME    = "''${HOME}/.local/bin";
      XDG_DATA_HOME   = "''${HOME}/.local/share";

If discourse’s syntax highlighting was better, you’d be able to tell here too :slight_smile:

Ignore me, seems for non-indented strings it’s a \ indeed

config.fish :

if status is-interactive
    # Commands to run in interactive sessions can go here
end

conf.d as only one file omf.fish all commented out (and I can see that plugin is not enabled anymore)

The problem is with how nixos is parsing the environment variables for the pam module. Check out the file /etc/pam/environment and you will probably see that most variables are defined as @{HOME}, except for the ones manually defines on config.environment.sessionVariables.

The workaround is to change how variables are used in the sessionVariables section to:

      XDG_CACHE_HOME  = "\$HOME/.cache";
      XDG_CONFIG_HOME = "\$HOME/.config";
      XDG_BIN_HOME    = "\$HOME/.local/bin";
      XDG_DATA_HOME   = "\$HOME/.local/share";

Removing the curly braces makes the parser change $HOME → @{HOME}

I have only been using nix for a few hours and I am not familiar with the procedure to report bugs, in case anyone else wants to report it, please go ahead.

2 Likes

Wow ! That did the trick !

Many thanks @Litz ! I would never have found that !

1 Like