Commit Graph

45 Commits

Author SHA1 Message Date
Aliaksandr
f8b9b7a087 stdenv/darwin: move the libiconv alias assertion into tests.stdenv
The final stage asserted

    assert prevStage.libiconv == prevStage.darwin.libiconv;

On Darwin `libiconv` is `darwin.libiconv`, so this compares a value with
itself. Nix does not notice: `eqValues` short-circuits only on pointer
identity of the two value slots, and these are two slots that resolve to
one attribute set. It therefore falls through to the derivation case,
which compares `outPath`.

`lib.extendDerivation` guards `outPath` behind the derivation's validity,
which reads `config.allowUnfree`, so the assertion demanded a `config`
option while the package set was still being assembled. When `config` is a
function it is passed `pkgs`, and the loop closes:

    (import <nixpkgs> {
      system = "aarch64-darwin";
      config = { pkgs, lib, ... }: { allowUnfree = lib.isAttrs pkgs; };
    }).config.allowUnfree

failed with an infinite recursion on Darwin while evaluating on Linux,
whose stdenv never forces a derivation that early. It now evaluates on
both.

Keep checking the invariant, from `tests.stdenv` instead. By then the
package set is complete, so forcing `outPath` is just a read.
The other twelve assertions in the stage read `passthru` and
`stdenv.cc.cc`, which are ungated, and stay where they are.

Assisted-by: claude-code with claude-opus-5[1m]-high
2026-08-10 00:50:54 +03:00
nixpkgs-ci[bot]
9af8e8ea80 Merge master into staging-next 2026-02-20 18:13:26 +00:00
Emily
36e1dea26b tests.stdenv: extend the existing config 2026-02-19 16:07:57 +00:00
Aleksi Hannula
5500570e9f stdenv: refactor to hook up minimal-bootstrap 2026-01-26 21:45:18 +02:00
jopejoe1
9e568d613d tests.stdenv: migrate tests-stdenv-gcc-stageCompare from all-packages 2026-01-16 20:31:57 +01:00
nixpkgs-ci[bot]
6b5a50c011 Merge staging-next into staging 2025-12-13 06:06:37 +00:00
Taeer Bar-Yam
97c3645990 stdenv: add tests for inputDerivation with allowedReferences, etc.
Co-authored-by: infinisil <github@infinisil.com>

!fixup every test needs a meta field?

!fixup refactor inputDerivation tests

!fixup fix tests
2025-12-12 20:23:22 +01:00
K900
8b56bf20bb Merge remote-tracking branch 'origin/staging-next' into staging 2025-12-07 23:38:37 +03:00
David McFarland
d613d20a13 treewide: fix nix-env eval in cross 2025-12-04 19:44:19 -04:00
DavHau
c66b12ff90 make-symlinks-relative.sh: optimize - use multiple cores
This optimizes the performance of the hook on machines with multiple cores.

The previous implementation was slow, as it was launching two extra processes per symlink (readlink and ln) while not making use of multiprocessing.

The following improvements were made:
- don't even execute the hook if dontRewriteSymlinks is set
- replace multiple find calls with single find call over all outputs
- use xargs -P to process symlinks in parallel
- add test to check that the hook operates as expected
2025-12-03 11:39:52 +07:00
Connor Baker
d9dbfc0a6c tests.stdenv: use system from stdenv.{build,host}Platform
Signed-off-by: Connor Baker <ConnorBaker01@gmail.com>
2025-09-30 15:23:18 -07:00
Wolfgang Walther
5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
langsjo
e432d5321e tests.stdenv: drop "test-env-derivation"
This behavior is no longer supported
2025-07-18 11:21:52 -07:00
DavHau
4a42314f72 generic-builder: optimize - reduce execve calls when sourcing
This improves the implementation of `dumpVars` by removing a call to `install`.

This improves performance when sourcing setup.sh by more than 10%
It should also improve the performance when transitioning between build phases significantly as no process executions are issued anymore,

A test is added, which ensures that no extra execve calls are issued while sourcing setup.sh.
2025-06-16 22:21:39 +07:00
jopejoe1
b494b7ed40 tests.stdenv: remove __attrsFailEvaluation
These attrs do not fail to Eval on Darwin anymore
2025-05-13 20:32:18 +02:00
Silvan Mosberger
374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](8616af08d9/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00
Wolfgang Walther
56b09628e3 stdenv: support multi-char separators in concatStringsSep
One prominent use-case for this is pytestCheckHook. This will help
making it work with structuredAttrs in the future.
2024-11-30 16:38:02 +01:00
Artturin
f0e657f3b1 Merge branch 'master' into staging-next 2024-09-25 06:05:01 +03:00
Artturin
e0464e4788 treewide: replace stdenv.is with stdenv.hostPlatform.is
In preparation for the deprecation of `stdenv.isX`.

These shorthands are not conducive to cross-compilation because they
hide the platforms.

Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way

One example of why this is bad and especially affects compiler packages
https://www.github.com/NixOS/nixpkgs/pull/343059

There are too many files to go through manually but a treewide should
get users thinking when they see a `hostPlatform.isX` in a place where it
doesn't make sense.

```
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is"
fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is"
```
2024-09-25 00:04:37 +03:00
Wolfgang Walther
bc0395ee6f auto-patchelf: refactor structuredAttrs support
stdenv now provides better tooling to support structuredAttrs without
depending on $__structuredAttrs itself.
2024-09-11 19:29:39 +02:00
Wolfgang Walther
1efcffa700 stdenv: support default values in concatTo
The previously used pattern was introduced in #318614, but technically
leaked the default flags into the global scope. While this would
probably not make much of a practical difference, making concatTo
support default values is a much cleaner approach.
2024-08-24 12:23:35 +02:00
Someone Serge
9876c2fe9e stdenv: concatStringsSep: test sep="&"
The test fails without 64eaa63181
("stdenv: concatStringsSep: quote ${sep}")

Co-authored-by: Ivan Trubach <mr.trubach@icloud.com>
Co-authored-by: Wolfgang Walther <walther@technowledgy.de>
2024-08-11 23:54:15 +00:00
Wolfgang Walther
471cbdd062 stdenv: add concatStringsSep helper
This can be used to separate lists for example with commas, when
creating argument strings. This works with both structuredAttrs disabled
and enabled.
2024-08-02 22:11:41 +02:00
Wolfgang Walther
6bdfef9d2d stdenv: generalize _accumFlagsArray to concatTo
Passing "flagsArray" as the first argument allows using this function
in a few more places.
2024-08-02 22:11:38 +02:00
Wolfgang Walther
929db7bc22 tests.stdenv: fix spelling 2024-08-02 21:54:25 +02:00
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
nicoo
1cabb1c445 tests/stdenv: Check derivations with an MD5 outputHash fail to evaluate 2023-10-25 23:14:16 +00:00
Alyssa Ross
2023766e31 tests.stdenv.test-inputDerivation: init 2023-05-09 14:02:45 +00: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
425e4250db tests.stdenv.outputs-no-out: fix 2023-02-22 21:23:04 +02:00
Artturin
8876a5c91f tests.stdenv: move patch-shebangs test 2023-02-17 22:23:33 +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
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