84 Commits
Author SHA1 Message Date
Aliaksandr 18e7551efc buildenv: replace // optionalAttrs with nullable attr names
Convert 2 optionalAttrs (args ? nativeBuildInputs, args ? buildInputs) in the compatArgs block into nullable attribute names in a single attrset.
2026-05-18 03:54:27 +03:00
Eman Resu 01d170164d buildEnv: use concatMap, avoid piping 2026-05-13 21:14:09 -04:00
Yueh-Shun LiandPhilip Taron ed96bfd307 buildEnv: construct with structured attributes and pass chosenOutputs directly 2026-04-02 07:31:12 -07:00
Yueh-Shun LiandPhilip Taron 0efccf1dd9 buildEnv: remove redundant pname-version-name assertion
Delegate such a check to stdenv.mkDerivation.
2026-04-02 07:30:35 -07:00
Philip Taron 1b0981b3cb buildEnv: explicitly set __structuredAttrs = false
builder.pl reads all configuration from %ENV, which is fundamentally
incompatible with __structuredAttrs = true (values go into a JSON file
instead). Explicitly opt out so buildEnv doesn't break when
structuredAttrsByDefault is enabled.

The override is placed in the final merge block so it cannot be
circumvented via derivationArgs.

Update the structuredAttrs test from asserting build failure to
verifying that the override works: the build succeeds even when
derivationArgs.__structuredAttrs = true, and eval tests confirm the
attribute is always false.

Suggested-by: Sietse Ringers <SFrijters>
2026-03-24 20:54:58 -07:00
Philip Taron 7269072659 buildEnv: fix passthru merging
Merge derivationArgs.passthru into the passthru chain so that passthru attributes passed via derivationArgs are not silently dropped.
2026-03-19 13:17:19 -07:00
Yueh-Shun LiandPhilip Taron 7e851e1cf5 buildEnv: take derivationArgs 2026-03-19 13:17:19 -07:00
Yueh-Shun LiandPhilip Taron ae8cb8c65e buildEnv: reference attributes from finalAttrs 2026-03-19 13:17:19 -07:00
Yueh-Shun LiandPhilip Taron 726999375d buildEnv: construct with extendMkDerivation and stdenvNoCC.mkDerivation 2026-03-19 13:17:18 -07:00
Yueh-Shun LiandPhilip Taron c42757764c buildEnv: specify extraPathsFrom a string as expected by the builder
Specify `extraPathsFrom` as a string using `lib.optionalString` instead of a singleton list using `lib.optional` to align with the current behavior of the Perl build script.
2026-03-19 13:17:18 -07:00
SandroandGitHub 6c6495bd50 treewide: remove exec bit from files that don't need it (#461314) 2026-02-16 14:56:12 +00:00
19f546749c buildEnv: make name optional
Signed-off-by: Connor Baker <ConnorBaker01@gmail.com>
Co-authored-by: Yueh-Shun Li <shamrocklee@posteo.net>
2026-01-19 12:45:01 +01:00
Maevi 3126d71478 treewide: remove exec bit from files that don't need it
find . -type f -executable ! -name '*.sh' -exec grep -L '^#!' {} \; | xargs chmod a-x
2026-01-16 15:42:35 +01:00
Hans Joachim KliemeckandGitHub 866aaf8e61 buildEnv: relax constraints about readdir contents 2025-11-20 13:10:04 +01:00
Ivy Pierlot fbe214434a buildEnv: change pathsToLink to json decoding 2025-10-15 11:15:29 +11:00
NAHO c8d4dabc43 pkgs: remove optional builtins prefixes from prelude functions
Remove optional builtins prefixes from prelude functions by running:

    builtins=(
      abort
      baseNameOf
      break
      derivation
      derivationStrict
      dirOf
      false
      fetchGit
      fetchMercurial
      fetchTarball
      fetchTree
      fromTOML
      import
      isNull
      map
      null
      placeholder
      removeAttrs
      scopedImport
      throw
      toString
      true
    )

    fd \
      --type file \
      . \
      pkgs \
      --exec-batch sed --in-place --regexp-extended "
        s/\<builtins\.($(
          printf '%s\n' "${builtins[@]}" |
            paste --delimiter '|' --serial -
        ))\>/\1/g
      "

    nix fmt
2025-10-04 19:02:37 +02:00
Jade Lovelace b116ba58dc buildEnv: improve error messages a little bit
buildEnv didn't previously make it exceedingly clear that it was
responsible for errors so finding docs for it was less clear.

Now it says it was responsible and suggests ways to compare the paths,
but only prints this if it's in your critical path and hard-failed.

```
> pkgs.buildEnv error: two given paths contain a conflicting subpath:
>   `/nix/store/kiifd22fh7pcwzbljy0zznzaw3nq508c-hello-2.12.2/bin/hello' and
>   `/nix/store/3sxwkxdm96bn84rhn2g867shsi284qja-hello-2.12.2/bin/hello'
> hint: this may be caused by two different versions of the same package in buildEnv's `paths` parameter
> hint: `pkgs.nix-diff` can be used to compare derivations
```

Tested with:

```nix
let
  pkgs = import ./. { };
  pkgs' = pkgs.stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages;
in

pkgs'.buildEnv {
  name = "meow";
  paths = [
    pkgs'.hello
    (pkgs'.hello.overrideAttrs (old: {
      dontCheck = true;
      dontVersionCheck = true;
      postInstall = ''
        > $out/bin/hello
      '';
    }))
  ];
}
```
2025-06-09 12:23:03 -07:00
Wolfgang Walther a8f509677f various: replace substituteAll with replaceVars
Some easy ones.
2025-01-26 16:47:16 +01:00
Philip TaronandGitHub d752ad6a9a buildEnv: builder.pl: use signature and move the ignoreSingleFileOutputs parameter after the collision-related ones (#364203) 2024-12-12 09:56:13 -08:00
Yueh-Shun Li a3d0d19bb8 buildEnv: builedr.pl: use signatures 2024-12-11 04:21:49 +08:00
Silvan Mosberger 667d42c00d treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build https://github.com/infinisil/treewide-nixpkgs-reformat-script/archive/a08b3a4d199c6124ac5b36a889d9099b4383463f.tar.gz \
      --argstr baseRev 57b193d8dd
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:27:17 +01:00
Yueh-Shun Li 14414ee678 buildEnv: builder.pl: specify parameter ignoreSingleFileOutput after priority 2024-12-11 03:24:38 +08:00
Yueh-Shun Li a993958324 buildEnv: fix bulder.pl (addPkg argument ignoreSingleFileOutputs)
Specify the ignoreSingleFileOutputs parameter wherever calling addPkg.
2024-12-10 04:20:38 +08:00
Yueh-Shun Li 70038f0e4d buildEnv: support ignoreSingleFileOutputs
Add option to ignore single-file output instead of failing.
2024-12-03 12:14:00 +08:00
jopejoe1 e37eeadacd buildenv: fix version not being set 2024-11-26 23:46:24 +01:00
jopejoe1 b497dfa184 bundler-{app,env}: expose pname and version in derivation 2024-11-15 23:57:00 +01:00
K900 f32ec5e6d7 buildenv: don't pass null paths to writeClosure 2024-09-19 23:09:26 +03:00
K900 4654ea4cc0 buildEnv: support pulling in closures of paths
This will become important for Steam.
2024-09-12 15:27:46 +03:00
Philip Taron ae92f312bf treewide: use a consistent meta.priority default 2024-08-29 09:04:57 -07:00
adisbladis dda7578745 build-support/buildenv: Hoist builder instantiation 2023-12-29 03:04:46 +13:00
Christopher League ef2d657a01 buildenv: Limit exclusion of info/dir
While trying to exclude a generated `/share/info/dir` in a package
from symlinking into a profile, we also ended up excluding the Emacs
info manual for `dired-x`.  This change excludes only the dir file.
2023-07-09 22:06:26 -04:00
Robert Hensing fcea105698 buildEnv: Nix's buildEnv should be stable
It's mostly used by nix-env, but Nix should remain simple and small
for reproducibility.
2023-07-06 16:13:38 +02:00
pennae dc895fb281 lib: make extendDerivation lighter on eval
the fix to extendDerivation in #140051 unwittingly worsened eval performance by
quite a bit. set elements alone needed over 1GB extra after the change, which
seems disproportionate to how small it was. if we flip the logic used to
determine which outputs to install around and keep a "this one exactly" flag in
the specific outputs instead of a "all of them" in the root we can avoid most
of that cost.
2021-10-15 16:39:10 +02:00
Peter FerenczyandGitHub 1ec54d2fba buildenv: fix regression introduced by #134215 2021-08-20 15:47:47 +03:00
Peter Ferenczy f8be06a311 buildEnv: better warning and error messages 2021-08-17 18:16:20 +02:00
sternenseemannandProfpatsch b398d00903 trivial-builders: merge passAsFile with env in runCommand'
Previously it was awkward to use the runCommand-variants with
passAsFile as a double definition of passAsFile would potentially
break runCommand: passAsFile would overwrite the previous definition,
defeating the purpose of setting it in runCommand in the first place.
This is now fixed by concatenating the [ "buildCommand" ] list with
one the one from env, if present.

Adjust buildEnv where passAsFile = null; was passed in some cases,
breaking evaluation since it'd evaluate to [ "buildCommand" ] ++ null.
2021-03-18 19:56:40 +01:00
John Ericson 4f6ec19dbc buildEnv: Support nativeBuildInputs too
Since #112276, we should always put `makeWrapper` in
`nativeBuildInputs`. But `buildEnv` was saying put it in `buildInputs`.
That's wrong!

Fix the instructions, and make the right thing possible.
2021-03-02 22:34:54 +00:00
José Romildo Malaquias 4a1ef63c55 buildenv: paths to link resolving to the same absolute path is not a conflict
When building an environment if two paths conflict but one or both are
symbolic links and they resolve to the same real path, the conflict is
discarded because the contents of both paths are the same. One of them
is chosen and there is no need to recur into them in order to build
deeper symbolic links.
2020-06-10 06:42:48 -03:00
Linus Heckemann 3125ab3afe buildEnv: check pathsToLink before checking collisions
Fixes #32683
2019-09-18 15:13:50 +02:00
Vladimír Čunát 2adf954e84 Merge #55420: buildEnv, substituteAll: disable binary cache
... into staging.
2019-02-22 13:57:01 +01:00
Maximilian BoschandFrederik Rietdijk 9fcd3bffc2 buildEnv: improve file check to avoid false-positives
The original change in #55372 was supposed to fix the case where a store
path which is a file should be placed into `buildEnv` which broke with a
fairly misleading Perl error.

Unfortunately this introduced a regression, `findFiles` can have targets
that are files if the file isn't a store path. Rather than adding more
obscure checks with probably further regressions, I figured that it's
better to replicate the behavior of `lib.isStorePath` and explicitly
check if the store path is a file and break in this case only.

This should also fix recent staging issues.
2019-02-21 10:37:42 +01:00
Maximilian BoschandFrederik Rietdijk 1cab56e01a buildEnv: break with a proper error if one path is actually a file
I noticed by creating `buildEnv` where I accidentally put a derivation
from `pkgs.writeText` into `paths` and got a broken build with the
following misleading error message:

```
Use of uninitialized value $stat1 in numeric ne (!=) at /nix/store/9g4wc31j7a2xp22xpgwr0qssfxahxdzl-builder.pl line 74.
Use of uninitialized value $stat1 in bitwise and (&) at /nix/store/9g4wc31j7a2xp22xpgwr0qssfxahxdzl-builder.pl line 75.
different permissions in `' and `/nix/store/0vy5ss91laxvwkyvrbld5hv27i88qk5w-noise': 0000 <-> 0444 at /nix/store/9g4wc31j7a2xp22xpgwr0qssfxahxdzl-builder.pl line 75.
```

It can be reproduced with an expression like this:

``` nix
{ pkgs ? import <nixpkgs> { } }:
let
  file = pkgs.writeText "test" ''
    content
  '';
in
  pkgs.buildEnv {
    name = "test-env";
    paths = [ /* ... */ file ];
  }
```
2019-02-19 07:56:44 +01:00
volthandGitHub 09665fee2b buildEnv: allowSubstitutes = false
trivial derivation
2019-02-07 22:19:26 +00:00
Frederik RietdijkandGitHub 87f757e834 Merge pull request #27780 from tilpner/overridable-buildenv
Make buildEnv overridable
2017-09-14 17:26:33 +02:00
tilpner 77f1c7d5bc buildenv: Make buildEnv overridable
callPackage already calls makeOverridable, but that just
makes the function that evaluates to buildEnv overridable,
not buildEnv itself.
If no overridable version of buildEnv is used during construction,
users can't override e.g. `paths` at all
2017-08-02 11:56:37 +02:00
Thomas Tuegel dce958ac39 buildenv: read propagated-user-env-packages line-by-line
Since 3cb745d5a6, the format of
propagated-user-env-packages has changed and propagated packages have not been
included by buildenv, including in the system environment.

The buildenv builder is modified to read propagated-user-env-packages
line-by-line, instead of expecting all packages on one line.
2017-07-16 16:06:06 -05:00
Eric Litak bd45ec6416 buildEnv: use buildPackages.perl so crossDrv works 2017-04-14 02:00:08 -07:00
Alexey ShmalkoandNikolay Amiantov 0172558e82 buildEnv: build the whole tree of directories to pathsToLink
This patch fixes #16614 and #16741.

The first issue was caused by the fact that both `/share` and
`/share/fish/vendor_completions.d` end in the `pathsToLink`. The
`pkgs/build-support/buildenv/builder.pl` creates `/share`, then links
`/share/fish` under `/share` and then tries to create the directory
`/share/fish/vendor_completions.d` and fails because it already exists.

The simplest way to reproduce the issue is to build the next Nix
expression:

```nix
let pkgs = import <nixpkgs> { };
in pkgs.buildEnv {
  name = "buildenv-issue";

  paths = [
    pkgs.fish
    pkgs.vim
  ];

  pathsToLink = [
    "/share"
    "/share/fish/vendor_completions.d"
  ];
}
```

The second issue is more critical and was caused by the fact findFiles
doesn't recurse deep enough. It stops at first unique directory for the
package (e.g., "/share" or even "/") and later the scripts decides it
shouldn't link it as it doesn't match pathsToLink (e.g., "/share/fish"),
so the result is empty.

The test:
```nix
let pkgs = import <nixpkgs> { };
in pkgs.buildEnv {
  name = "buildenv-issue";

  paths = [
    pkgs.fish
    pkgs.vim
  ];

  pathsToLink = [
    "/share/fish/functions"
  ];
}
```

or

```nix
let pkgs = import <nixpkgs> { };
in pkgs.buildEnv {
  name = "buildenv-issue";

  paths = [
    pkgs.vim
  ];

  pathsToLink = [
    "/share"
  ];
}
```
2016-07-13 03:54:11 +03:00
Vladimír Čunát f57c6449dc buildEnv: fix #14682 evaluation in some edge cases
I supplied meta.outputsToInstall automatically in all
mkDerivation products, but some packages still don't use it.
The reported case: jekyll -> bundlerEnv -> buildEnv -> runCommand.
2016-04-17 08:57:17 +02:00
Vladimír Čunát 9a824f2f1d treewide: rename extraOutputs{ToLink,ToInstall}
This is to get more consistent with `meta.outputsToInstall`.
2016-04-07 15:59:44 +02:00