Skip to content

Commit

Permalink
treewide: load structured attributes in all bash builders consistently
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wolfgangwalther committed Nov 18, 2024
1 parent 7b1064c commit 4e583b2
Show file tree
Hide file tree
Showing 51 changed files with 8 additions and 117 deletions.
2 changes: 0 additions & 2 deletions pkgs/applications/audio/pianoteq/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pkgs/applications/emulators/wine/builder-wow.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
## build described at https://wiki.winehq.org/Building_Wine#Shared_WoW64

source $stdenv/setup
preFlags="${configureFlags}"

unpackPhase
Expand Down
3 changes: 0 additions & 3 deletions pkgs/applications/misc/adobe-reader/builder.sh
Original file line number Diff line number Diff line change
@@ -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 "unpacking $src..."
tar xvfa $src

Expand Down
2 changes: 0 additions & 2 deletions pkgs/build-support/docker/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,6 @@ rec {
mkdir $out
${if enableFakechroot then ''
proot -r $PWD/old_out ${bind-paths} --pwd=/ fakeroot bash -c '
source $stdenv/setup
eval "$fakeRootCommands"
tar \
--sort name \
Expand All @@ -983,7 +982,6 @@ rec {
'
'' else ''
fakeroot bash -c '
source $stdenv/setup
cd old_out
eval "$fakeRootCommands"
tar \
Expand Down
3 changes: 0 additions & 3 deletions pkgs/build-support/fetchbzr/builder.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions pkgs/build-support/fetchcvs/builder.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions pkgs/build-support/fetchdarcs/builder.sh
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 0 additions & 2 deletions pkgs/build-support/fetchdocker/fetchdocker-builder.sh
Original file line number Diff line number Diff line change
@@ -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}"

Expand Down
1 change: 0 additions & 1 deletion pkgs/build-support/fetchdocker/generic-fetcher.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pkgs/build-support/fetchfirefoxaddon/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ stdenv.mkDerivation {
};

builder = writeScript "xpibuilder" ''
source $stdenv/setup
echo "firefox addon $name into $out"
UUID="${extid}"
Expand Down
2 changes: 0 additions & 2 deletions pkgs/build-support/fetchfossil/builder.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 0 additions & 2 deletions pkgs/build-support/fetchgit/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 0 additions & 2 deletions pkgs/build-support/fetchhg/builder.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions pkgs/build-support/fetchipfs/builder.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions pkgs/build-support/fetchmtn/builder.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions pkgs/build-support/fetchsvn/builder.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions pkgs/build-support/fetchsvnssh/builder.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions pkgs/build-support/fetchurl/builder.sh
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 0 additions & 2 deletions pkgs/build-support/fetchurl/write-mirror-list.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
source $stdenv/setup

# !!! this is kinda hacky.
set | grep -E '^[a-zA-Z]+=.*://' > $out
2 changes: 0 additions & 2 deletions pkgs/build-support/kernel/make-initrd.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
source $stdenv/setup

set -o pipefail

objects=($objects)
Expand Down
2 changes: 0 additions & 2 deletions pkgs/build-support/kernel/modules-closure.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions pkgs/build-support/substitute/substitute-all.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
source $stdenv/setup

eval "$preInstall"

args=
Expand Down
2 changes: 0 additions & 2 deletions pkgs/build-support/substitute/substitute.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
source $stdenv/setup

args=

target=$out
Expand Down
3 changes: 0 additions & 3 deletions pkgs/by-name/bo/boot/builder.sh
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 0 additions & 2 deletions pkgs/by-name/in/invidious/videojs.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
source $stdenv/setup

unpackPhase
cd source
# this helper downloads the videojs files and checks their checksums
Expand Down
1 change: 0 additions & 1 deletion pkgs/by-name/k2/k2pdfopt/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
let
# Create a patch against src based on changes applied in patchCommands
mkPatch = { name, src, patchCommands }: runCommand "${name}-k2pdfopt.patch" { inherit src; } ''
source $stdenv/setup
unpackPhase
orig=$sourceRoot
Expand Down
3 changes: 0 additions & 3 deletions pkgs/by-name/wt/wtk/builder.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions pkgs/by-name/xo/xorg_sys_opengl/builder.sh
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
2 changes: 0 additions & 2 deletions pkgs/by-name/xq/xquartz/system-fonts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ stdenv.mkDerivation {
xorg.mkfontdir xorg.mkfontscale
];
buildCommand = ''
source $stdenv/setup
for i in ${toString fontDirs} ; do
if [ -d $i/ ]; then
list="$list $i";
Expand Down
1 change: 0 additions & 1 deletion pkgs/by-name/ya/yandex-disk/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pkgs/development/bower-modules/generic/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
3 changes: 0 additions & 3 deletions pkgs/development/compilers/chicken/4/fetchegg/builder.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions pkgs/development/compilers/fpc/binary-builder-darwin.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 0 additions & 3 deletions pkgs/development/compilers/fpc/binary-builder.sh
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 0 additions & 2 deletions pkgs/development/compilers/fpc/remove-signature.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
source $stdenv/setup

codesign_allocate -r -i "$1" -o "$1"
2 changes: 0 additions & 2 deletions pkgs/development/compilers/ios-cross-compile/9.2_builder.sh
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
3 changes: 0 additions & 3 deletions pkgs/development/libraries/glibc/locales-builder.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions pkgs/development/libraries/gtk-sharp/builder.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions pkgs/development/perl-modules/generic/builder.sh
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
3 changes: 0 additions & 3 deletions pkgs/development/tools/misc/automake/builder.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 0 additions & 3 deletions pkgs/os-specific/linux/nvidia-x11/builder.sh
Original file line number Diff line number Diff line change
@@ -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 -
Expand Down
3 changes: 0 additions & 3 deletions pkgs/servers/x11/xorg/builder.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 0 additions & 3 deletions pkgs/stdenv/generic/default-builder.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion pkgs/stdenv/generic/make-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,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.
Expand Down
7 changes: 7 additions & 0 deletions pkgs/stdenv/generic/source-stdenv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if [ -e "$NIX_ATTRS_SH_FILE" ]; then
source "$NIX_ATTRS_SH_FILE";
elif [ -f .attrs.sh ]; then
source ./attrs.sh;
fi
source "$stdenv/setup"
source "$1"
2 changes: 0 additions & 2 deletions pkgs/tools/typesetting/tex/nix/animatedot.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
source $stdenv/setup

mkdir -p $out

for ((i = 1; i <= $nrFrames; i++)); do
Expand Down
2 changes: 0 additions & 2 deletions pkgs/tools/typesetting/tex/nix/dot2pdf.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
source $stdenv/setup

mkdir -p $out

dot2pdf() {
Expand Down
2 changes: 0 additions & 2 deletions pkgs/tools/typesetting/tex/nix/dot2ps.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
source $stdenv/setup

mkdir -p $out

dot2ps() {
Expand Down
2 changes: 0 additions & 2 deletions pkgs/tools/typesetting/tex/nix/lhs2tex.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
source $stdenv/setup

mkdir -p $out

mkdir root
Expand Down
2 changes: 0 additions & 2 deletions pkgs/tools/typesetting/tex/nix/run-latex.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
source $stdenv/setup

mkdir -p $out

export VARTEXFONTS=$TMPDIR/texfonts
Expand Down

0 comments on commit 4e583b2

Please sign in to comment.