NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.37k stars 13.6k forks source link

`/etc/fish/nixos-env-preinit.fish` is run after fish-internal `config.fish`, destroying `$fish_function_path` #218306

Open diktomat opened 1 year ago

diktomat commented 1 year ago

Describe the bug

/etc/fish/nixos-env-preinit.fish uses a temporary $fish_function_path, as "This happens before $__fish_datadir/config.fish sets fish_function_path, so it is currently unset." (comment in file). However, it is actually run after $__fish_datadir/config.fish (= /nix/store/jv695hxb7dvn971mxjrfxzmf6sppsvgs-fish-3.6.0/share/fish/config.fish), so it leaves an empty function path behind, leading to errors on startup.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Install Fish using programs.fish.enable = true; in home-manager and nix-darwin configs.
  2. fish --help (or any other fish cmd, including just starting it) errors not finding functions.
  3. echo $fish_function_path inside fish is empty.

Expected behavior

/etc/fish/nixos-env-preinit.fish should be run before $__fish_datadir/config.fish, as it's preinit.

Additional context

Complete flake: https://gist.github.com/d12bb/f4ac5936eb4ab0184f2eb3e1fbe6973c

Notify maintainers

@cole-h @winterqt @rapenne-s

Metadata

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"aarch64-darwin"`
 - host os: `Darwin 22.2.0, macOS 13.1`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.13.2`
 - channels(root): `""`
 - nixpkgs: `/nix/store/x9inhkqzamikrzjx808xkdilnwxfymai-source`
winterqt commented 1 year ago

I'll look into this when I get a chance, but I notably cannot reproduce this with the same configuration you have set up:

$ echo $fish_function_path
/Users/winter/.config/fish/functions /nix/store/zdndayx0blswvg332xx3bi2c03gwmcdc-fish-3.6.0/etc/fish/functions /Users/winter/.local/share/fish/vendor_functions.d /Users/winter/.nix-profile/share/fish/vendor_functions.d /run/current-system/sw/share/fish/vendor_functions.d /nix/var/nix/profiles/default/share/fish/vendor_functions.d /Users/winter/.nix-profile/etc/fish/functions /run/current-system/sw/etc/fish/functions /nix/var/nix/profiles/default/etc/fish/functions /Users/winter/.nix-profile/share/fish/vendor_functions.d /run/current-system/sw/share/fish/vendor_functions.d /nix/var/nix/profiles/default/share/fish/vendor_functions.d /nix/store/zdndayx0blswvg332xx3bi2c03gwmcdc-fish-3.6.0/share/fish/vendor_functions.d /nix/store/zdndayx0blswvg332xx3bi2c03gwmcdc-fish-3.6.0/share/fish/functions

Given this, I feel like there's more to the issue, though I don't know what 🤔

winterqt commented 1 year ago

Ah, okay, let's try something:

Can you edit your nix-darwin configuration to contain this:

  programs.fish = {
    enable = true;
    useBabelfish = true;
    babelfishPackage = pkgs.babelfish;
  };

And see if the issue still persists?

diktomat commented 1 year ago

And see if the issue still persists?

Works with babelfish added.

winterqt commented 1 year ago

Cool, please use that as a "workaround" (IMO it's better anyways). I'll see to looking into why/when this regressed. Thank you for the report!

diktomat commented 1 year ago

I'll do, thank you very much! (If you'd like to elaborate, why is this better? I never had the need for using posix scripts from inside fish before, so never researched foreign-env and babelfish..)

winterqt commented 1 year ago

babelfish translates the Bash scripts ahead-of-time as opposed to fenv doing it every time it needs to interpret a script. So... speed!