diff options
author | Naïm Favier <n@monade.li> | 2022-05-07 13:37:03 +0200 |
---|---|---|
committer | Naïm Favier <n@monade.li> | 2022-05-07 17:01:51 +0200 |
commit | 4d2ea62d8211be13575d62c6d1aa3858bf5c90e1 (patch) | |
tree | 85bc7a57c10298c4a8a63dcbcad5a0801d4290c4 /lib/strings.nix | |
parent | 7dbfd6b9970c0bd939072f2f4e972e72fc70302a (diff) |
lib/strings/toShellVars: handle derivations as strings
Diffstat (limited to 'lib/strings.nix')
-rw-r--r-- | lib/strings.nix | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/strings.nix b/lib/strings.nix index 328f64cf1b61d..295d98900e994 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -339,9 +339,10 @@ rec { /* Translate a Nix value into a shell variable declaration, with proper escaping. - Supported value types are strings (mapped to regular variables), lists of strings - (mapped to Bash-style arrays) and attribute sets of strings (mapped to Bash-style - associative arrays). Note that "strings" include string-coercible values like paths. + The value can be a string (mapped to a regular variable), a list of strings + (mapped to a Bash-style array) or an attribute set of strings (mapped to a + Bash-style associative array). Note that "string" includes string-coercible + values like paths or derivations. Strings are translated into POSIX sh-compatible code; lists and attribute sets assume a shell that understands Bash syntax (e.g. Bash or ZSH). @@ -356,7 +357,7 @@ rec { */ toShellVar = name: value: lib.throwIfNot (isValidPosixName name) "toShellVar: ${name} is not a valid shell variable name" ( - if isAttrs value then + if isAttrs value && ! isCoercibleToString value then "declare -A ${name}=(${ concatStringsSep " " (lib.mapAttrsToList (n: v: "[${escapeShellArg n}]=${escapeShellArg v}" |