Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions doc/stdenv/stdenv.chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,32 @@ Convenience function for `makeWrapper` that replaces `<\executable\>` with a wra

If you will apply it multiple times, it will overwrite the wrapper file and you will end up with double wrapping, which should be avoided.

### `prependToVar` \<variableName\> \<elements...\> {#fun-prependToVar}

Prepend elements to a variable.

Example:

```shellSession
$ configureFlags="--disable-static"
$ prependToVar configureFlags --disable-dependency-tracking --enable-foo
$ echo $configureFlags
--disable-dependency-tracking --enable-foo --disable-static
```

### `appendToVar` \<variableName\> \<elements...\> {#fun-appendToVar}

Append elements to a variable.

Example:

```shellSession
$ configureFlags="--disable-static"
$ appendToVar configureFlags --disable-dependency-tracking --enable-foo
$ echo $configureFlags
--disable-static --disable-dependency-tracking --enable-foo
```

## Package setup hooks {#ssec-setup-hooks}

Nix itself considers a build-time dependency as merely something that should previously be built and accessible at build time—packages themselves are on their own to perform any additional setup. In most cases, that is fine, and the downstream derivation can deal with its own dependencies. But for a few common tasks, that would result in almost every package doing the same sort of setup work—depending not on the package itself, but entirely on which dependencies were used.
Expand Down
1 change: 1 addition & 0 deletions nixos/modules/services/networking/ircd-hybrid/builder.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we source this at the beginning of stdenv setup?

Copy link
Member Author

@Artturin Artturin Dec 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$stdenv variable will not be set for the source below

The better way to fix these would be to do 983382d / use buildCommand but I wanted to keep the diffs small

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$stdenv isn't exported?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with structuredAttrs all things are passed with .attrs.sh/.attrs.json and nothing is in env ( i have not confirmed this yet)

source $stdenv/setup

doSub() {
Expand Down
1 change: 1 addition & 0 deletions nixos/modules/services/web-servers/jboss/builder.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set -e

if [ -e .attrs.sh ]; then source .attrs.sh; fi
source $stdenv/setup

mkdir -p $out/bin
Expand Down
1 change: 1 addition & 0 deletions pkgs/applications/misc/adobe-reader/builder.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
source $stdenv/setup

echo "unpacking $src..."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let
mv bin/nomad-autoscaler $bin/bin
ln -s $bin/bin/nomad-autoscaler $out/bin/nomad-autoscaler

for d in $outputs; do
for d in $(getAllOutputNames); do
mkdir -p ''${!d}/share
done
rmdir $bin/share
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
source $stdenv/setup

tar --extract --file=$src libreoffice-$version/download.lst -O > $out
32 changes: 15 additions & 17 deletions pkgs/build-support/bintools-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ let
bintoolsVersion = lib.getVersion bintools;
bintoolsName = lib.removePrefix targetPrefix (lib.getName bintools);

libc_bin = if libc == null then null else getBin libc;
libc_dev = if libc == null then null else getDev libc;
libc_lib = if libc == null then null else getLib libc;
libc_bin = if libc == null then "" else getBin libc;
libc_dev = if libc == null then "" else getDev libc;
libc_lib = if libc == null then "" else getLib libc;
bintools_bin = if nativeTools then "" else getBin bintools;
# The wrapper scripts use 'cat' and 'grep', so we may need coreutils.
coreutils_bin = if nativeTools then "" else getBin coreutils;
Expand All @@ -68,7 +68,7 @@ let
# The dynamic linker has different names on different platforms. This is a
# shell glob that ought to match it.
dynamicLinker =
/**/ if sharedLibraryLoader == null then null
/**/ if sharedLibraryLoader == null then ""
else if targetPlatform.libc == "musl" then "${sharedLibraryLoader}/lib/ld-musl-*"
else if targetPlatform.libc == "uclibc" then "${sharedLibraryLoader}/lib/ld*-uClibc.so.1"
else if (targetPlatform.libc == "bionic" && targetPlatform.is32bit) then "/system/bin/linker"
Expand All @@ -87,7 +87,7 @@ let
else if targetPlatform.isDarwin then "/usr/lib/dyld"
else if targetPlatform.isFreeBSD then "/libexec/ld-elf.so.1"
else if lib.hasSuffix "pc-gnu" targetPlatform.config then "ld.so.1"
else null;
else "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a general pattern, is it? Having more to do with good bash style, perhaps setting set -u at some point? (Treat unset as error)

It would be very useful to have a small section in the manual about upgrading a derivation to structured attrs.


expand-response-params =
if buildPackages ? stdenv && buildPackages.stdenv.hasCC && buildPackages.stdenv.cc != "/dev/null"
Expand All @@ -103,15 +103,10 @@ stdenv.mkDerivation {

preferLocalBuild = true;

inherit bintools_bin libc_bin libc_dev libc_lib coreutils_bin;
shell = getBin shell + shell.shellPath or "";
gnugrep_bin = if nativeTools then "" else gnugrep;

inherit targetPrefix suffixSalt;

outputs = [ "out" ] ++ optionals propagateDoc ([ "man" ] ++ optional (bintools ? info) "info");

passthru = {
inherit targetPrefix suffixSalt;
inherit bintools libc nativeTools nativeLibc nativePrefix;

emacsBufferSetup = pkgs: ''
Expand Down Expand Up @@ -193,8 +188,6 @@ stdenv.mkDerivation {
strictDeps = true;
depsTargetTargetPropagated = extraPackages;

wrapperName = "BINTOOLS_WRAPPER";

setupHooks = [
../setup-hooks/role.bash
./setup-hook.sh
Expand Down Expand Up @@ -366,10 +359,15 @@ stdenv.mkDerivation {
##
+ extraBuildCommands;

inherit dynamicLinker;

# for substitution in utils.bash
expandResponseParams = "${expand-response-params}/bin/expand-response-params";
env = {
# for substitution in utils.bash
expandResponseParams = "${expand-response-params}/bin/expand-response-params";
shell = getBin shell + shell.shellPath or "";
gnugrep_bin = if nativeTools then "" else gnugrep;
wrapperName = "BINTOOLS_WRAPPER";
inherit dynamicLinker targetPrefix suffixSalt coreutils_bin;
inherit bintools_bin libc_bin libc_dev libc_lib;
};

meta =
let bintools_ = if bintools != null then bintools else {}; in
Expand Down
30 changes: 15 additions & 15 deletions pkgs/build-support/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ let
ccVersion = lib.getVersion cc;
ccName = lib.removePrefix targetPrefix (lib.getName cc);

libc_bin = if libc == null then null else getBin libc;
libc_dev = if libc == null then null else getDev libc;
libc_lib = if libc == null then null else getLib libc;
libc_bin = if libc == null then "" else getBin libc;
libc_dev = if libc == null then "" else getDev libc;
libc_lib = if libc == null then "" else getLib libc;
cc_solib = getLib cc
+ optionalString (targetPlatform != hostPlatform) "/${targetPlatform.config}";

Expand Down Expand Up @@ -131,22 +131,16 @@ stdenv.mkDerivation {

preferLocalBuild = true;

inherit cc libc_bin libc_dev libc_lib bintools coreutils_bin;
shell = getBin shell + shell.shellPath or "";
gnugrep_bin = if nativeTools then "" else gnugrep;

inherit targetPrefix suffixSalt;
inherit darwinPlatformForCC darwinMinVersion darwinMinVersionVariable;

outputs = [ "out" ] ++ optionals propagateDoc [ "man" "info" ];

passthru = {
inherit targetPrefix suffixSalt;
# "cc" is the generic name for a C compiler, but there is no one for package
# providing the linker and related tools. The two we use now are GNU
# Binutils, and Apple's "cctools"; "bintools" as an attempt to find an
# unused middle-ground name that evokes both.
inherit bintools;
inherit libc nativeTools nativeLibc nativePrefix isGNU isClang;
inherit cc libc nativeTools nativeLibc nativePrefix isGNU isClang;

emacsBufferSetup = pkgs: ''
; We should handle propagation here too
Expand Down Expand Up @@ -270,8 +264,6 @@ stdenv.mkDerivation {
propagatedBuildInputs = [ bintools ] ++ extraTools ++ optionals cc.langD or false [ zlib ];
depsTargetTargetPropagated = optional (libcxx != null) libcxx ++ extraPackages;

wrapperName = "CC_WRAPPER";

setupHooks = [
../setup-hooks/role.bash
] ++ lib.optional (cc.langC or true) ./setup-hook.sh
Expand Down Expand Up @@ -538,8 +530,16 @@ stdenv.mkDerivation {
nixSupport);


# for substitution in utils.bash
expandResponseParams = "${expand-response-params}/bin/expand-response-params";
env = {
# for substitution in utils.bash
expandResponseParams = "${expand-response-params}/bin/expand-response-params";
shell = getBin shell + shell.shellPath or "";
gnugrep_bin = if nativeTools then "" else gnugrep;
wrapperName = "CC_WRAPPER";
inherit suffixSalt coreutils_bin bintools cc;
inherit libc_bin libc_dev libc_lib;
inherit darwinPlatformForCC darwinMinVersion darwinMinVersionVariable;
};

meta =
let cc_ = if cc != null then cc else {}; in
Expand Down
1 change: 1 addition & 0 deletions pkgs/build-support/fetchbzr/builder.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
source "$stdenv/setup"

header "exporting \`$url' (revision $rev) into \`$out'"
Expand Down
1 change: 1 addition & 0 deletions pkgs/build-support/fetchcvs/builder.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
source $stdenv/setup

(echo "#!$SHELL"; \
Expand Down
1 change: 1 addition & 0 deletions pkgs/build-support/fetchdarcs/builder.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
source $stdenv/setup

tagtext=""
Expand Down
3 changes: 2 additions & 1 deletion pkgs/build-support/fetchdocker/fetchdocker-builder.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
source "${stdenv}/setup"
header "exporting ${repository}/${imageName} (tag: ${tag}) into ${out}"
mkdir -p "${out}"
Expand All @@ -8,7 +9,7 @@ cat <<EOF > "${out}/compositeImage.sh"
# Create a tar archive of a docker image's layers, docker image config
# json, manifest.json, and repositories json; this streams directly to
# stdout and is intended to be used in concert with docker load, i.e:
#
#
# ${out}/compositeImage.sh | docker load

# The first character follow the 's' command for sed becomes the
Expand Down
1 change: 1 addition & 0 deletions pkgs/build-support/fetchfossil/builder.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
source $stdenv/setup
header "Cloning Fossil $url [$rev] into $out"

Expand Down
2 changes: 2 additions & 0 deletions pkgs/build-support/fetchgit/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# - no revision specified and remote has a HEAD which is used
# - revision specified and remote has a HEAD
# - revision specified and remote without HEAD
#
if [ -e .attrs.sh ]; then source .attrs.sh; fi
source $stdenv/setup

header "exporting $url (rev $rev) into $out"
Expand Down
1 change: 1 addition & 0 deletions pkgs/build-support/fetchhg/builder.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
source $stdenv/setup
header "getting $url${rev:+ ($rev)} into $out"

Expand Down
1 change: 1 addition & 0 deletions pkgs/build-support/fetchipfs/builder.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
source $stdenv/setup

# Curl flags to handle redirects, not use EPSV, handle cookies for
Expand Down
1 change: 1 addition & 0 deletions pkgs/build-support/fetchmtn/builder.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
source $stdenv/setup

set -x
Expand Down
1 change: 1 addition & 0 deletions pkgs/build-support/fetchsvn/builder.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
source $stdenv/setup

header "exporting $url (r$rev) into $out"
Expand Down
1 change: 1 addition & 0 deletions pkgs/build-support/fetchsvnssh/builder.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
source $stdenv/setup

header "exporting $url (r$rev) into $out"
Expand Down
1 change: 1 addition & 0 deletions pkgs/build-support/fetchurl/builder.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
source $stdenv/setup

source $mirrorsFile
Expand Down
10 changes: 6 additions & 4 deletions pkgs/build-support/nuke-references/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ stdenvNoCC.mkDerivation {
'';

# FIXME: get rid of perl dependency.
inherit perl;
inherit (builtins) storeDir;
shell = lib.getBin shell + (shell.shellPath or "");
signingUtils = if darwinCodeSign then signingUtils else null;
env = {
inherit perl;
inherit (builtins) storeDir;
shell = lib.getBin shell + (shell.shellPath or "");
signingUtils = if darwinCodeSign then signingUtils else "";
};
}
13 changes: 7 additions & 6 deletions pkgs/build-support/pkg-config-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@ stdenv.mkDerivation {

preferLocalBuild = true;

shell = getBin stdenvNoCC.shell + stdenvNoCC.shell.shellPath or "";

inherit targetPrefix suffixSalt baseBinName;

outputs = [ "out" ] ++ optionals propagateDoc ([ "man" ] ++ optional (pkg-config ? doc) "doc");

passthru = {
inherit targetPrefix suffixSalt;
inherit pkg-config;
};

Expand Down Expand Up @@ -83,8 +80,6 @@ stdenv.mkDerivation {
ln -s ${pkg-config}/share $out/share
'';

wrapperName = "PKG_CONFIG_WRAPPER";

setupHooks = [
../setup-hooks/role.bash
./setup-hook.sh
Expand Down Expand Up @@ -120,6 +115,12 @@ stdenv.mkDerivation {
##
+ extraBuildCommands;

env = {
shell = getBin stdenvNoCC.shell + stdenvNoCC.shell.shellPath or "";
wrapperName = "PKG_CONFIG_WRAPPER";
inherit targetPrefix suffixSalt baseBinName;
};

meta =
let pkg-config_ = if pkg-config != null then pkg-config else {}; in
(if pkg-config_ ? meta then removeAttrs pkg-config.meta ["priority"] else {}) //
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/release/nix-build.nix
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ stdenv.mkDerivation (
echo "$system" > $out/nix-support/system

if [ -z "${toString doingAnalysis}" ]; then
for i in $outputs; do
for i in $(getAllOutputNames); do
if [ "$i" = out ]; then j=none; else j="$i"; fi
mkdir -p ''${!i}/nix-support
echo "nix-build $j ''${!i}" >> ''${!i}/nix-support/hydra-build-products
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/setup-hooks/auto-patchelf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ autoPatchelf() {
# (Expressions don't expand in single quotes, use double quotes for that.)
postFixupHooks+=('
if [ -z "${dontAutoPatchelf-}" ]; then
autoPatchelf -- $(for output in $outputs; do
autoPatchelf -- $(for output in $(getAllOutputNames); do
[ -e "${!output}" ] || continue
echo "${!output}"
done)
Expand Down
12 changes: 9 additions & 3 deletions pkgs/build-support/setup-hooks/move-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
preFixupHooks+=(_moveToShare)

_moveToShare() {
forceShare=${forceShare:=man doc info}
if [ -n "$__structuredAttrs" ]; then
if [ -z "${forceShare-}" ]; then
forceShare=( man doc info )
fi
else
forceShare=( ${forceShare:-man doc info} )
fi

if [[ -z "$out" ]]; then return; fi

for d in $forceShare; do
for d in "${forceShare[@]}"; do
if [ -d "$out/$d" ]; then
if [ -d "$out/share/$d" ]; then
echo "both $d/ and share/$d/ exist!"
Expand All @@ -20,4 +27,3 @@ _moveToShare() {
fi
done
}

Loading