Visitar URL original
Allow specifying the fish config directory with FISH_CONFIG_DIR by OleStrohm · Pull Request #13074 · fish-shell/fish-shell · GitHub
Skip to content

Allow specifying the fish config directory with FISH_CONFIG_DIR - #13074

Open
OleStrohm wants to merge 1 commit into
fish-shell:masterfrom
OleStrohm:push-llluznkmssrp
Open

OleStrohm wants to merge 1 commit into
fish-shell:masterfrom
OleStrohm:push-llluznkmssrp

Conversation

@OleStrohm

@OleStrohm OleStrohm commented Oct 29, 2026 •

Copy link
Copy Markdown

This adds an environment variable that allows the user to specify the fish config directory.
This is primarily aimed at usage with nix, as it will allow making a fully hermetic fish installation that includes the configuration inside it. See example flake.nix:

Details The config would be in the same directory as the flake.nix (Note: This assumes that this commit is merged and updated in nixpkgs)
{
  description = "A fish installation wrapped with the fish config";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
  };

  outputs = { nixpkgs, ... }:
    let
      pkgs = (import nixpkgs) {
        system = "x86_64-linux";
      };

      fish = pkgs.stdenv.mkDerivation {
        pname = "fish";
        version = "wrapped";

        buildInputs = [ pkgs.makeWrapper ];
        dontUnpack = true;

        installPhase = ''
          mkdir -p $out/
          cp -r ${pkgs.fish}/* $out/
          chmod -R +rw $out/
          rm $out/bin/fish
          makeWrapper ${pkgs.fish}/bin/fish $out/bin/fish --set-default FISH_CONFIG_DIR ${./.}
        '';

        meta = {
          description = "Custom wrapped fish shell";
          mainProgram = "fish";
        };
        passthru = {
          shellPath = "/bin/fish";
        };
      };
  in
  {
    packages.x86_64-linux.default = fish;
  };
}

But I believe that this will also be useful for people wanting to try out someone else's configs more easily (just download it and set CONFIG_FISH_DIR, without affecting your actual installed config in any way)

TODOs:

  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added
  • User-visible changes noted in CHANGELOG.rst

Not sure how to add a test for this to be perfectly honest, so guidance for that would be very helpful!

@OleStrohm

Copy link
Copy Markdown
Author

Looks like the failing test is also failing on latest master

@agammann agammann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Resolve a relative FISH_CONFIG_DIR once against the startup working directory. The new override stores ./my-fish verbatim in the static config path. Startup can source ./my-fish/config.fish, but after cd /tmp, __fish_config_dir and the function/completion paths built from it now point at /tmp/my-fish instead. That silently changes which config files are read and can autoload a different function from the new directory. The documented override does not require an absolute path, so normalize relative values before caching them and add a cd regression test.

@zanchey

zanchey commented Nov 3, 2026

Copy link
Copy Markdown
Member

We've previously decided against this (see #3030), although the idea of a "hermetic portable fish" is interesting. I'm inclined not to merge this because of the additional complexity in interface though.

@OleStrohm

Copy link
Copy Markdown
Author

@zanchey I should've looked to see if there had been prior art, apologies! I can understand the desire not to add complexity to the interface, but the original decision made in #3030 was based on someone wanting to place their fish config in a different directory. That can be handled, as people mention, by either deciding not to, using a symlink, or changing XDG_CONFIG_DIR.
However the use-case I'm proposing is not covered by any of those options. If I change XDG_CONFIG_DIR, then it will impact other software running inside the fish (Just because someone is running a hermetic fish Nix flake does not mean their entire system is Nix-based, so it would mess up their actual XDG_CONFIG_DIR setting. For example I intend to run this on my Ubuntu machine at work in addition to using it in my Nix machine at home).
Using a symlink from ~/.config/fish is not possible as that's not possible in Nix.
And of course I can just not do this, but that's no fun!

I would love to see this supported upstream, as I don't want to rebase this patch every time I want to upgrade fish, but I will if it's not wanted by the project, but hopefully you will reconsider!
Is there any adjustment that can be made that would lower the complexity perhaps?

@agammann I will make the change you suggest and try to figure out how to make a test for this ☺️

@OleStrohm
OleStrohm force-pushed the push-llluznkmssrp branch 2 times, most recently from ea90996 to a3d637c Compare November 3, 2026 23:22
@OleStrohm

Copy link
Copy Markdown
Author

I've made the path absolute and added a test that verifies the behaviour of this feature in general 🎉

@OleStrohm
OleStrohm force-pushed the push-llluznkmssrp branch 2 times, most recently from c2d6684 to 0b71585 Compare November 3, 2026 23:29

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants