Commit Graph

367 Commits

Author SHA1 Message Date
sternenseemann
b5cad4d4a4 stdenv/setup.sh: make sure $sourceRoot has +x before cd-ing
This change is prompted by the following, admittedly cursed tarball:

```
> curl https://registry.npmjs.org/char-regex/-/char-regex-1.0.2.tgz 2>/dev/null \
  | tar -ztv
drw-rw-rw- 0/0               0 2020-02-18 10:50 package
-rw-rw-rw- 0/0             297 2020-02-18 10:50 package/index.d.ts
-rw-rw-rw- 0/0            1920 2020-02-18 10:50 package/index.js
-rw-rw-rw- 0/0            1092 2020-01-31 11:31 package/LICENSE
-rw-rw-rw- 0/0             937 2020-02-18 10:51 package/package.json
-rw-rw-rw- 0/0             713 2020-02-18 10:50 package/README.md
```

The minimal reproducer for the issue is the following derivation trying
to work around the uid 0 issue with `dontMakeSourcesWritable = true`:

```nix
{ stdenv, fetchurl }:

stdenv.mkDerivation {
  name = "test";

  src = fetchurl {
    sha1 = "d744358226217f981ed58f479b1d6bcc29545dcf";
    url = "https://registry.npmjs.org/char-regex/-/char-regex-1.0.2.tgz";
  };

  dontMakeSourcesWritable = true;

  installPhase = ''
    cp -R . $out
  '';
}
```

This currently fails in the following way:

```
these derivations will be built:
  /nix/store/pc3jbydl0xcc8nrndf5xkf7hdhpgpb41-test.drv
building '/nix/store/pc3jbydl0xcc8nrndf5xkf7hdhpgpb41-test.drv'...
unpacking sources
unpacking source archive /nix/store/v9p98kqplf4kflmy91p0687xlvr6klb1-char-regex-1.0.2.tgz
source root is package
find: 'package/index.d.ts': Permission denied
find: 'package/index.js': Permission denied
find: 'package/LICENSE': Permission denied
find: 'package/package.json': Permission denied
find: 'package/README.md': Permission denied
/nix/store/6c47azxacncswc1pllzj28zfzqw40d7c-stdenv-linux/setup: line 1311: cd: package: Permission denied
builder for '/nix/store/pc3jbydl0xcc8nrndf5xkf7hdhpgpb41-test.drv' failed with exit code 1
error: build of '/nix/store/pc3jbydl0xcc8nrndf5xkf7hdhpgpb41-test.drv' failed
```

As you can see, the issue is that `$sourceRoot` isn't executable,
prohibiting the call to `cd`. This can be fixed by running
`chmod +x "${sourceRoot}"` before `cd` regardless of
`dontMakeSourcesWritable` in `unpackPhase` since if `chmod` fails, `cd`
would fail as well and we are out of options.

Verified that the workaround works locally.

Another thing to investigate is investigating if we should use
`--no-same-owner` for `tar` and if it helps in this case as well.
See also <https://github.com/Profpatsch/yarn2nix/issues/56>.
2022-03-24 11:13:38 +01:00
Sandro Jäckel
b7da6c7da7
stdenv, dep-licenses.sh: do not skip handling of other exit traps
See https://github.com/akinomyoga/ble.sh/issues/179
2022-02-20 16:27:24 +01:00
Sandro Jäckel
24880b690b stdenv: fix shellcheck complaining about things not being posix compliant 2022-01-23 03:50:23 +01:00
Sandro Jäckel
37fdba0b4f stdenv: restore bash options -e/-u to the values they where before
Source https://github.com/akinomyoga/ble.sh/issues/169#issuecomment-1019049032

Author: akinomyoga
2022-01-23 03:50:09 +01:00
Alyssa Ross
2ebeb02a99 stdenv/setup: tell libtool about library paths
Packages that use libtool run it as a wrapper around the linker.
Before calling the linker, libtool will determine what libraries would
be linked, and check if there's a corresponding libtool
archive (libfoo.la) file in the same directory .  This file
contains extra information about the library.  This is especially
important for static linking, because static archives don't contain
dependency information, so we need libtool to use the .la files to
figure out which libraries actually need to be linked against.

But in Nixpkgs, this has never worked.  libtool isn't able to find any
libraries, because only the compiler wrapper knows how to find them,
and the compiler wrapper is opaque to libtool.  This is why
pkgsStatic.util-linuxMinimal doesn't build prior to this patch — it
depends on libpam, which depends on libaudit, and if libtool can't
find the .la file, nothing will tell the linker to also link against
libaudit when linking libpam.  (It was previously possible to build a
static util-linux, because linux-pam only recently had the audit
dependency added.)

There are a couple of ways we could fix this, so that libtool knows
where to look for .la files.

 * Set LD_LIBRARY_PATH/DYLD_LIBRARY_PATH/whatever, which libtool will
   examine.  This would have major side effects though, because the
   dynamic linker looks at it too.

 * Inject libtool scripts with the appropriate information.  That's
   what I've done here.  It was the obvious choice because we're
   already finding and modifying the libtool scripts, to remove paths
   outside the Nix store that libtool might check in unsandboxed
   builds.  Instead of emptying out the system paths, we can
   repopulate it with our own library paths.

(We can't use a wrapper like we do for other tools in Nixpkgs, because
libtool scripts are often distributed in source tarballs, so we can't
just add a wrapped version of libtool as a dependency.  That's why
there's already the fixLibtool function in stdenv.)

With this change, libtool is able to discover .la files, and
pkgsStatic.util-linuxMinimal can build again, linking correctly
against libpam and libaudit.
2021-11-23 21:33:16 +00:00
Artturi
0809a3a44b
Merge pull request #137209 from milahu/patch-10 2021-10-25 20:32:06 +03:00
happysalada
a634fbe065 stdenv: add shopt inherit_errexit 2021-10-06 00:42:58 +09:00
happysalada
84e4715a14 stdenv: use named ref to clarify intent 2021-10-06 00:42:29 +09:00
Winter
8cff7796d7
stdenv: re-add isMachO helper function (#138334) 2021-09-17 23:09:06 -04:00
Vladimír Čunát
183cd6b09f
Merge #138186: stdenv: remove isMachO helper function
...into staging-next
2021-09-17 18:31:26 +02:00
Winter
f8edf7720d stdenv: remove isMachO helper function
This reverts commit 488395c0f8.

Currently, `nix print-dev-env` fails to execute if this function is present, because of its use of hex literals.
Until this issue (https://github.com/NixOS/nix/issues/5262) is solved, we should revert this to prevent breakage.
2021-09-16 16:56:12 -04:00
happysalada
33518fcb45 stdenv/setup.sh: fix read -N 0 for bash 5
somehow `read -N 0` behavior changed in bash 5. `read -d ''` has identical behavior
the purpose of the function is to read stdin and exit 1 on a null byte (i.e. if stdin is the content of a binary)

(cherry picked from commit 5d0acf20f88b1820cb8b641cfc5a43e973122701)
2021-09-12 09:48:54 +09:00
milahu
5e2f703e83
unpackFile: ignore timestamp warnings 2021-09-09 20:13:21 +02:00
happysalada
4c92bb8bdf stdenv: fix nix_build_cores guess
- use builtin arithmetic instead of external expr
- simplify logic with bash builtins
2021-09-07 00:36:55 +09:00
happysalada
02c142a2dd stdenv: fix showBuildStats
- remove going through another file
- use builtin instead of external cat
- improve echo formatting
2021-09-06 22:51:33 +09:00
Martin Weinelt
7f732aca66 Revert "Merge remote-tracking branch 'origin/python-unstable' into staging-next"
This reverts commit b041b2e1b2, reversing
changes made to 5b6c2380ad.
2021-09-05 15:02:25 +02:00
happysalada
e32bf6f4f2 stdenv setup.sh: remove combined [ in favor of [[
[ ... ] && [ ...] -> [[ ... && ... ]]
2021-08-30 10:27:45 +09:00
happysalada
fd89fb6248 stdenv: remove bash version compatibility hack 2021-08-30 10:26:56 +09:00
happysalada
13049cd33e stdenv: remove combined command conditional 2021-08-30 10:26:14 +09:00
happysalada
2fa9facc49 stdenv: arithmetic fixes 2021-08-30 10:25:40 +09:00
happysalada
54475daa27 stdenv: declare missing variables 2021-08-30 10:24:00 +09:00
Sebastián Mancilla
488395c0f8
stdenv: add isMachO helper function (#133808)
Detect if a binary is a Mach-O file.
2021-08-21 15:33:03 -04:00
Alyssa Ross
0901dfb214 stdenv/setup: force libtool to skip dep checks
When we "fix" libtool, we empty out its system library path to avoid
it discovering libraries in e.g. /usr when the sandbox is disabled.
But this also means that the checks libtool does to make sure it can
find the libraries its supposed to be linking to won't work.  On Linux
and Darwin, this isn't a problem, because libtool doesn't actually
perform any checks, but it is on at least NetBSD and Cygwin[1].

So, we force libtool not to do these checks on any platform, bringing
the more exotic platforms into line with the existing behaviour on
Linux and Darwin.

Without this change, lots of library packages produce warnings like
this in their build output on the platforms with checks by default:

    *** Warning: linker path does not have real file for library -lz.
    *** I have the capability to make that library automatically link in when
    *** you link to this library.  But I can only do this if you have a
    *** shared version of the library, which you do not appear to have
    *** because I did check the linker path looking for a file starting
    *** with libz but no candidates were found. (...for regex pattern test)
    *** The inter-library dependencies that have been dropped here will be
    *** automatically added whenever a program is linked with this library
    *** or is declared to -dlopen it.

And dependent packages break because libtool doesn't link their
transitive dependencies.  So making this change fixes _lots_ of
packages on those platforms.

[1]: https://git.savannah.gnu.org/cgit/libtool.git/tree/m4/libtool.m4?id=544fc0e2c2a03129a540aebef41ad32bfb5c06b8#n3445
2021-07-27 20:42:31 +00:00
happysalada
4fc50527f8 stdenv: typo 2021-07-19 14:49:47 +09:00
Sandro
d871186cdf
Merge pull request #108102 from matthewbauer/bash-version-check
stdenv/setup.sh: Add version check to setup script
2021-06-24 13:06:46 +02:00
Matthew Bauer
8fa084dc0f stdenv/setup.sh: Add version check to setup script
Only bash 4+ works in setup.sh. To make sure this is obvious, we can
check BASH_VERSINFO to get the major version number of Bash.

While Bash 3 is pretty rare, it still comes stock in macOS.

We *could* provide a warning here for non-Bash shells, but it’s not
always clear whether they will work or not. Zsh should have no trouble
while busybox sh, fish, or any others. There’s no great way to detect
what feature set the shell supports.

Fixes #71625
2021-06-23 01:32:58 -05:00
Vincenzo Mantova
6ba632c2a4
stdenv: ignore duplicates in addToSearchPath (#113800) 2021-03-13 13:58:21 -05:00
tv
659da9b738 stdenv: mute errors when failing to write env-vars 2021-01-05 22:23:37 +01:00
Robert Hensing
c8ae3d870c setup.sh: export XDG_DATA_DIRS for consistency
By exporting it, we always make the new directories available
to subprocesses, regardless of whether the environment
variable existed before `nix-shell` was invoked.
2020-11-25 08:44:04 -08:00
Robert Hensing
84c58abdc4 setup.sh: Only load XDG_DATA_DIRS for executable inputs
This avoids the scenario where strictDeps is off and cross-compiled
XDG_DATA_DIRS content is brought into the environment.

While probably harmless for data like manpages and completion scripts,
this would cause issues when XDG_DATA_DIRS is used to find executables
or plugins. The Qt framework is known to behave like this and might
have run into incompatibilities.
2020-11-25 08:44:04 -08:00
Robert Hensing
0f13cccb95 setup.sh: Support XDG_DATA_DIRS
XDG_DATA_DIRS is to /share as PATH is to /bin.

It was defined as part of the XDG basedir specification.
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

While it originated from the X Desktop Group, it is not limited to
the X11 ecosystem, as evidenced by its use in bash-completion.

The removal of ` && -d "$pkg/bin"` is ok, because this optimization is
already performed by `addToSearchPath`.
2020-11-25 08:44:04 -08:00
Joachim Breitner
d92a19b039 stdenv: Fix error message when checkPhase is missing 2020-11-07 10:37:37 -08:00
Jörg Thalheim
bc4927a526
stdenv: set SOURCE_DATE_EPOCH to a value python supports
in nix-shell this value breaks the build because python's
packaging refuses to build timestamps that date before 1980.
2020-06-08 11:54:46 +01:00
worldofpeace
5384d72885 setup.sh: add dontPatch
Fixes #85038
2020-04-12 07:04:35 -04:00
Matthew Bauer
e0fb0df64f generic/setup.sh: allow clobbering env-vars file
If the option ‘noclobber’ is set in Bash, we get an error when we
clobber an already existing env-vars. This is an okay error to ignore,
so just >| instead. Note that >| is NOT a Bashism[[1]].

Fixes #79651

[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07_02
2020-04-09 22:39:16 -04:00
Lily Ballard
d45d6205de setup.sh: rewrite stripHash
Rewrite the `stripHash` helper function with 2 differences:

* Paths starting with `--` will no longer produce an error.
* Use Bash string manipulation instead of shelling out to `grep` and
  `cut`. This should be faster.
2019-11-12 14:38:41 +01:00
John Ericson
5b6da99ea0 stdenv: Don't unset propagated*DepFiles before main phases
A bunch of stdenv-internal variables were deleted in
1601a7fcce, but these are needed in the
fixup phase, whereas the rest are just needed for the initial work
(findInputs, etc) before the user phases.

CC @matthewbauer
2019-11-05 16:32:22 -05:00
Matthew Bauer
9ffedfef81
Merge pull request #69603 from matthewbauer/unset-unused-setup-var
Unset unused variables in setup.sh
2019-11-05 14:43:11 -05:00
John Ericson
9df7efe0c6 stdenv: Don't stop set -u-ing
Before, we very carefully unapplied and reapplied `set -u` so the rest
of Nixpkgs could continue to not fail on undefined variables. Let's rip
off the band-aid.
2019-11-01 22:03:47 +00:00
Matthew Bauer
1601a7fcce generic/setup.sh: Unset locally defined variables
setup.sh adds a bunch of variables that only it needs. To avoid
polluting environments, we should unset these as soon as we are done
with them.
2019-09-26 18:47:38 -04:00
Matthew Bauer
8e9b98a183
Merge pull request #69028 from matthewbauer/remove-iselfexec-iselfdyn
Revert "setup.sh introduce isELFExec, isELFDyn"
2019-09-20 23:26:48 -04:00
Albert Safin
42482a1d60 setup.sh: avoid subshells: iterating a file 2019-09-20 02:45:53 +00:00
Albert Safin
cf4e4820f6 setup.sh: avoid subshells: type -t in _callImplicitHook 2019-09-20 02:45:52 +00:00
Albert Safin
d53920a5be setup.sh: avoid subshells: mapOffset 2019-09-20 02:45:52 +00:00
Albert Safin
6f024f6e65 setup.sh: avoid subshells: type -t 2019-09-20 02:45:52 +00:00
Albert Safin
463463b395 setup.sh: avoid subshells: shopt -po nounset 2019-09-19 09:54:29 +00:00
Matthew Bauer
24c6aef75a Revert "setup.sh introduce isELFExec, isELFDyn"
This reverts commit e1b80a5a99.

This is broken in PIE (#68513). Best to not keep it in until something
else starts using it.
2019-09-18 11:28:27 -04:00
Florian Klink
e1b80a5a99 setup.sh introduce isELFExec, isELFDyn
These can be used to determine whether a ELF file with ELF header is an
executable or shared library.

We can't implement it in pure bash, as bash has problems with null
bytes.
2019-08-17 16:45:52 +02:00
worldofpeace
4a88f4ebfc setup.sh: add dontUnpack 2019-07-01 04:23:51 -04:00
worldofpeace
0197c05786 setup.sh: add dontConfigure
There's already 21 occurences of this and I've
expected this to exist without knowing it had no affect for a while.
2019-07-01 01:52:54 -04:00
Vladimír Čunát
b27cc37671
stdenv: also override cert files in pure nix-shell
That's very much consistent with the spirit of nix-shell --pure

BTW, nix 1.x shells will be always treated as pure;
in that version detection isn't possible.
https://github.com/NixOS/nix/commit/1bffd83e1a9c
2019-05-09 09:49:42 +02:00
Vladimír Čunát
79bd4ad579
stdenv, cacert: consider $NIX_SSL_CERT_FILE in hooks
Some SSL libs don't react to $SSL_CERT_FILE.
That actually makes sense to me, as we add this behavior
as nixpkgs-specific, so it seems "safer" to use $NIX_*.
2019-05-09 08:46:22 +02:00
Matthew Bauer
ec7d72a57d setup.sh: make sure initialPath goes at end of HOST_PATH
We want initialPath to have lowest precedence.

In addition, unset _PATH and _HOST_PATH as they shouldn’t be needed
after final PATH and HOST_PATH are set.
2019-04-26 21:54:49 -04:00
Matthew Bauer
d54fbbebbb
Merge pull request #49552 from matthewbauer/setup-dedupe
setup.sh: avoid running the same hook twice
2019-01-27 18:22:41 -05:00
Matthew Bauer
9172c1eee2 setup.sh: avoid running the same hook twice
In strictDeps=false, we don’t want the same package hook to be run
twice, otherwise we get duplicates in some flags.

Fixes #41340
2019-01-27 17:49:13 -05:00
Matthew Bauer
329913f733 setup.sh: put SHELL in flagsArray
We don’t want to modify makeFlags, that is given to us by our
environment. Adding to it could lead to duplicates after repeated use.

Fixes #27533
2019-01-26 21:14:36 -05:00
Jörg Thalheim
1b146a8c6f
treewide: remove paxutils from stdenv
More then one year ago we removed grsecurity kernels from nixpkgs:
https://github.com/NixOS/nixpkgs/pull/25277

This removes now also paxutils from stdenv.
2018-12-22 12:55:05 +01:00
Daiderd Jordan
c9223a17bc
Revert "patch-shebangs: use --build for auto patch shebangs"
Completely breaks darwin. Every package in the stdenv that has shebangs
in the output will end up with references to bootstrap-tools.

This reverts commit eb7c50a993.
2018-11-14 23:37:31 +01:00
Matthew Bauer
f19bb8321a
Merge pull request #35304 from volth/patch-97
[staging] substitute() print warning if does nothing
2018-11-12 12:52:51 -06:00
Matthew Bauer
eb7c50a993 patch-shebangs: use --build for auto patch shebangs
In strictDeps=false, autoPatchshebangs should use
--build (corresponding to PATH) to lookup commands. This restores the
previous behavior of patchshebangs so that we don’t break stuff that
isn’t careful in the buildInputs vs. nativeBuildInputs distinction.
Unfortunately this won’t work under cross compilation.
2018-11-02 00:27:14 -05:00
aszlig
b25b6e0c75
stdenv: Improve ELF detection for isELF
The isELF function only checks whether ELF is contained within the first
4 bytes of the file, which is a bit fuzzy and will also return
successful if it's a text file starting with ELF, for example:

  ELF headers
  -----------

  Some text here about ELF headers...

So instead, we're now doing a precise match on \x7fELF.

Signed-off-by: aszlig <aszlig@nix.build>
Acked-by: @Ericson2314
Closes: https://github.com/NixOS/nixpkgs/pull/47244
2018-09-25 06:55:18 +02:00
Matthew Bauer
ba5717a6f5 stdenv: fix HOST_PATH change
a4630c65ca was incorrect in assuming $SHELL would be a path to the
bash derivation. In fact $SHELL will be a path to the bash executable.

Unfortunately this did not fix the original issue. So instead, we just
have to reuse initialPath can be added like PATH is.

Sorry for the inconvenience! I hadn’t thought through the effects of
the last commit.

/cc @copumpkin @ericson2314
2018-09-17 14:18:06 -05:00
Matthew Bauer
a4630c65ca stdenv: add shell to HOST_PATH for backwards compatibility
To avoid breaking things, we need to make sure SHELL goes into
HOST_PATH. This reflects my changes to patch-shebangs to make it cross
compilation ready. When a script is patched from the Nix store it now
looks to HOST_PATH to get the targeted machine’s executables.
Unfortunately, this only works in native builds.
2018-09-16 15:58:21 -05:00
Jan Malakhovski
c63ca0a431 stdenv: implement enableParallelChecking option
Works similarly to `enableParallelBuilding`, but is set by default when
`enableParallelBuilding` is set. In my experience most packages that build
fine in parallel also check fine in parallel.
2018-09-05 01:14:39 +00:00
James Deikun
bd63de114e stdenv/build-support: support .tbz and .txz tarballs 2018-07-30 15:30:16 -04:00
Matthew Bauer
cd91d1ad9f setup.sh: add HOST_PATH
HOST_PATH contains the path of the host package. This will include the
packages listed in buildInputs & depsHostHost. Use this to find
runtime commands that the host needs.

For instance to find the runtime version of perl,

$ PATH="$HOST_PATH" command -v perl
/nix/store/...-perl-5.28.0-aarch64-unknown-linux-android/bin/perl

This path should not be executed directly (it will break for cross
compilation). Only use it to find the location of executables that
will be run by your host system. Your build tools will, as always, be
available on the default PATH.
2018-07-22 23:14:49 -04:00
Matthew Bauer
37273afd27
Merge pull request #43224 from volth/patch-179
[staging] substitute(): --subst-var was silently coercing to "" if the variable does not exist.
2018-07-21 15:48:14 -04:00
volth
5ff872aa24 substituteStream(): print warning if nothing done 2018-07-10 22:47:34 +00:00
aszlig
739c835515
stdenv-setup: Remove superfluous check for /bin/sh
The line was essentially checking whether /bin/sh exists and is
executable and if that's the case, the isScript function returns
successfully.

When asking the author of this line on IRC it seems that even they can't
remember or imagine what this was supposed to be.

In summary: Whenever /bin/sh doesn't exist during a build, *any* file
given to isScript is reported as being a script even if it isn't.

This is kinda counter-intuitive and not something what somebody would
expect from a function called "isScript".

Signed-off-by: aszlig <aszlig@nix.build>
Cc: @edolstra
2018-07-09 20:43:34 +02:00
volth
0de0ce5893 substitute(): --subst-var was silently coercing to "" if the variable does not exist. 2018-07-08 16:32:03 +00:00
John Ericson
5e17335bd7 Merge remote-tracking branch 'upstream/staging' into strictDeps 2018-05-14 23:33:03 -04:00
John Ericson
330ca731e8 treewide: Get rid of all uses of crossConfig
The hack of using `crossConfig` to enforce stricter handling of
dependencies is replaced with a dedicated `strictDeps` for that purpose.
(Experience has shown that my punning was a terrible idea that made more
difficult and embarrising to teach teach.)

Now that is is clear, a few packages now use `strictDeps`, to fix
various bugs:

 - bintools-wrapper and cc-wrapper
2018-05-14 23:30:37 -04:00
John Ericson
4f7cdd35d5
Merge pull request #40139 from obsidiansystems/modular-setup-hooks
treewide: Modular setup hooks
2018-05-07 15:32:10 -04:00
John Ericson
34a3233a2e stdenv: Support concatenating setup hooks from multiple parts. 2018-05-07 14:43:22 -04:00
Jan Malakhovski
50af975d85 stdenv: implement checkTarget and installCheckTarget autodetection 2018-04-25 19:53:25 +00:00
Jan Malakhovski
e9e06888ed stdenv: generic/setup.sh: cleanup installPhase 2018-04-25 19:53:25 +00:00
Jan Malakhovski
ad98c36f1b stdenv: generic/setup.sh: simplify buildPhase Makefile check 2018-04-25 19:53:24 +00:00
Shea Levy
b24ce2ae63
Handle sourceRoots with leading dashes 2018-02-15 11:50:24 -05:00
Shea Levy
f83b6e1130
unpackPhase: Handle sources starting with a hyphen 2018-01-24 21:58:57 -08:00
adisbladis
c2316114bc
stdenv: Kill off ensureDir 2018-01-09 11:14:48 +08:00
John Ericson
469fd89832 stdenv-setup: Ease the transition with native builds
- All deps go on the PATH

 - CC and Bintools wrappers with their host != depender's host still get their
   setup hooks run.

 - Environment hooks get applied to all packages

This isn't so elegent, but eases the transition on a very significant
PR.
2017-12-30 22:04:23 -05:00
John Ericson
a036473a0a {bintools,cc}-wrapper: Fix setup hook to respect the role of the cc-compiler
We now have the information to properly determine the role the
cc-wrapper dependency has, by taking advantage of `offset`. No longer
use the soon-to-be-deprecated crossConfig environment variable, the
temp hack used before this change.
2017-12-30 22:04:21 -05:00
John Ericson
7f3ca3e21a stdenv: Fix handling of dependencies and hooks
4 far-reaching changes: Smaller PATH, New vars, different propagation
logic, and different hook logic

Smaller PATH
------------

`buildInputs` no longer go on the PATH at build time, as they cannot be
run when cross compiling and we don't want to special case. Simply make
a `nativeBuildInput` too if one needs them on the PATH. Fixes #21191.

Many new depedendency variables
-------------------------------

See the stdenv chapter of the nixpkgs manual. I pulled out the existing
documentation of dependency specification into a new section, and added
language for these two (and their propagated equivalents) along side
the others'.

More complex propagation logic
------------------------------

Before a propagated*XXX*Input always acted as if it was specified
directly as a *XXX*Input downstream. That's simple enough, but violates
the intended roles of each sort of dep, which has functional and not
just stylistic consequences.

The new algorithm is detailed in the manual, and ensures everything
ends up in the right place. I tried to give both an informal and formal
description, but I suspect in practice it will not make much sense
until one tries cross compiling, after which it will immediately make
sense as the only sane option.

Simplified hook logic
---------------------

Rather than `envHook` and `crossEnvHook`, whose behavior differs
depending on whether we are cross compiling or not, there is now one
hook per sort (or rather non-propagated and propagated pair of sorts)
of dependency. These new hooks have the same meaning regardless of
cross compilation. See the setup hook section of stdenv chapter of the
Nixpkgs manual for more details.
2017-12-30 22:04:21 -05:00
John Ericson
da19c34d0f stdenv setup: Always use both propagated files
This continues #23374, which always kept around both attributes, by
always including both propagated files: `propgated-native-build-inputs`
and `propagated-build-inputs`. `nativePkgs` and `crossPkgs` are still
defined as before, however, so this change should only barely
observable.

This is an incremental step to fully keeping the dependencies separate
in all cases.
2017-11-21 10:44:44 -05:00
John Ericson
6a5cda5131 stdenv setup: Run setup hooks and other processing after accumulating deps
I find the separation of concerns, accumulating, then processing, easier
to follow. Also, with my yet-to-be-merged cross work, the accumulation
part will become more complex.
2017-11-15 18:51:06 -05:00
John Ericson
f6fcb9bc0d stdenv: Turn on set -x if NIX_DEBUG >= 6
Why 6? It seems a decently high number, giving us room for more degrees
of debugging before the `set -x` sledgehammer without incurring a
mass-rebuild.
2017-09-26 11:24:19 -04:00
John Ericson
127a5f3357 treewide: Use (( "${NIX_DEBUG:-0}" >= 1) )) consistently 2017-09-26 11:24:19 -04:00
Eelco Dolstra
0061fae2e6 genericBuild: Communicate the current build phase to Nix
This allows the progress bar to show e.g.

  [1/9/59 built] building bison-3.0.4 (configurePhase): checking for strdup... yes
2017-09-07 22:24:27 +02:00
Eelco Dolstra
6b3cef2246 Remove tracePhases
This has not been used in a long time.
2017-09-07 22:15:37 +02:00
Orivej Desh
f4044c1ccc stdenv-setup: list environment variables with awk 2017-09-03 12:57:08 +00:00
Orivej Desh
a09d9e7cd4 stdenv-setup: fix substituteAll with set -eu
Environment variable filter in substituteAll was not precise and produced
undefined and invalid variable names.  Vladimír Čunát tried to fix that in [1],
but `env -0` did not work during Darwin bootstrap, so [2] reverted this change
and replaced an error due to invalid variables with a warning.  Recently in #28057
John Ericson added `set -u` to `setup.sh` and undefined variables made the setup
fail during e.g. `nix-build -A gnat` with `setup: line 519: !varName: unbound
variable`.

[1] 62fc8859c1
[2] 81df035429
2017-09-03 12:57:08 +00:00
John Ericson
81194eef45 stdenv-setup: Use set -u as much as possible
Older bash version, like those in the bootstrap tools and on macOS,
currently confuse variables defined as an empty array with undefined
variables. `${foo+"${foo[@]}"}` will prevent `set -u` problems with
empty arrays and older without making a single '' in the empty case.

Care is taken to `set +u` when running hooks so as to not break existing
packages.
2017-08-23 15:57:56 -04:00
Tuomas Tynkkynen
7320fa9d45 Revert "stdenvs: Distinguish between extraBuildInputs and extraNativeBuildInputs"
This reverts commit eeabf85780.

This change suddenly makes tons of stdenv internals visible in
nativeBuildInputs of every derivation, which doesn't seem desirable.
E.g:

````
nix-repl> hello.nativeBuildInputs
[ «derivation /nix/store/bcfkyf6bhssxd2vzwgzmsbn7b5b9rpxc-patchelf-0.9.drv»
  «derivation /nix/store/4wnshnz9wwanpfzcrdd76rri7pyqn9sk-paxctl-0.9.drv»
  << snip 10+ lines >>
  «derivation /nix/store/d35pgh1lcg5nm0x28d899pxj30b8c9b2-gcc-wrapper-6.4.0.drv»
]
````
2017-08-18 13:21:56 +03:00
John Ericson
eeabf85780 stdenvs: Distinguish between extraBuildInputs and extraNativeBuildInputs
Additionally, instead of pulling them from `setup.sh`, route them via
Nix. This gets us one step closer to making stdenv be a plain attribute
set instead of a derivation.
2017-08-15 18:24:54 -04:00
Linus Heckemann
17753fa005 stdenv: fix typo in setup.sh 2017-08-09 17:33:02 +01:00
John Ericson
42f35503b5 cc-wrapper: Make hygienic
See the added comments for what exactly has been done.
2017-08-07 03:05:50 -04:00
John Ericson
820e4021d3 stdenv-setup: Remove any declare -g
This is invalid before bash-4.2, affecting bash used impurely in
nix-shell on MacOS.
2017-07-26 09:11:18 -04:00
John Ericson
ea7d13cf1a stdenv-setup and misc hooks: Work with bash-3.4 for MacOS nix-shell
This is a temporary measure until this impurity is removed from Nix.
2017-07-26 09:08:01 -04:00
John Ericson
f6f40e3fe5 stdenv-setup and misc pkgs: Revert to space-deliminated propagated-* files
We cannot switch to line-delimited yet, because certain Nix commands do
not read in the entire file, but just the first line.
2017-07-26 09:07:55 -04:00
John Ericson
34c0ba498c stdenv-setup: Add quotes that don't do anything for consistency.
@vcunat and others rightly point out that it's easier to quote always,
than learn Bash's idiosyncrasies enough to know when it doesn't make a
difference.

This reverts commit 2743078f66, which
removes quotes that don't do anything, and then goes further adding
even more quotes.
2017-07-25 14:36:00 -04:00