treewide: load structured attributes in all bash builders consistently

It's hard to put the sourcing of ./.attrs.sh into all builder
consistently - mistakes will happen. Thus, load structured attrs once in
make-derivation and then source the remaining builder on top.

This should fix quite a few builders with structured attributes in
principle. Most importantly it helps substitute / substituteAll, which
are required for bootstrap on some platforms.
This commit is contained in:
Wolfgang Walther 2024-11-17 20:32:35 +01:00
parent c13f8abbe8
commit cf127c9dc3
No known key found for this signature in database
GPG key ID: B39893FA5F65CAE1
51 changed files with 6 additions and 126 deletions

View file

@ -75,17 +75,9 @@ stdenv.mkDerivation {
} }
``` ```
where the builder can do anything it wants, but typically starts with where `stdenv` sets up the environment automatically (e.g. by resetting `PATH` and populating it from build inputs). If you want, you can use `stdenv`s generic builder:
```bash ```bash
source $stdenv/setup
```
to let `stdenv` set up the environment (e.g. by resetting `PATH` and populating it from build inputs). If you want, you can still use `stdenv`s generic builder:
```bash
source $stdenv/setup
buildPhase() { buildPhase() {
echo "... this is my custom build phase ..." echo "... this is my custom build phase ..."
gcc foo.c -o foo gcc foo.c -o foo
@ -1276,7 +1268,7 @@ addEnvHooks "$hostOffset" myBashFunction
The *existence* of setups hooks has long been documented and packages inside Nixpkgs are free to use this mechanism. Other packages, however, should not rely on these mechanisms not changing between Nixpkgs versions. Because of the existing issues with this system, theres little benefit from mandating it be stable for any period of time. The *existence* of setups hooks has long been documented and packages inside Nixpkgs are free to use this mechanism. Other packages, however, should not rely on these mechanisms not changing between Nixpkgs versions. Because of the existing issues with this system, theres little benefit from mandating it be stable for any period of time.
First, lets cover some setup hooks that are part of Nixpkgs default `stdenv`. This means that they are run for every package built using `stdenv.mkDerivation` or when using a custom builder that has `source $stdenv/setup`. Some of these are platform specific, so they may run on Linux but not Darwin or vice-versa. First, lets cover some setup hooks that are part of Nixpkgs default `stdenv`. This means that they are run for every package built using `stdenv.mkDerivation`, even with custom builders. Some of these are platform specific, so they may run on Linux but not Darwin or vice-versa.
### `move-docs.sh` {#move-docs.sh} ### `move-docs.sh` {#move-docs.sh}

View file

@ -1,5 +1,3 @@
source $stdenv/setup
sources_=($sources) sources_=($sources)
targets_=($targets) targets_=($targets)

View file

@ -331,7 +331,6 @@ in
name = "wrappedSlurm"; name = "wrappedSlurm";
builder = pkgs.writeText "builder.sh" '' builder = pkgs.writeText "builder.sh" ''
source $stdenv/setup
mkdir -p $out/bin mkdir -p $out/bin
find ${lib.getBin cfg.package}/bin -type f -executable | while read EXE find ${lib.getBin cfg.package}/bin -type f -executable | while read EXE
do do

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
doSub() { doSub() {
local src=$1 local src=$1
local dst=$2 local dst=$2

View file

@ -1,8 +1,5 @@
set -e set -e
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
mkdir -p $out/bin mkdir -p $out/bin
cat > $out/bin/control <<EOF cat > $out/bin/control <<EOF

View file

@ -111,8 +111,6 @@ let
stdenv.mkDerivation { stdenv.mkDerivation {
inherit name; inherit name;
builder = writeShellScript "builder.sh" '' builder = writeShellScript "builder.sh" ''
source $stdenv/setup
curlVersion=$(${curl}/bin/curl -V | head -1 | cut -d' ' -f2) curlVersion=$(${curl}/bin/curl -V | head -1 | cut -d' ' -f2)
# Curl flags to handle redirects, not use EPSV, handle cookies for # Curl flags to handle redirects, not use EPSV, handle cookies for

View file

@ -1,6 +1,4 @@
## build described at https://wiki.winehq.org/Building_Wine#Shared_WoW64 ## build described at https://wiki.winehq.org/Building_Wine#Shared_WoW64
source $stdenv/setup
preFlags="${configureFlags}" preFlags="${configureFlags}"
unpackPhase unpackPhase

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source "$stdenv/setup"
echo "exporting \`$url' (revision $rev) into \`$out'" echo "exporting \`$url' (revision $rev) into \`$out'"
# Perform a lightweight checkout so that we don't end up importing # Perform a lightweight checkout so that we don't end up importing

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
(echo "#!$SHELL"; \ (echo "#!$SHELL"; \
echo 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$@"') > ssh echo 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$@"') > ssh
chmod +x ssh chmod +x ssh

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
tagtext="" tagtext=""
tagflags="" tagflags=""
# Darcs hashes are sha1 (120 bits, 40-character hex) # Darcs hashes are sha1 (120 bits, 40-character hex)

View file

@ -1,5 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source "${stdenv}/setup"
echo "exporting ${repository}/${imageName} (tag: ${tag}) into ${out}" echo "exporting ${repository}/${imageName} (tag: ${tag}) into ${out}"
mkdir -p "${out}" mkdir -p "${out}"

View file

@ -35,7 +35,6 @@ in
stdenv.mkDerivation { stdenv.mkDerivation {
inherit name; inherit name;
builder = writeText "${fetcher}-builder.sh" '' builder = writeText "${fetcher}-builder.sh" ''
source "$stdenv/setup"
echo "${fetcher} exporting to $out" echo "${fetcher} exporting to $out"
declare -A creds declare -A creds

View file

@ -33,8 +33,6 @@ stdenv.mkDerivation {
}; };
builder = writeScript "xpibuilder" '' builder = writeScript "xpibuilder" ''
source $stdenv/setup
echo "firefox addon $name into $out" echo "firefox addon $name into $out"
UUID="${extid}" UUID="${extid}"

View file

@ -1,5 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
echo "Cloning Fossil $url [$rev] into $out" echo "Cloning Fossil $url [$rev] into $out"
# Fossil, bless its adorable little heart, wants to write global configuration # Fossil, bless its adorable little heart, wants to write global configuration

View file

@ -3,8 +3,6 @@
# - revision specified and remote has a HEAD # - revision specified and remote has a HEAD
# - revision specified and remote without HEAD # - revision specified and remote without HEAD
# #
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
echo "exporting $url (rev $rev) into $out" echo "exporting $url (rev $rev) into $out"

View file

@ -1,5 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
echo "getting $url${rev:+ ($rev)} into $out" echo "getting $url${rev:+ ($rev)} into $out"
hg clone --insecure "$url" hg-clone hg clone --insecure "$url" hg-clone

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
# Curl flags to handle redirects, not use EPSV, handle cookies for # Curl flags to handle redirects, not use EPSV, handle cookies for
# servers to need them during redirects, and work on SSL without a # servers to need them during redirects, and work on SSL without a
# certificate (this isn't a security problem because we check the # certificate (this isn't a security problem because we check the

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
set -x set -x
if ! [ -f "$cacheDB" ]; then if ! [ -f "$cacheDB" ]; then

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
echo "exporting $url (r$rev) into $out" echo "exporting $url (r$rev) into $out"
if test -n "$http_proxy"; then if test -n "$http_proxy"; then

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
echo "exporting $url (r$rev) into $out" echo "exporting $url (r$rev) into $out"
if test "$sshSupport"; then if test "$sshSupport"; then

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
source $mirrorsFile source $mirrorsFile
curlVersion=$(curl -V | head -1 | cut -d' ' -f2) curlVersion=$(curl -V | head -1 | cut -d' ' -f2)

View file

@ -1,4 +1,2 @@
source $stdenv/setup
# !!! this is kinda hacky. # !!! this is kinda hacky.
set | grep -E '^[a-zA-Z]+=.*://' > $out set | grep -E '^[a-zA-Z]+=.*://' > $out

View file

@ -1,5 +1,3 @@
source $stdenv/setup
set -o pipefail set -o pipefail
objects=($objects) objects=($objects)

View file

@ -1,5 +1,3 @@
source $stdenv/setup
# When no modules are built, the $out/lib/modules directory will not # When no modules are built, the $out/lib/modules directory will not
# exist. Because the rest of the script assumes it does exist, we # exist. Because the rest of the script assumes it does exist, we
# handle this special case first. # handle this special case first.

View file

@ -5,7 +5,6 @@ args:
stdenv.mkDerivation ({ stdenv.mkDerivation ({
name = if args ? name then args.name else baseNameOf (toString args.src); name = if args ? name then args.name else baseNameOf (toString args.src);
builder = builtins.toFile "builder.sh" '' builder = builtins.toFile "builder.sh" ''
source $stdenv/setup
set -o pipefail set -o pipefail
eval "$preInstall" eval "$preInstall"

View file

@ -1,5 +1,3 @@
source $stdenv/setup
eval "$preInstall" eval "$preInstall"
args= args=

View file

@ -1,5 +1,3 @@
source $stdenv/setup
args= args=
target=$out target=$out

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
boot_bin=$out/bin/boot boot_bin=$out/bin/boot
mkdir -pv $(dirname $boot_bin) mkdir -pv $(dirname $boot_bin)

View file

@ -1,5 +1,3 @@
source $stdenv/setup
unpackPhase unpackPhase
cd source cd source
# this helper downloads the videojs files and checks their checksums # this helper downloads the videojs files and checks their checksums

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
mkdir unzipped mkdir unzipped
pushd unzipped pushd unzipped
unzip $src || true unzip $src || true

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
mkdir -p $out/lib mkdir -p $out/lib
ln -s /usr/lib/libGL.so.1 $out/lib/ ln -s /usr/lib/libGL.so.1 $out/lib/

View file

@ -28,7 +28,6 @@ stdenv.mkDerivation rec {
}; };
builder = writeText "builder.sh" '' builder = writeText "builder.sh" ''
. $stdenv/setup
mkdir -pv $out/bin mkdir -pv $out/bin
mkdir -pv $out/share mkdir -pv $out/share
mkdir -pv $out/etc mkdir -pv $out/etc

View file

@ -18,8 +18,6 @@ in pkgs.stdenv.mkDerivation (
inherit bowerPackages; inherit bowerPackages;
builder = builtins.toFile "builder.sh" '' builder = builtins.toFile "builder.sh" ''
source $stdenv/setup
# The project's bower.json is required # The project's bower.json is required
cp $src/bower.json . cp $src/bower.json .

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
echo "exporting egg ${eggName} (version $version) into $out" echo "exporting egg ${eggName} (version $version) into $out"
mkdir -p $out mkdir -p $out

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
pkgdir=$(pwd)/pkg pkgdir=$(pwd)/pkg
deploydir=$(pwd)/deploy deploydir=$(pwd)/deploy

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
tar xf $src tar xf $src
cd */ cd */
tarballdir=$(pwd) tarballdir=$(pwd)

View file

@ -1,6 +1,4 @@
# -*- shell-script -*- # -*- shell-script -*-
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
function extract function extract
{ {

View file

@ -1,9 +1,6 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
# Glibc cannot have itself in its RPATH. # Glibc cannot have itself in its RPATH.
export NIX_NO_SELF_RPATH=1 export NIX_NO_SELF_RPATH=1
source $stdenv/setup
postConfigure() { postConfigure() {
# Hack: get rid of the `-static' flag set by the bootstrap stdenv. # Hack: get rid of the `-static' flag set by the bootstrap stdenv.
# This has to be done *after* `configure' because it builds some # This has to be done *after* `configure' because it builds some

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
genericBuild genericBuild
# !!! hack # !!! hack

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
PERL5LIB="$PERL5LIB${PERL5LIB:+:}$out/lib/perl5/site_perl" PERL5LIB="$PERL5LIB${PERL5LIB:+:}$out/lib/perl5/site_perl"
perlFlags= perlFlags=

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
# Wrap the given `aclocal' program, appending extra `-I' flags # Wrap the given `aclocal' program, appending extra `-I' flags
# corresponding to the directories listed in $ACLOCAL_PATH. (Note # corresponding to the directories listed in $ACLOCAL_PATH. (Note
# that `wrapProgram' can't be used for that purpose since it can only # that `wrapProgram' can't be used for that purpose since it can only

View file

@ -1,6 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
unpackManually() { unpackManually() {
skip=$(sed 's/^skip=//; t; d' $src) skip=$(sed 's/^skip=//; t; d' $src)
tail -n +$skip $src | bsdtar xvf - tail -n +$skip $src | bsdtar xvf -

View file

@ -1,7 +1,4 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
# This is the builder for all X.org components. # This is the builder for all X.org components.
source $stdenv/setup
# After installation, automatically add all "Requires" fields in the # After installation, automatically add all "Requires" fields in the
# pkgconfig files (*.pc) to the propagated build inputs. # pkgconfig files (*.pc) to the propagated build inputs.

View file

@ -1,4 +1 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
genericBuild genericBuild

View file

@ -400,7 +400,7 @@ else let
); );
}) // { }) // {
builder = attrs.realBuilder or stdenv.shell; builder = attrs.realBuilder or stdenv.shell;
args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)]; args = attrs.args or ["-e" ./source-stdenv.sh (attrs.builder or ./default-builder.sh)];
inherit stdenv; inherit stdenv;
# The `system` attribute of a derivation has special meaning to Nix. # The `system` attribute of a derivation has special meaning to Nix.

View file

@ -0,0 +1,3 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source "$stdenv/setup"
source "$1"

View file

@ -1,5 +1,3 @@
source $stdenv/setup
mkdir -p $out mkdir -p $out
for ((i = 1; i <= $nrFrames; i++)); do for ((i = 1; i <= $nrFrames; i++)); do

View file

@ -1,5 +1,3 @@
source $stdenv/setup
mkdir -p $out mkdir -p $out
dot2pdf() { dot2pdf() {

View file

@ -1,5 +1,3 @@
source $stdenv/setup
mkdir -p $out mkdir -p $out
dot2ps() { dot2ps() {

View file

@ -1,5 +1,3 @@
source $stdenv/setup
mkdir -p $out mkdir -p $out
mkdir root mkdir root

View file

@ -1,5 +1,3 @@
source $stdenv/setup
mkdir -p $out mkdir -p $out
export VARTEXFONTS=$TMPDIR/texfonts export VARTEXFONTS=$TMPDIR/texfonts