aboutsummaryrefslogtreecommitdiff
path: root/src/nix/get-env.sh
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-03-07 10:46:47 +0100
committereldritch horrors <pennae@lix.systems>2024-03-07 10:46:47 +0100
commit9eb58f5209f9cd1fd18f33b691c6a613075dffc4 (patch)
tree5cf7c86dd196f0f3b5a83d4c4cc962d2b8333349 /src/nix/get-env.sh
parentca03f7cc28ba09cb4db59ca51c52d4e7783f11e0 (diff)
Merge pull request #9032 from Ma27/structured-attrs-env-vars
structured attrs: improve support / usage of NIX_ATTRS_{SH,JSON}_FILE (cherry picked from commit 3c042f3b0b0a7ef9c47bf049f5410dbd4aac9e90) Change-Id: I7e41838338ee1edf31fff6f9e354c3db2bba6c0e
Diffstat (limited to 'src/nix/get-env.sh')
-rw-r--r--src/nix/get-env.sh20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/nix/get-env.sh b/src/nix/get-env.sh
index a7a8a01b9..832cc2f11 100644
--- a/src/nix/get-env.sh
+++ b/src/nix/get-env.sh
@@ -1,5 +1,5 @@
set -e
-if [ -e .attrs.sh ]; then source .attrs.sh; fi
+if [ -e "$NIX_ATTRS_SH_FILE" ]; then source "$NIX_ATTRS_SH_FILE"; fi
export IN_NIX_SHELL=impure
export dontAddDisableDepTrack=1
@@ -101,7 +101,21 @@ __dumpEnv() {
printf "}"
done < <(printf "%s\n" "$__vars")
- printf '\n }\n}'
+ printf '\n }'
+
+ if [ -e "$NIX_ATTRS_SH_FILE" ]; then
+ printf ',\n "structuredAttrs": {\n '
+ __escapeString ".attrs.sh"
+ printf ': '
+ __escapeString "$(<"$NIX_ATTRS_SH_FILE")"
+ printf ',\n '
+ __escapeString ".attrs.json"
+ printf ': '
+ __escapeString "$(<"$NIX_ATTRS_JSON_FILE")"
+ printf '\n }'
+ fi
+
+ printf '\n}'
}
__escapeString() {
@@ -117,7 +131,7 @@ __escapeString() {
# In case of `__structuredAttrs = true;` the list of outputs is an associative
# array with a format like `outname => /nix/store/hash-drvname-outname`, so `__olist`
# must contain the array's keys (hence `${!...[@]}`) in this case.
-if [ -e .attrs.sh ]; then
+if [ -e "$NIX_ATTRS_SH_FILE" ]; then
__olist="${!outputs[@]}"
else
__olist=$outputs