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-12-29 18:36:47 +01:00
parent c13f8abbe8
commit cf127c9dc3
51 changed files with 6 additions and 126 deletions
+2 -10
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
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() {
echo "... this is my custom build phase ..."
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.
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}
-2
View File
@@ -1,5 +1,3 @@
source $stdenv/setup
sources_=($sources)
targets_=($targets)
@@ -331,7 +331,6 @@ in
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
@@ -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() {
local src=$1
local dst=$2
@@ -1,8 +1,5 @@
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
@@ -111,8 +111,6 @@ let
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
@@ -1,6 +1,4 @@
## build described at https://wiki.winehq.org/Building_Wine#Shared_WoW64
source $stdenv/setup
preFlags="${configureFlags}"
unpackPhase
-3
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'"
# Perform a lightweight checkout so that we don't end up importing
-3
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 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$@"') > ssh
chmod +x ssh
-3
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=""
tagflags=""
# Darcs hashes are sha1 (120 bits, 40-character hex)
@@ -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}"
mkdir -p "${out}"
@@ -35,7 +35,6 @@ in
stdenv.mkDerivation {
inherit name;
builder = writeText "${fetcher}-builder.sh" ''
source "$stdenv/setup"
echo "${fetcher} exporting to $out"
declare -A creds
@@ -33,8 +33,6 @@ stdenv.mkDerivation {
};
builder = writeScript "xpibuilder" ''
source $stdenv/setup
echo "firefox addon $name into $out"
UUID="${extid}"
@@ -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"
# Fossil, bless its adorable little heart, wants to write global configuration
-2
View File
@@ -3,8 +3,6 @@
# - 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
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"
hg clone --insecure "$url" hg-clone
-3
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
# servers to need them during redirects, and work on SSL without a
# certificate (this isn't a security problem because we check the
-3
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
if ! [ -f "$cacheDB" ]; then
-3
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"
if test -n "$http_proxy"; then
@@ -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"
if test "$sshSupport"; then
-3
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
curlVersion=$(curl -V | head -1 | cut -d' ' -f2)
@@ -1,4 +1,2 @@
source $stdenv/setup
# !!! this is kinda hacky.
set | grep -E '^[a-zA-Z]+=.*://' > $out
-2
View File
@@ -1,5 +1,3 @@
source $stdenv/setup
set -o pipefail
objects=($objects)
@@ -1,5 +1,3 @@
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.
@@ -5,7 +5,6 @@ args:
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"
@@ -1,5 +1,3 @@
source $stdenv/setup
eval "$preInstall"
args=
@@ -1,5 +1,3 @@
source $stdenv/setup
args=
target=$out
-3
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
mkdir -pv $(dirname $boot_bin)
-2
View File
@@ -1,5 +1,3 @@
source $stdenv/setup
unpackPhase
cd source
# this helper downloads the videojs files and checks their checksums
-3
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
pushd unzipped
unzip $src || true
@@ -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
ln -s /usr/lib/libGL.so.1 $out/lib/
-1
View File
@@ -28,7 +28,6 @@ stdenv.mkDerivation rec {
};
builder = writeText "builder.sh" ''
. $stdenv/setup
mkdir -pv $out/bin
mkdir -pv $out/share
mkdir -pv $out/etc
@@ -18,8 +18,6 @@ in pkgs.stdenv.mkDerivation (
inherit bowerPackages;
builder = builtins.toFile "builder.sh" ''
source $stdenv/setup
# The project's bower.json is required
cp $src/bower.json .
@@ -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"
mkdir -p $out
@@ -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
deploydir=$(pwd)/deploy
@@ -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
cd */
tarballdir=$(pwd)
@@ -1,6 +1,4 @@
# -*- 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
{
@@ -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.
export NIX_NO_SELF_RPATH=1
source $stdenv/setup
postConfigure() {
# Hack: get rid of the `-static' flag set by the bootstrap stdenv.
# This has to be done *after* `configure' because it builds some
@@ -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
# !!! hack
@@ -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"
perlFlags=
@@ -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
# corresponding to the directories listed in $ACLOCAL_PATH. (Note
# that `wrapProgram' can't be used for that purpose since it can only
@@ -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() {
skip=$(sed 's/^skip=//; t; d' $src)
tail -n +$skip $src | bsdtar xvf -
-3
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.
source $stdenv/setup
# After installation, automatically add all "Requires" fields in the
# pkgconfig files (*.pc) to the propagated build inputs.
-3
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
+1 -1
View File
@@ -400,7 +400,7 @@ else let
);
}) // {
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
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"
@@ -1,5 +1,3 @@
source $stdenv/setup
mkdir -p $out
for ((i = 1; i <= $nrFrames; i++)); do
@@ -1,5 +1,3 @@
source $stdenv/setup
mkdir -p $out
dot2pdf() {
-2
View File
@@ -1,5 +1,3 @@
source $stdenv/setup
mkdir -p $out
dot2ps() {
@@ -1,5 +1,3 @@
source $stdenv/setup
mkdir -p $out
mkdir root
@@ -1,5 +1,3 @@
source $stdenv/setup
mkdir -p $out
export VARTEXFONTS=$TMPDIR/texfonts