Skip to content

Commit 8bc5104

Browse files
committed
treewide: refactor .attrs.sh detection
When specifying the `builder` attribute in `stdenv.mkDerivation`, this will be effectively transformed into builtins.derivation { builder = stdenv.shell; args = [ "-e" builder ]; } This also means that `default-builder.sh` is never sourced and as a result it's not guaranteed that `$NIX_ATTRS_SH_FILE` is set to a correct location[1]. Also, we need to source `.attrs.sh` to source `$stdenv`. So, the following is done now: * If `$NIX_ATTRS_SH_FILE` points to a correct location, then use it. Directly using `.attrs.sh` is problematic for `nix-shell(1)` usage (see previous commit for more context), so prefer the environment variable if possible. * Otherwise, if `.attrs.sh` exists, then use it. See [1] for when this can happen. * If neither applies, it can be assumed that `__structuredAttrs` is turned off and thus nothing needs to be done. [1] It's possible that it doesn't exist at all - in case of Nix 2.3 or it can point to a wrong location on older Nix versions with a bug in `__structuredAttrs`.
1 parent 53c5f08 commit 8bc5104

36 files changed

Lines changed: 36 additions & 38 deletions

File tree

nixos/modules/services/networking/ircd-hybrid/builder.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if [ -e .attrs.sh ]; then source .attrs.sh; fi
1+
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
22
source $stdenv/setup
33

44
doSub() {

nixos/modules/services/web-servers/jboss/builder.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
set -e
22

3-
if [ -e .attrs.sh ]; then source .attrs.sh; fi
3+
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
44
source $stdenv/setup
55

66
mkdir -p $out/bin

pkgs/applications/misc/adobe-reader/builder.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if [ -e .attrs.sh ]; then source .attrs.sh; fi
1+
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
22
source $stdenv/setup
33

44
echo "unpacking $src..."

pkgs/build-support/fetchbzr/builder.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if [ -e .attrs.sh ]; then source .attrs.sh; fi
1+
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
22
source "$stdenv/setup"
33

44
echo "exporting \`$url' (revision $rev) into \`$out'"

pkgs/build-support/fetchcvs/builder.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if [ -e .attrs.sh ]; then source .attrs.sh; fi
1+
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
22
source $stdenv/setup
33

44
(echo "#!$SHELL"; \

pkgs/build-support/fetchdarcs/builder.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if [ -e .attrs.sh ]; then source .attrs.sh; fi
1+
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
22
source $stdenv/setup
33

44
tagtext=""

pkgs/build-support/fetchdocker/fetchdocker-builder.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if [ -e .attrs.sh ]; then source .attrs.sh; fi
1+
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
22
source "${stdenv}/setup"
33
echo "exporting ${repository}/${imageName} (tag: ${tag}) into ${out}"
44
mkdir -p "${out}"

pkgs/build-support/fetchfossil/builder.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if [ -e .attrs.sh ]; then source .attrs.sh; fi
1+
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
22
source $stdenv/setup
33
echo "Cloning Fossil $url [$rev] into $out"
44

pkgs/build-support/fetchgit/builder.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# - revision specified and remote has a HEAD
44
# - revision specified and remote without HEAD
55
#
6-
if [ -e .attrs.sh ]; then source .attrs.sh; fi
6+
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
77
source $stdenv/setup
88

99
echo "exporting $url (rev $rev) into $out"

pkgs/build-support/fetchhg/builder.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if [ -e .attrs.sh ]; then source .attrs.sh; fi
1+
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
22
source $stdenv/setup
33
echo "getting $url${rev:+ ($rev)} into $out"
44

0 commit comments

Comments
 (0)