fish: use babelfish for hm-session-vars.sh (#4012)

* home-environment: add `home.sessionVariablesPackage`

Allow the `hm-session-vars.sh` derivation to be referenced from other
modules, e.g. to translate it to fish with babelfish at build time.

* fish: use babelfish for `hm-session-vars.sh`

Translate `hm-session-vars.sh` to fish at system build time,
significantly decreasing shell startup time.

Based on https://github.com/NixOS/nixpkgs/pull/108947 by @kevingriffin.
This commit is contained in:
Emily 2023-05-31 23:01:27 +01:00 committed by GitHub
parent f1490b8caf
commit 53ccbe0170
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 20 deletions

View file

@ -152,6 +152,13 @@ let
passAsFile = [ "text" ];
} "env HOME=$(mktemp -d) fish_indent < $textPath > $out";
translatedSessionVariables =
pkgs.runCommandLocal "hm-session-vars.fish" { } ''
${pkgs.babelfish}/bin/babelfish \
<${config.home.sessionVariablesPackage}/etc/profile.d/hm-session-vars.sh \
>$out
'';
in {
imports = [
(mkRemovedOptionModule [ "programs" "fish" "promptInit" ] ''
@ -354,9 +361,7 @@ in {
set -q __fish_home_manager_config_sourced; and exit
set -g __fish_home_manager_config_sourced 1
set --prepend fish_function_path ${pkgs.fishPlugins.foreign-env}/share/fish/vendor_functions.d
fenv source ${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh > /dev/null
set -e fish_function_path[1]
source ${translatedSessionVariables}
${cfg.shellInit}