mirror of
https://github.com/nix-community/home-manager.git
synced 2026-06-05 21:02:51 +00:00
{home-environment,bash,zsh}: support ignoring null sessionVariables
Some applications consider environment variables to be “true” simply if they are set. Previously it was not possible to have a var set and later override (e.g. with `lib.mkForce`) to *unset* it. This makes that possible. The filtering must be done in the `exportAll` as attempting to do it in the option’s `apply` causing infinite recursion (likely why it is `lazyAttrsOf`).
This commit is contained in:
committed by
Austin Horstman
parent
62f445c13c
commit
d45a13f96c
@@ -266,12 +266,14 @@ in
|
||||
default = { };
|
||||
type =
|
||||
with types;
|
||||
lazyAttrsOf (oneOf [
|
||||
str
|
||||
path
|
||||
int
|
||||
float
|
||||
]);
|
||||
lazyAttrsOf (
|
||||
nullOr (oneOf [
|
||||
str
|
||||
path
|
||||
int
|
||||
float
|
||||
])
|
||||
);
|
||||
example = {
|
||||
EDITOR = "emacs";
|
||||
GS_OPTIONS = "-sPAPERSIZE=a4";
|
||||
@@ -307,6 +309,9 @@ in
|
||||
BAR = "''${config.home.sessionVariables.FOO} World!";
|
||||
};
|
||||
```
|
||||
|
||||
Setting a value to `null` will skip setting the variable at all, which
|
||||
may be useful when overriding.
|
||||
'';
|
||||
};
|
||||
|
||||
|
||||
@@ -69,7 +69,9 @@ in
|
||||
# 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);
|
||||
exportAll =
|
||||
vars:
|
||||
lib.concatStringsSep "\n" (lib.mapAttrsToList export (lib.filterAttrs (_k: v: v != null) vars));
|
||||
|
||||
# Formats a list of items for shell array content with intelligent width optimization.
|
||||
# IMPORTANT: This formats the CONTENTS of an array (what goes inside parentheses),
|
||||
|
||||
@@ -38,5 +38,7 @@ rec {
|
||||
let
|
||||
separator = if indent == "" then "\n" else "\n" + indent;
|
||||
in
|
||||
lib.concatStringsSep separator (lib.mapAttrsToList export vars);
|
||||
lib.concatStringsSep separator (
|
||||
lib.mapAttrsToList export (lib.filterAttrs (_k: v: v != null) vars)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -135,17 +135,22 @@ in
|
||||
default = { };
|
||||
type =
|
||||
with types;
|
||||
lazyAttrsOf (oneOf [
|
||||
str
|
||||
path
|
||||
int
|
||||
float
|
||||
]);
|
||||
lazyAttrsOf (
|
||||
nullOr (oneOf [
|
||||
str
|
||||
path
|
||||
int
|
||||
float
|
||||
])
|
||||
);
|
||||
example = {
|
||||
MAILCHECK = 30;
|
||||
};
|
||||
description = ''
|
||||
Environment variables that will be set for the Bash session.
|
||||
|
||||
Setting a value to `null` will skip setting the variable at all, which
|
||||
may be useful when overriding.
|
||||
'';
|
||||
};
|
||||
|
||||
|
||||
@@ -249,16 +249,23 @@ in
|
||||
default = { };
|
||||
type =
|
||||
with types;
|
||||
lazyAttrsOf (oneOf [
|
||||
str
|
||||
path
|
||||
int
|
||||
float
|
||||
]);
|
||||
lazyAttrsOf (
|
||||
nullOr (oneOf [
|
||||
str
|
||||
path
|
||||
int
|
||||
float
|
||||
])
|
||||
);
|
||||
example = {
|
||||
MAILCHECK = 30;
|
||||
};
|
||||
description = "Environment variables that will be set for zsh session.";
|
||||
description = ''
|
||||
Environment variables that will be set for zsh session.
|
||||
|
||||
Setting a value to `null` will skip setting the variable at all, which
|
||||
may be useful when overriding.
|
||||
'';
|
||||
};
|
||||
|
||||
initContent = mkOption {
|
||||
|
||||
@@ -9,6 +9,7 @@ let
|
||||
if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
|
||||
export __HM_SESS_VARS_SOURCED=1
|
||||
|
||||
export IS_EMPTY=""
|
||||
export LOCALE_ARCHIVE_2_27="${config.i18n.glibcLocales}/lib/locale/locale-archive"
|
||||
export V1="v1"
|
||||
export V2="v2-v1"
|
||||
@@ -25,6 +26,7 @@ let
|
||||
if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
|
||||
export __HM_SESS_VARS_SOURCED=1
|
||||
|
||||
export IS_EMPTY=""
|
||||
export TERMINFO_DIRS="/home/hm-user/.nix-profile/share/terminfo:$TERMINFO_DIRS''${TERMINFO_DIRS:+:}/usr/share/terminfo"
|
||||
export V1="v1"
|
||||
export V2="v2-v1"
|
||||
@@ -45,6 +47,8 @@ in
|
||||
home.sessionVariables = {
|
||||
V1 = "v1";
|
||||
V2 = "v2-${config.home.sessionVariables.V1}";
|
||||
IS_EMPTY = "";
|
||||
IS_NULL = null;
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
sessionVariables = {
|
||||
V1 = "v1";
|
||||
V2 = "v2-${config.programs.bash.sessionVariables.V1}";
|
||||
IS_EMPTY = "";
|
||||
IS_NULL = null;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -18,6 +20,7 @@
|
||||
${builtins.toFile "session-variables-expected" ''
|
||||
. "/nix/store/00000000000000000000000000000000-hm-session-vars.sh/etc/profile.d/hm-session-vars.sh"
|
||||
|
||||
export IS_EMPTY=""
|
||||
export V1="v1"
|
||||
export V2="v2-v1"
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
PATH = "$HOME/bin:$PATH";
|
||||
V1 = "v1";
|
||||
V2 = "v2-${config.programs.zsh.sessionVariables.V1}";
|
||||
IS_EMPTY = "";
|
||||
IS_NULL = null;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
# Only source this once
|
||||
if [[ -z "$__HM_ZSH_SESS_VARS_SOURCED" ]]; then
|
||||
export __HM_ZSH_SESS_VARS_SOURCED=1
|
||||
export IS_EMPTY=""
|
||||
export PATH="$HOME/bin:$PATH"
|
||||
export V1="v1"
|
||||
export V2="v2-v1"
|
||||
|
||||
Reference in New Issue
Block a user