fish: isolated sourcePaths configuration

This commit is contained in:
Primrose 2024-11-16 01:01:26 +01:00
parent 72c44a183d
commit 29eb64a321
Signed by: primrose
GPG key ID: 4E887A4CA9714ADA
2 changed files with 95 additions and 88 deletions

View file

@ -0,0 +1,31 @@
{ config, lib, ... }:
{
options.programs.fish.sourcePaths = lib.mkOption {
type = with lib.types; nonEmptyListOf str;
description = ''
Paths to be sourced idempotently at the start of a login-shell.
'';
};
# We need to handle path idempotently, because fish in home-manager is
# unable to depend on nixos/nix-darwin configurations to figure out the profile.d/nix.sh
# to source.
#
# The hack is to make terminal emulators run fish as a login shell
# whenever fish should handle the path.
# tmux should NOT call fish as a login shell, because it would inherit the
# environment variables from its parent shell, which is a login shell.
config.programs.fish.loginShellInit = ''
begin
set ps ${builtins.concatStringsSep " " config.programs.fish.sourcePaths}
set -e fish_user_paths
for p in $ps
test -d $p && set --append fish_user_paths $p
end
end
'';
}