mirror of
https://github.com/nix-community/home-manager.git
synced 2026-01-11 01:19:32 +08:00
fish: expose session variables package
This allows fish users to source the `hm-session-vars.fish` if they are not using the generated `config.fish` (which now sources the same file).
This commit is contained in:
committed by
Matthieu Coudron
parent
46c9af8a92
commit
af7f14ddf7
@@ -17,8 +17,11 @@ way. In Bash and Z shell this can be done by adding
|
||||
to your `.profile` and `.zshrc` files, respectively. The
|
||||
`hm-session-vars.sh` file should work in most Bourne-like shells. For
|
||||
fish shell, it is possible to source it using [the foreign-env
|
||||
plugin](https://github.com/oh-my-fish/plugin-foreign-env)
|
||||
plugin](https://github.com/oh-my-fish/plugin-foreign-env) or using the builtin
|
||||
[babelfish](https://github.com/bouk/babelfish)-translated variables:
|
||||
|
||||
``` bash
|
||||
fenv source "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" > /dev/null
|
||||
# or
|
||||
source "$HOME/.nix-profile/etc/profile.d/hm-session-vars.fish"
|
||||
```
|
||||
|
||||
@@ -388,12 +388,14 @@ let
|
||||
passAsFile = [ "text" ];
|
||||
} "env HOME=$(mktemp -d) fish_indent < $textPath > $out";
|
||||
|
||||
translatedSessionVariables = pkgs.runCommandLocal "hm-session-vars.fish" { } ''
|
||||
sessionVarsFile = "etc/profile.d/hm-session-vars.fish";
|
||||
sessionVarsPkg = pkgs.runCommandLocal "hm-session-vars.fish" { } ''
|
||||
mkdir -p "$(dirname $out/${sessionVarsFile})"
|
||||
(echo "function setup_hm_session_vars;"
|
||||
${pkgs.buildPackages.babelfish}/bin/babelfish \
|
||||
<${config.home.sessionVariablesPackage}/etc/profile.d/hm-session-vars.sh
|
||||
<${config.home.sessionVariablesPackage}/etc/profile.d/hm-session-vars.sh
|
||||
echo "end"
|
||||
echo "setup_hm_session_vars") > $out
|
||||
echo "setup_hm_session_vars") > $out/${sessionVarsFile}
|
||||
'';
|
||||
|
||||
in
|
||||
@@ -591,11 +593,25 @@ in
|
||||
<https://fishshell.com/docs/current/completions.html>.
|
||||
'';
|
||||
};
|
||||
|
||||
programs.fish.sessionVariablesPackage = mkOption {
|
||||
type = types.package;
|
||||
internal = true;
|
||||
description = ''
|
||||
The package containing the translated {file}`hm-session-vars.fish` file.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable (
|
||||
lib.mkMerge [
|
||||
{ home.packages = [ cfg.package ]; }
|
||||
{
|
||||
home.packages = [
|
||||
cfg.package
|
||||
cfg.sessionVariablesPackage
|
||||
];
|
||||
programs.fish.sessionVariablesPackage = sessionVarsPkg;
|
||||
}
|
||||
|
||||
(mkIf cfg.generateCompletions (
|
||||
let
|
||||
@@ -708,7 +724,7 @@ in
|
||||
set -q __fish_home_manager_config_sourced; and exit
|
||||
set -g __fish_home_manager_config_sourced 1
|
||||
|
||||
source ${translatedSessionVariables}
|
||||
source ${cfg.sessionVariablesPackage}/${sessionVarsFile}
|
||||
|
||||
${cfg.shellInit}
|
||||
|
||||
|
||||
@@ -7,4 +7,5 @@
|
||||
fish-plugins = ./plugins.nix;
|
||||
fish-manpage = ./manpage.nix;
|
||||
fish-binds = ./binds.nix;
|
||||
fish-session-variables = ./session-variables.nix;
|
||||
}
|
||||
|
||||
20
tests/modules/programs/fish/session-variables.nix
Normal file
20
tests/modules/programs/fish/session-variables.nix
Normal file
@@ -0,0 +1,20 @@
|
||||
{ config, ... }:
|
||||
|
||||
{
|
||||
config = {
|
||||
home.sessionVariables = {
|
||||
V1 = "v1";
|
||||
V2 = "v2-${config.home.sessionVariables.V1}";
|
||||
};
|
||||
|
||||
programs.fish.enable = true;
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists home-path/etc/profile.d/hm-session-vars.fish
|
||||
assertFileRegex home-path/etc/profile.d/hm-session-vars.fish \
|
||||
"set -gx V1 'v1'"
|
||||
assertFileRegex home-path/etc/profile.d/hm-session-vars.fish \
|
||||
"set -gx V1 'v1'"
|
||||
'';
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user