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.

Changed files
+6 -126
doc
nixos
lib
modules
services
computing
slurm
networking
ircd-hybrid
web-servers
jboss
pkgs
applications
audio
pianoteq
emulators
build-support
fetchbzr
fetchcvs
fetchdarcs
fetchdocker
fetchfirefoxaddon
fetchfossil
fetchgit
fetchhg
fetchipfs
fetchmtn
fetchsvn
fetchsvnssh
fetchurl
kernel
substitute
substitute-files
by-name
bo
boot
in
invidious
wt
xo
xorg_sys_opengl
ya
yandex-disk
development
bower-modules
generic
compilers
chicken
4
fetchegg
fpc
ios-cross-compile
libraries
glibc
gtk-sharp
perl-modules
generic
tools
misc
automake
os-specific
linux
nvidia-x11
servers
x11
xorg
stdenv
tools
+2 -10
doc/stdenv/stdenv.chapter.md
···
}
```
-
where the builder can do anything it wants, but typically starts with
-
-
```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:
+
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
-
source $stdenv/setup
-
buildPhase() {
echo "... this is my custom build phase ..."
gcc foo.c -o foo
···
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, there’s little benefit from mandating it be stable for any period of time.
-
First, let’s 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, let’s 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}
-2
nixos/lib/make-system-tarball.sh
···
-
source $stdenv/setup
-
sources_=($sources)
targets_=($targets)
-1
nixos/modules/services/computing/slurm/slurm.nix
···
name = "wrappedSlurm";
builder = pkgs.writeText "builder.sh" ''
-
source $stdenv/setup
mkdir -p $out/bin
find ${lib.getBin cfg.package}/bin -type f -executable | while read EXE
do
-3
nixos/modules/services/networking/ircd-hybrid/builder.sh
···
-
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
-
source $stdenv/setup
-
doSub() {
local src=$1
local dst=$2
-3
nixos/modules/services/web-servers/jboss/builder.sh
···
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
cat > $out/bin/control <<EOF
-2
pkgs/applications/audio/pianoteq/default.nix
···
stdenv.mkDerivation {
inherit name;
builder = writeShellScript "builder.sh" ''
-
source $stdenv/setup
-
curlVersion=$(${curl}/bin/curl -V | head -1 | cut -d' ' -f2)
# Curl flags to handle redirects, not use EPSV, handle cookies for
-2
pkgs/applications/emulators/wine/builder-wow.sh
···
## build described at https://wiki.winehq.org/Building_Wine#Shared_WoW64
-
-
source $stdenv/setup
preFlags="${configureFlags}"
unpackPhase
-3
pkgs/build-support/fetchbzr/builder.sh
···
-
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'"
# Perform a lightweight checkout so that we don't end up importing
-3
pkgs/build-support/fetchcvs/builder.sh
···
-
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 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$@"') > ssh
chmod +x ssh
-3
pkgs/build-support/fetchdarcs/builder.sh
···
-
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
-
source $stdenv/setup
-
tagtext=""
tagflags=""
# Darcs hashes are sha1 (120 bits, 40-character hex)
-2
pkgs/build-support/fetchdocker/fetchdocker-builder.sh
···
-
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}"
mkdir -p "${out}"
-1
pkgs/build-support/fetchdocker/generic-fetcher.nix
···
stdenv.mkDerivation {
inherit name;
builder = writeText "${fetcher}-builder.sh" ''
-
source "$stdenv/setup"
echo "${fetcher} exporting to $out"
declare -A creds
-2
pkgs/build-support/fetchfirefoxaddon/default.nix
···
};
builder = writeScript "xpibuilder" ''
-
source $stdenv/setup
-
echo "firefox addon $name into $out"
UUID="${extid}"
-2
pkgs/build-support/fetchfossil/builder.sh
···
-
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"
# Fossil, bless its adorable little heart, wants to write global configuration
-2
pkgs/build-support/fetchgit/builder.sh
···
# - revision specified and remote has a 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"
-2
pkgs/build-support/fetchhg/builder.sh
···
-
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"
hg clone --insecure "$url" hg-clone
-3
pkgs/build-support/fetchipfs/builder.sh
···
-
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
# servers to need them during redirects, and work on SSL without a
# certificate (this isn't a security problem because we check the
-3
pkgs/build-support/fetchmtn/builder.sh
···
-
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
-
source $stdenv/setup
-
set -x
if ! [ -f "$cacheDB" ]; then
-3
pkgs/build-support/fetchsvn/builder.sh
···
-
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"
if test -n "$http_proxy"; then
-3
pkgs/build-support/fetchsvnssh/builder.sh
···
-
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"
if test "$sshSupport"; then
-3
pkgs/build-support/fetchurl/builder.sh
···
-
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
-
source $stdenv/setup
-
source $mirrorsFile
curlVersion=$(curl -V | head -1 | cut -d' ' -f2)
-2
pkgs/build-support/fetchurl/write-mirror-list.sh
···
-
source $stdenv/setup
-
# !!! this is kinda hacky.
set | grep -E '^[a-zA-Z]+=.*://' > $out
-2
pkgs/build-support/kernel/make-initrd.sh
···
-
source $stdenv/setup
-
set -o pipefail
objects=($objects)
-2
pkgs/build-support/kernel/modules-closure.sh
···
-
source $stdenv/setup
-
# When no modules are built, the $out/lib/modules directory will not
# exist. Because the rest of the script assumes it does exist, we
# handle this special case first.
-1
pkgs/build-support/substitute-files/substitute-all-files.nix
···
stdenv.mkDerivation ({
name = if args ? name then args.name else baseNameOf (toString args.src);
builder = builtins.toFile "builder.sh" ''
-
source $stdenv/setup
set -o pipefail
eval "$preInstall"
-2
pkgs/build-support/substitute/substitute-all.sh
···
-
source $stdenv/setup
-
eval "$preInstall"
args=
-2
pkgs/build-support/substitute/substitute.sh
···
-
source $stdenv/setup
-
args=
target=$out
-3
pkgs/by-name/bo/boot/builder.sh
···
-
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
mkdir -pv $(dirname $boot_bin)
-2
pkgs/by-name/in/invidious/videojs.sh
···
-
source $stdenv/setup
-
unpackPhase
cd source
# this helper downloads the videojs files and checks their checksums
-3
pkgs/by-name/wt/wtk/builder.sh
···
-
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
-
source $stdenv/setup
-
mkdir unzipped
pushd unzipped
unzip $src || true
-3
pkgs/by-name/xo/xorg_sys_opengl/builder.sh
···
-
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
ln -s /usr/lib/libGL.so.1 $out/lib/
-1
pkgs/by-name/ya/yandex-disk/package.nix
···
};
builder = writeText "builder.sh" ''
-
. $stdenv/setup
mkdir -pv $out/bin
mkdir -pv $out/share
mkdir -pv $out/etc
-2
pkgs/development/bower-modules/generic/default.nix
···
inherit bowerPackages;
builder = builtins.toFile "builder.sh" ''
-
source $stdenv/setup
-
# The project's bower.json is required
cp $src/bower.json .
-3
pkgs/development/compilers/chicken/4/fetchegg/builder.sh
···
-
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"
mkdir -p $out
-3
pkgs/development/compilers/fpc/binary-builder-darwin.sh
···
-
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
deploydir=$(pwd)/deploy
-3
pkgs/development/compilers/fpc/binary-builder.sh
···
-
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
cd */
tarballdir=$(pwd)
-2
pkgs/development/compilers/ios-cross-compile/9.2_builder.sh
···
# -*- 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
{
-3
pkgs/development/libraries/glibc/locales-builder.sh
···
-
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.
export NIX_NO_SELF_RPATH=1
-
-
source $stdenv/setup
postConfigure() {
# Hack: get rid of the `-static' flag set by the bootstrap stdenv.
-3
pkgs/development/libraries/gtk-sharp/builder.sh
···
-
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
-
source $stdenv/setup
-
genericBuild
# !!! hack
-3
pkgs/development/perl-modules/generic/builder.sh
···
-
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"
perlFlags=
-3
pkgs/development/tools/misc/automake/builder.sh
···
-
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
# corresponding to the directories listed in $ACLOCAL_PATH. (Note
# that `wrapProgram' can't be used for that purpose since it can only
-3
pkgs/os-specific/linux/nvidia-x11/builder.sh
···
-
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
-
source $stdenv/setup
-
unpackManually() {
skip=$(sed 's/^skip=//; t; d' $src)
tail -n +$skip $src | bsdtar xvf -
-3
pkgs/servers/x11/xorg/builder.sh
···
-
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.
-
source $stdenv/setup
-
# After installation, automatically add all "Requires" fields in the
# pkgconfig files (*.pc) to the propagated build inputs.
-3
pkgs/stdenv/generic/default-builder.sh
···
-
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
-
-
source $stdenv/setup
genericBuild
+1 -1
pkgs/stdenv/generic/make-derivation.nix
···
);
}) // {
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;
# The `system` attribute of a derivation has special meaning to Nix.
+3
pkgs/stdenv/generic/source-stdenv.sh
···
+
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
+
source "$stdenv/setup"
+
source "$1"
-2
pkgs/tools/typesetting/tex/nix/animatedot.sh
···
-
source $stdenv/setup
-
mkdir -p $out
for ((i = 1; i <= $nrFrames; i++)); do
-2
pkgs/tools/typesetting/tex/nix/dot2pdf.sh
···
-
source $stdenv/setup
-
mkdir -p $out
dot2pdf() {
-2
pkgs/tools/typesetting/tex/nix/dot2ps.sh
···
-
source $stdenv/setup
-
mkdir -p $out
dot2ps() {
-2
pkgs/tools/typesetting/tex/nix/lhs2tex.sh
···
-
source $stdenv/setup
-
mkdir -p $out
mkdir root
-2
pkgs/tools/typesetting/tex/nix/run-latex.sh
···
-
source $stdenv/setup
-
mkdir -p $out
export VARTEXFONTS=$TMPDIR/texfonts