Commit Graph

30 Commits

Author SHA1 Message Date
Tristan Ross
013ade6562
pkgs/test/stdenv/default.nix: fix eval on darwin 2024-06-30 07:00:11 -07:00
Jade Lovelace
78945a827c stdenv: make inputDerivation never fixed-output
This fixes using inputDerivation on derivations that are fixed-output.

Previously:

```
nix-repl> drv = runCommand "huh" { outputHash = "sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU="; outputHashAlgo = "sha256"; outputHashType = "flat"; } "touch $out"

nix-repl> drv.inputDerivation
«derivation /nix/store/d8mjs6cmmvsr1fv7psm6imis5pmh9bcs-huh.drv»

nix-repl> :b drv.inputDerivation
error: fixed output derivation 'huh' is not allowed to refer to other store paths.
       You may need to use the 'unsafeDiscardReferences' derivation attribute, see the manual for more details.
```

Fixes: https://github.com/NixOS/nixpkgs/issues/304209
2024-04-15 00:52:28 -07:00
Rick van Schijndel
b728d76d0e
Merge pull request #255463 from emilylange/stdenv/patch-shebangs-trailing-newline
patch-shebangs: fix crash with shebang without trailing newline
2024-02-16 18:33:27 +01:00
nicoo
1cabb1c445 tests/stdenv: Check derivations with an MD5 outputHash fail to evaluate 2023-10-25 23:14:16 +00:00
emilylange
c47f245253
patch-shebangs: fix crash with shebang without trailing newline
This fixes a bug where `patchShebangs` crashes when trying to patch
files that contain only a shebang (e.g. `#!/bin/bash`) (and nothing
else) and do not end with a newline.

Such file can be produced using `printf "#!/bin/bash" > example` or
`echo -n "#!/bin/bash" > example`.

I don't understand why one would want to create such files, as they do
literally nothing, but the chromium tarball we are using started
shipping some 🫠

Full reproducer:

```nix
with import <nixpkgs> { };

stdenv.mkDerivation {
  dontUnpack = true;
  name = "patch-shebangs-no-trailing-newline-reproducer";
  postPatch = ''
    printf "#!/bin/bash" > reproducer
    chmod +x reproducer
    patchShebangs reproducer
  '';
}
```

```
❯ nix-build reproducer.nix
this derivation will be built:
  /nix/store/vmbshdkdk4a0bayw3wi21wvxyhzpcsy2-patch-shebangs-no-trailing-newline-reproducer.drv
building '/nix/store/vmbshdkdk4a0bayw3wi21wvxyhzpcsy2-patch-shebangs-no-trailing-newline-reproducer.drv'...
patching sources
patching script interpreter paths in reproducer
/nix/store/vr6wwdxkmyy44sg0gwxi10b8fc5zhwz0-stdenv-linux/setup: line 144: pop_var_context: head of shell_variables not a function context
error: builder for '/nix/store/vmbshdkdk4a0bayw3wi21wvxyhzpcsy2-patch-shebangs-no-trailing-newline-reproducer.drv' failed with exit code 1;
       last 3 log lines:
       > patching sources
       > patching script interpreter paths in reproducer
       > /nix/store/vr6wwdxkmyy44sg0gwxi10b8fc5zhwz0-stdenv-linux/setup: line 144: pop_var_context: head of shell_variables not a function context
       For full logs, run 'nix log /nix/store/vmbshdkdk4a0bayw3wi21wvxyhzpcsy2-patch-shebangs-no-trailing-newline-reproducer.drv'.
```
2023-09-16 14:20:56 +02:00
Ivan Trubach
ebd4619053 patch-shebangs: add a flag to update shebangs with store paths
This change adds a flag to update shebang paths that point to the Nix
store. This is particularly useful when a cross-compiled package uses
same script at compile-time and run-time, but the interpreter must be
changed since hostPlatform != buildPlatform.
2023-06-19 09:01:21 +03:00
Artturin
2879607431 tests.stdenv.hooks.reproducible-builds: fix mistake 2023-06-17 23:45:11 +03:00
Alyssa Ross
2023766e31
tests.stdenv.test-inputDerivation: init 2023-05-09 14:02:45 +00:00
Adam Joseph
5f57c2e0f9 pkgs/test/stdenv/default.nix: add gcc-stageCompare
This commit adds a derivation `gcc-stageCompare` to
`pkgs/test/stdenv/default.nix`.

It is important to always build this derivation whenever building
`stdenv`!  Because we are using a Nix-driven bootstrap instead of
gcc's built-in `--enable-bootstrap`, the `gcc` derivation no longer
performs the post-self-compilation sanity check.  You must build
this derivation in order to perform that sanity check.

The major benefit of this new approach is that the sanity check
(which involves a third compilation of gcc) can be performed
*concurrently* with all packages that depend on `stdenv`, rather
than serially.  Since `stdenv` has very little derivation-level
parallelism it cannot take advantage of more than one or perhaps two
builders.  If you have three or more builders this commit will
reduce the time-to-rebuild-stdenv by around 20% (one of three gcc
rebuilds is removed from the critical path, and stdenv's build time
is dominated by roughly 3*gcc + 1*binutils + 1*bison-test-suite).

Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
2023-04-02 13:49:53 -07:00
Artturin
a4e1cf6d13 tests.stdenv.outputs-no-out: update expectedMsg 2023-03-02 22:10:50 +01:00
Artturin
6e422a0fba tests.stdenv.outputs-no-out: cause less rebuilds
now gcc isn't built
2023-03-02 22:10:50 +01:00
github-actions[bot]
3cdd771820
Merge staging-next into staging 2023-02-23 18:01:49 +00:00
Artturin
f9fdf2d402 treewide: move NIX_CFLAGS_COMPILE to the env attrset
with structuredAttrs lists will be bash arrays which cannot be exported
which will be a issue with some patches and some wrappers like cc-wrapper

this makes it clearer that NIX_CFLAGS_COMPILE must be a string as lists
in env cause a eval failure
2023-02-22 21:23:04 +02:00
Artturin
425e4250db tests.stdenv.outputs-no-out: fix 2023-02-22 21:23:04 +02:00
Artturin
883daacbaa tests.stdenv: add hooks.patch-shebangs.split-string & tweak tests 2023-02-17 22:23:35 +02:00
Artturin
8876a5c91f tests.stdenv: move patch-shebangs test 2023-02-17 22:23:33 +02:00
Artturi
e42cdd2383
Merge pull request #212286 from Artturin/runonall
make-symlinks-relative: run on all outputs
2023-01-25 15:51:53 +02:00
Artturin
cfb543a532 make-symlinks-relative: run on all outputs 2023-01-23 20:11:41 +02:00
Robert Hensing
01d7f19346 multi-outputs.sh: Improve _assignFirst error message
Closes #16182

This improves the error message

    Error: _assignFirst found no valid variant!

which occurred when the set of outputs was not sufficient to set
the various outputDev, outputBin, etc variables. Specifically, this
would mean that "out" is not among the outputs, which is valid for
a derivation.

This changes the message to something like

    error: _assignFirst: could not find a non-empty variable to assign to outputDev. The following variables were all unset or empty: dev out.
          If you did not define an "out" output, make sure to define all the specific required outputs: define an output for one of the unset variables.

While this isn't a full explanation of what stdenv can and can not do,
I think it's vast improvement over the 0 bits of information that it
used to provide. This at least gives a clue as to what's going on, and
even suggests a fix, although probably multiple such fixes are required
in an instance where someone starts with a no-out derivation from scratch
(and decide to persist).
2023-01-16 12:57:01 +01:00
Naïm Favier
84eebc0fe4
Merge pull request #205944 from ncfavier/structured-attrs-env 2022-12-15 13:27:54 +01:00
Artturin
9b1e8d7267
tests.stdenv: check that attrs in env are exported 2022-12-15 13:27:11 +01:00
Naïm Favier
e14de22618
stdenv: handle env gracefully
Derivations not using `__structuredAttrs` should not attempt to set
environment variables from `env`.

Derivations using `__structuredAttrs` should fail if `env` is not
exportable.
2022-12-15 13:27:11 +01:00
Artturin
630bb71ac5 stdenv: sort defaultNativeBuildInputs alphabetically 2022-12-13 01:12:20 +02:00
Artturin
60b1f09aa4 tests.stdenv.hooks: add more tests 2022-12-12 21:39:56 +02:00
Artturin
9cb5662187 tests: move stdenv hook tests to stdenv.hooks 2022-12-12 21:39:56 +02:00
Artturin
84a7cadfd2 tests.stdenv: add test-golden-example-structuredAttrs
examples copied from https://nixos.mayflower.consulting/blog/2020/01/20/structured-attrs/

nix has tests for structuredAttrs but i figured it'd be good to have a
golden test here too

https://github.com/NixOS/nix/blob/master/tests/structured-attrs.nix
https://github.com/NixOS/nix/blob/master/tests/structured-attrs-shell.nix
2022-12-12 21:39:56 +02:00
Artturin
11c3127e38 stdenv: detect the type of variable in {prepend,append}ToVar
stdenv: error if using {prepend,append}ToVar on associative array

i don't know how to prepend to associative array
2022-12-10 04:42:36 +02:00
Artturin
bf972f1873 tests.stdenv: add tests for prependToVar and appendToVar 2022-12-10 04:22:11 +02:00
Artturin
68fb254bf2 tests.stdenv: deduplicate 2022-12-10 04:22:11 +02:00
Artturin
18d00c5814 tests.stdenv: add some env attrset tests 2022-12-08 21:09:02 +02:00