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
  • Loading branch information
wolfgangwalther authored Dec 29, 2024
2 parents c13f8ab + 255012c commit 464605b
Show file tree
Hide file tree
Showing 57 changed files with 18 additions and 166 deletions.
12 changes: 2 additions & 10 deletions doc/stdenv/stdenv.chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, 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}

Expand Down
2 changes: 0 additions & 2 deletions nixos/lib/make-system-tarball.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
source $stdenv/setup

sources_=($sources)
targets_=($targets)

Expand Down
1 change: 0 additions & 1 deletion nixos/modules/services/computing/slurm/slurm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions nixos/modules/services/networking/ircd-hybrid/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

doSub() {
local src=$1
local dst=$2
Expand Down
3 changes: 0 additions & 3 deletions nixos/modules/services/web-servers/jboss/builder.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 8 additions & 1 deletion nixos/modules/system/etc/test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ lib.recurseIntoAttrs {
} ''
mkdir fake-root
export FAKECHROOT_EXCLUDE_PATH=/dev:/proc:/sys:${builtins.storeDir}:$out
fakechroot fakeroot chroot $PWD/fake-root bash -c 'source $stdenv/setup; eval "$fakeRootCommands"'
if [ -e "$NIX_ATTRS_SH_FILE" ]; then
export FAKECHROOT_EXCLUDE_PATH=$FAKECHROOT_EXCLUDE_PATH:$NIX_ATTRS_SH_FILE
fi
fakechroot fakeroot chroot $PWD/fake-root bash -e -c '
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; fi
source $stdenv/setup
eval "$fakeRootCommands"
'
'';

}
32 changes: 0 additions & 32 deletions nixos/modules/tasks/tty-backgrounds-combine.sh

This file was deleted.

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
6 changes: 4 additions & 2 deletions pkgs/build-support/docker/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,8 @@ rec {
mkdir $out
${if enableFakechroot then ''
proot -r $PWD/old_out ${bind-paths} --pwd=/ fakeroot bash -c '
proot -r $PWD/old_out ${bind-paths} --pwd=/ fakeroot bash -e -c '
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; fi
source $stdenv/setup
eval "$fakeRootCommands"
tar \
Expand All @@ -994,7 +995,8 @@ rec {
-cf $out/layer.tar .
'
'' else ''
fakeroot bash -c '
fakeroot bash -e -c '
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; fi
source $stdenv/setup
cd old_out
eval "$fakeRootCommands"
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 @@ -61,7 +61,6 @@ let
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
Loading

0 comments on commit 464605b

Please sign in to comment.