How to set startup script in Fish shell using home-manager?

I am running Debian with home-manager.

I want to run a script when the Fish shell starts. It is usually placed at ~/.config/fish/conf.d/ but how do I do it with home-manager?

What I tried:

options.programs.fish.interactiveShellInit = mkOption {
        type = types.lines;
        default = "fnm env --use-on-cd | source";
        description = ''
          Shell script code called during interactive fish shell
          initialisation.
        '';
      };

But it gives the following error:

❯ home-manager switch
error: undefined variable 'mkOption'

       at /home/user/.config/nixpkgs/home.nix:71:48:

           70|
           71|   options.programs.fish.interactiveShellInit = mkOption {
             |                                                ^
           72|     type = types.lines;
(use '--show-trace' to show detailed location information)

Basically I am tring to setup fnm for fish shell.

That’s how you would create a completely new option. You’d also have to make mkOption available from nixpkgs’ lib to do this.

But this option already exists: Redirecting…

Just set it:

programs.fish.interactiveShellIinit = ''
  fnm env --use-on-cd | source
'';
2 Likes