mirror of
https://github.com/nix-community/home-manager
synced 2025-01-30 21:05:02 +01: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:
parent
7e00856596
commit
e48030e9a7
4 changed files with 53 additions and 7 deletions
|
@ -17,8 +17,11 @@ way. In Bash and Z shell this can be done by adding
|
||||||
to your `.profile` and `.zshrc` files, respectively. The
|
to your `.profile` and `.zshrc` files, respectively. The
|
||||||
`hm-session-vars.sh` file should work in most Bourne-like shells. For
|
`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
|
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
|
``` bash
|
||||||
fenv source "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" > /dev/null
|
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"
|
||||||
```
|
```
|
||||||
|
|
|
@ -220,13 +220,16 @@ let
|
||||||
passAsFile = [ "text" ];
|
passAsFile = [ "text" ];
|
||||||
} "env HOME=$(mktemp -d) fish_indent < $textPath > $out";
|
} "env HOME=$(mktemp -d) fish_indent < $textPath > $out";
|
||||||
|
|
||||||
|
profileDir = "/etc/profile.d";
|
||||||
|
translatedSessionVarsFile = "hm-session-vars.fish";
|
||||||
translatedSessionVariables =
|
translatedSessionVariables =
|
||||||
pkgs.runCommandLocal "hm-session-vars.fish" { } ''
|
pkgs.runCommandLocal translatedSessionVarsFile { } ''
|
||||||
|
mkdir -p $out/${profileDir}
|
||||||
(echo "function setup_hm_session_vars;"
|
(echo "function setup_hm_session_vars;"
|
||||||
${pkgs.buildPackages.babelfish}/bin/babelfish \
|
${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 "end"
|
||||||
echo "setup_hm_session_vars") > $out
|
echo "setup_hm_session_vars") > $out/${profileDir}/${translatedSessionVarsFile}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
in {
|
in {
|
||||||
|
@ -393,11 +396,24 @@ in {
|
||||||
<https://fishshell.com/docs/current/cmds/function.html>.
|
<https://fishshell.com/docs/current/cmds/function.html>.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# TODO: maybe this makes more sense as `programs.fish.sessionVariablesPackage`?
|
||||||
|
# if `programs.fish.sessionVariables` were added, would that need its own
|
||||||
|
# separate package, or would they just go in config.fish directly?
|
||||||
|
home.fishSessionVariablesPackage = mkOption {
|
||||||
|
type = types.package;
|
||||||
|
internal = true;
|
||||||
|
description = ''
|
||||||
|
The package containing the translated {file}`hm-session-vars.fish` file.
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable (mkMerge [
|
config = mkIf cfg.enable (mkMerge [
|
||||||
{ home.packages = [ cfg.package ]; }
|
{
|
||||||
|
home.fishSessionVariablesPackage = translatedSessionVariables;
|
||||||
|
home.packages = [ cfg.package config.home.fishSessionVariablesPackage ];
|
||||||
|
}
|
||||||
(mkIf cfg.generateCompletions {
|
(mkIf cfg.generateCompletions {
|
||||||
# Support completion for `man` by building a cache for `apropos`.
|
# Support completion for `man` by building a cache for `apropos`.
|
||||||
programs.man.generateCaches = mkDefault true;
|
programs.man.generateCaches = mkDefault true;
|
||||||
|
@ -473,7 +489,7 @@ in {
|
||||||
set -q __fish_home_manager_config_sourced; and exit
|
set -q __fish_home_manager_config_sourced; and exit
|
||||||
set -g __fish_home_manager_config_sourced 1
|
set -g __fish_home_manager_config_sourced 1
|
||||||
|
|
||||||
source ${translatedSessionVariables}
|
source ${config.home.fishSessionVariablesPackage}/${profileDir}/${translatedSessionVarsFile}
|
||||||
|
|
||||||
${cfg.shellInit}
|
${cfg.shellInit}
|
||||||
|
|
||||||
|
|
|
@ -4,4 +4,5 @@
|
||||||
fish-functions = ./functions.nix;
|
fish-functions = ./functions.nix;
|
||||||
fish-no-functions = ./no-functions.nix;
|
fish-no-functions = ./no-functions.nix;
|
||||||
fish-plugins = ./plugins.nix;
|
fish-plugins = ./plugins.nix;
|
||||||
|
fish-session-variables = ./session-variables.nix;
|
||||||
}
|
}
|
||||||
|
|
26
tests/modules/programs/fish/session-variables.nix
Normal file
26
tests/modules/programs/fish/session-variables.nix
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
{
|
||||||
|
config = {
|
||||||
|
home.sessionVariables = {
|
||||||
|
V1 = "v1";
|
||||||
|
V2 = "v2-${config.home.sessionVariables.V1}";
|
||||||
|
};
|
||||||
|
|
||||||
|
programs.fish = {
|
||||||
|
enable = true;
|
||||||
|
|
||||||
|
# TODO: should there be an equivalent sessionVariables here like bash + zsh?
|
||||||
|
};
|
||||||
|
|
||||||
|
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'"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue