1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-03-18 14:28:15 +00:00
home-manager/modules/lib/shell.nix
Thiago Kenji Okada 277eea1cc7 home-environment: add home.sessionSearchVariables
This commit introduces `home.sessionSearchVariables` option, that is
created to be a "generic" version of `home.sessionPath` for any
environment variables that is similar to PATH (e.g.: MANPATH). This
allows composition of those variables between multiple modules, avoiding
issues like this one:

https://github.com/nix-community/home-manager/pull/4579/files#r1364374048

This commit also reimplements `home.sessionPath` as terms of
`home.sessionSearchVariables`, to reduce code duplication and show that
the code is correct.

The behavior is to prepend the new search paths. This will allow
the user to override the defaults easily by setting it later in the
configuration.
2025-03-09 09:36:41 -05:00

41 lines
1.5 KiB
Nix

{ lib }:
let
mkShellIntegrationOption = name:
{ config, baseName ? name, extraDescription ? "" }:
let attrName = "enable${baseName}Integration";
in lib.mkOption {
default = config.home.shell.${attrName};
defaultText = lib.literalMD "[](#opt-home.shell.${attrName})";
example = false;
description = "Whether to enable ${name} integration.${
lib.optionalString (extraDescription != "")
("\n\n" + extraDescription)
}";
type = lib.types.bool;
};
in rec {
# Produces a Bourne shell like statement that prepend new values to
# an possibly existing variable, using sep(arator).
# Example:
# prependToVar ":" "PATH" [ "$HOME/bin" "$HOME/.local/bin" ]
# => "$HOME/bin:$HOME/.local/bin:${PATH:+:}\$PATH"
prependToVar = sep: n: v:
"${lib.concatStringsSep sep v}\${${n}:+${sep}}\$${n}";
# Produces a Bourne shell like variable export statement.
export = n: v: ''export ${n}="${toString v}"'';
# Given an attribute set containing shell variable names and their
# assignment, this function produces a string containing an export
# statement for each set entry.
exportAll = vars: lib.concatStringsSep "\n" (lib.mapAttrsToList export vars);
mkBashIntegrationOption = mkShellIntegrationOption "Bash";
mkFishIntegrationOption = mkShellIntegrationOption "Fish";
mkIonIntegrationOption = mkShellIntegrationOption "Ion";
mkNushellIntegrationOption = mkShellIntegrationOption "Nushell";
mkZshIntegrationOption = mkShellIntegrationOption "Zsh";
}