Putting fish.config into configuration.nix

I would like to put the contents of my fish.config into configuration.nix for reproducibility/central configuration.

E.g. in my fish.config i have the following entires:

if status is-interactive

    set -g fish_key_bindings fish_default_key_bindings
    bind \cc kill-whole-line repaint
    bind \cd forward-char

    set -g fish_greeting

    fish_add_path ~/Dokumente/Install/Linux/Skripte
    ### Hinzugefügt für Emacs
#     fish_add_path ~/.npm-global/bin
#     fish_add_path ~/.config/composer/vendor/bin
    fish_add_path ~/.emacs.d/bin
    fish_add_path /run/current-system/sw/share/hunspell

end

zoxide init fish --cmd j | source

Entering them under programs.fish.shellInit or programs.fish.interactiveShellInit doesn’t work because Nixos complains about things like set -g or bind. I guess, because these are not normal commands but specific to fish.

How can i get around this? Do i have to escape the commands or is someting else the matter? Or am i just not meant to define my fish.config in configuration.nix?

I also couldn’t find out how to simply add contents to the system wide PATH although reading through a lot of google search results. They were dealing with making custom scripts or packages run, which isn’t my problem as far as i understand it.

So far, the only thing that i could transfer were global variables with environment.sessionVariables

How did you add stuff to the options? And what was the exact error?

“Package“ with the executable copied to $out/bin and then add the “package” to environment.systemPackages

If it set

  programs.fish.interactiveShellInit = {
    set -g fish_key_bindings fish_default_key_bindings
      bind \cc kill-whole-line repaint
      bind \cd forward-char
  };

i get

error: syntax error, unexpected '-', expecting '.' or '='

       at /etc/nixos/configuration.nix:284:9:

          283|   programs.fish.interactiveHsellInit={
          284|     set -g fish_key_bindings fish_default_key_bindings
             |         ^
          285|       bind \cc kill-whole-line repaint
(use '--show-trace' to show detailed location information)

Regarding the path, i would like to add e.g. ~/Dokumente/Install/Linux/Skripte and ~/.emacs.d/bin to PATH and not an indiviual program within the directory. So i don’t want to work with a nix pkgs but just add the whole directory to PATH.

This is not a big issue of course because i can just leave it in fish.config but i was wondering if i could transfer all instructions from my fish.config to configuration.nix

programs.fish.interactiveShellInit is a string:

  programs.fish.interactiveShellInit = ''
    set -g fish_key_bindings fish_default_key_bindings
      bind \cc kill-whole-line repaint
      bind \cd forward-char
  '';

This should do.

Even though you can use environment.sessionVariables or similar options, I’d strictly advice against that.

Whatever you put there will not work anyway on nixos, unless it is prepared for it. And the most reliable way to prepare is to package.

You do not need to submit to nixpkgs but can use local “package descriptions”.

1 Like

Thank you! I wasn’t aware that i have to set ‘’ at the beginning and end of block…

" encloses a single line string, '' encloses multiline strings, while {/} is for attribute sets, aka key value stores or maps.

1 Like

Thank you. I should read up on that, sorry

Currently the docs for that live here: Nix Language

They assume a fair bit of pre-knowledge though. Aiui a nix language tutorial is in the works which might be worth waiting for if you want to understand this kind of thing, presumably it will live on http://nix.dev

1 Like