Commit Graph

190 Commits

Author SHA1 Message Date
Eman Resu
4e54346578 make-derivation.nix: take args one at a time, declare variables early
While bootstrapping stdenv, we'd prefer not to call the entire file the
whole time on every single stage, since we have certain args ahead of
time.
2026-05-28 19:34:51 -04:00
adisbladis
a24cd2fd27 stdenv/adapters: foldl -> foldl' 2026-05-16 15:51:29 +12:00
nixpkgs-ci[bot]
fcd023ec9e Merge staging-next into staging 2026-03-22 12:09:03 +00:00
Alexander Foremny
bcb20ae99e stdenvAdapters: refactor in terms of overrideMkDerivationArgs
The newly added function `overrideMkDerivationArgs` [1] is strictly more
general than some of the stdenv adapters. We rewrite suitable functions in
terms of `overrideMkDerivationArgs` in order to simplify their implementation.

This commit is based off of @SomeoneSerge's PR [2].

[1] https://github.com/NixOS/nixpkgs/pull/496862
[2] https://github.com/NixOS/nixpkgs/pull/350350

Co-authored-by: SomeoneSerge <else+aalto@someonex.net>
2026-03-21 22:42:39 -07:00
Philip Taron
d69b59c191 stdenv: move NIX_CFLAGS_LINK into env by default for makeStaticBinaries (#498046) 2026-03-18 00:55:57 +00:00
nixpkgs-ci[bot]
284fe9ab7b Merge master into staging-next 2026-03-18 00:24:50 +00:00
Alexander Foremny
3c4cf6301a stdenvAdapters: add overrideMkDerivationArgs
In addition to the use-case mentioned inside the function's
documentation comment, I am motivated to add this function for two
reasons:

- My actual use-case is adding a guaranteed phase to every
  `stdenv.mkDerivation` via a nixpkgs overlay. Exposing this generic
  function allows me to do that, without having to replicate
  `defaultMkDerivationFromStdenv`. This relieves that maintainence
  burden for that overlay implementation, since that function has to be
  kept in sync with `stdenv/generic`.

- I see value in adding this generic function over a specialized
  function. At first, I had a different implementation in mind, and
  tried to make due with the specialized functions that were already
  exposed. Having access to this generic function allowed me to
  experiment, and settle on a better implementation.

This commit is based off of @SomeoneSerge's PR [1].

[1] https://github.com/NixOS/nixpkgs/pull/350350

Co-authored-by: SomeoneSerge <else+aalto@someonex.net>
2026-03-16 10:27:26 +01:00
Stefan Frijters
71003837dd stdenv: move NIX_CFLAGS_LINK into env by default for makeStaticBinaries
This should not depend on whether __structuredAttrs is enabled;
it belongs in env regardless.

Warn if the flag already exists in the wrong place
(which should not be the case in current nixpkgs).
2026-03-12 17:07:21 +01:00
Stefan Frijters
e9cd68c858 stdenv: move NIX_CFLAGS_LINK into env for useGoldLinker and useMoldLinker 2026-02-19 18:21:06 +01:00
Dawid Ciężarkiewicz
a468b2ed92 mold: switch to wrapped by default 2025-12-08 14:08:50 -08:00
Dawid Ciężarkiewicz
f7f415d099 wild: make wrapped default, add wild-unwrapped 2025-11-10 22:03:11 -08:00
Ross Smyth
a4bc70d4b4 adapters: Add useWildLinker 2025-11-05 11:49:38 -05:00
K900
f8d669f413 Merge remote-tracking branch 'origin/master' into staging-next 2025-10-04 21:10:21 +03: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
Emily
22455076d7 overrideLibcxx: drop
We now use the latest SDK’s libc++ headers, and longer have Clang
versions old enough for version compatibility to be a concern.
2025-09-15 19:24:08 +01:00
Emily
2e3fd465be {darwin.*,overrideSDK}: convert compatibility stubs to throws 2025-08-16 03:25:14 +01:00
Guillaume Girol
d0b787a627 pkgsStatic: fix in combination with __structuredAttrs
pkgsStatic injects { NIX_CFLAGS_COMPILE = " -static"; }. When
__structuredAttrs is true, it must inject { env.NIX_CFLAGS_COMPILE = "
-static"; } instead, as attributes outside env are ignored.
2025-07-26 12:00:00 +00:00
Alyssa Ross
e653ef6c4e stdenvAdapters.keepDebugInfo: add Rust support
These are the flags we use in the separateDebugInfo hook, plus
disabling optimisations in line with what we do for C.

This fixes e.g. enableDebugging amberol.
2025-07-14 19:20:49 +02:00
Ben Siraphob
6a4e8e9e8a Fix useMoldLinker when cross compiling (#400749) 2025-05-12 14:30:04 -04:00
Peter Collingbourne
f011e90094 Fix useMoldLinker when cross compiling
After #400734 we can make useMoldLinker work when cross compiling.
We need the following:
- Need to use pkgs.buildPackages.mold so that we use mold binaries
  for the build machine instead of the host.
- Need to create unprefixed ld.mold wrapper because gcc will not look
  for a triple-prefixed ld.mold when passing -fuse-ld=mold.

Tested on an aarch64 machine with this change + #400734:

$ nix-build -K --expr 'with import "${./.}" { crossSystem = { config = "x86_64-unknown-linux-gnu"; }; }; hello.override { stdenv = useMoldLinker stdenv; }' && strings result/bin/hello | grep mold
/nix/store/w1yg0am7iyqsgi253h84lsp92178sgfi-hello-x86_64-unknown-linux-gnu-2.12.1
mold 2.37.1 (compatible with GNU ld)
2025-04-21 23:23:58 -07:00
Emily
a7cc1269fa overrideSDK: add deprecation warning 2025-04-20 22:42:20 +01:00
Tristan Ross
c9ba38546b pkgsStatic.stdenv: fix eval on darwin 2025-04-09 12:13:06 +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
Kiskae
bd12176888 stdenvAdapters: set default_both_libraries for meson in makeStaticLibrary
The default value of `default_both_libraries` is 'shared'. This change
supplements the existing `default_library` flag for static builds.
2024-11-02 16:06:39 +01:00
Randy Eckenrode
0e61488c5b overrideSDK: update for the new SDK
Change the adapter to add the requested SDK to the target’s build
inputs. Note that only the “11.0” (i.e., 11.3) and 12.3 SDKs are
supported. This adapter is retained for compatibility. The preferred way
to override the SDK is to add it to the appropriate inputs directly.
2024-10-10 16:23:08 -04:00
Randy Eckenrode
1c26a2fabc makeStaticDarwin: handle when env.NIX_CFLAGS_LINK is set 2024-10-10 16:23:08 -04:00
Randy Eckenrode
66fcbb94e7 makeStaticDarwin: drop darwin-portable-libSystem-hook
`${stdenv.cc.libc}/lib/libSystem.B.dylib` does not exist and not existed
for as long as I have used nixpkgs. Since `/usr/lib/libSystem.B.dylib`
is already linked via text-based stubs, continue relying on those.
2024-10-10 16:23:08 -04:00
Randy Eckenrode
b7442b9066 darwin.stdenv: provide an SDK when cross-compiling
Static can rely on the standard cross-SDK because it will be a static
SDK when building for static targets.
2024-10-10 16:23:04 -04:00
Azat Bahawi
e8f0b7b782 stdenv: throw when using mold for targeting darwin
Mold does not support linking Mach-O, but still can be used on MacOS to
emit ELF.

Fixes: #338970
2024-09-02 13:59:59 +03:00
adisbladis
f4579bdf8d stdenv: Fix args.env.NIX_CFLAGS_LINK/args.NIX_CFLAGS_LINK typo 2024-08-07 18:49:56 +12:00
adisbladis
00b9996c9a stdenv: Take nested env.NIX_CFLAGS_LINK into account when making static binaries
https://github.com/NixOS/nixpkgs/pull/315998/files#diff-2828f66a476875b1160e3c241960db085c2a3933211cc187bcd1fb456fb95e7fL213-R216 moved NIX_CFLAGS_LINK from a top-level `mkDerivation` argument to the nested `env` attribute.

This doesn't play nicely with how `stdenv/adapters.nix` adds it's NIX_CFLAGS_LINK in the top-level.

This changes the stdenv adapter to check for the presence of `env.NIX_CFLAGS_LINK`, and override that one if present, and only otherwise override on the top-level drv attrset.
2024-08-03 23:26:42 +12:00
John Ericson
744d7e7477 *bsdCross: Remove these package sets
I realized what rhelmot did in 61202561d9
(specify what packages just need `stdenvNoLibc`) is definitely the right
approach for this, and adjusted NetBSD and OpenBSD to likewise use it.
With that change, we don't need these confusing and ugly `*bsdCross`
package sets at all!

We can get rid of a lot more libc-related `*Cross`, and I will do so
soon, but this is the first step.

(adapted from commit 51f1ecaa59)
2024-06-21 11:47:36 -04:00
Vladimír Čunát
879821772c Revert #320852: Clean up cross bootstrapping
It rebuilt stdenv on *-darwin; we can't do that in nixpkgs master.
This reverts commit 2f20501c5f, reversing
changes made to fd469c24af.
2024-06-21 07:48:24 +02:00
John Ericson
51f1ecaa59 Clean up cross bootstrapping
For a long time, we've had `crossLibcStdenv`, `*Cross` libc attributes,
and `*bsdCross` pre-libc package sets. This was always bad because
having "cross" things is "not declarative": the naming doesn't reflect
what packages *need* but rather how we *provide* something. This is
ugly, and creates needless friction between cross and native building.

Now, almost all of these `*Cross` attributes are gone: just these are
kept:

- Glibc's and Musl's are kept, because those packages are widely used
  and I didn't want to risk changing the native builds of those at this
  time.

- generic `libcCross`, `theadsCross`, and friends, because these relate
  to the convolulted GCC bootstrap which still needs to be redone.

The BSD and obscure Linux or freestnanding libcs have conversely all
been made to use a new `stdenvNoLibc`, which is like the old
`crossLibcStdenv` except:

1. It usable for native and cross alike

2. It named according to what it *is* ("a standard environment without
   libc but with a C compiler"), rather than some non-compositional
   jargon ("the stdenv used for building libc when cross compiling",
   yuck).

I should have done this change long ago, but I was stymied because of
"infinite recursions". The problem was that in too many cases we are
overriding `stdenv` to *remove* things we don't need, and this risks
cyles since those more minimal stdenvs are used to build things in the
more maximal stdenvs.

The solution is to pass `stage.nix` `stdenvNoCC`, so we can override to
*build up* rather than *tear down*. For now, the full `stdenv` is also
passed, so I don't need to change the native bootstraps, but I can see
this changing as we make things more uniform and clean those up.

Finally, the BSDs also had to be cleaned up, since they have a few
pre-libc dependencies, demanding a systematic approach. I realized what
rhelmot did in 61202561d9 (specify what
packages just need `stdenvNoLibc`) is definitely the right approach for
this, and adjusted NetBSD and OpenBSD to likewise use it.
2024-06-18 17:04:16 -04:00
Randy Eckenrode
f61e189ad3 overrideSDK: support all deps attributes
This is effectively a rewrite of `overrideSDK`. It was required because
`wrapGAppsHook` propagates `depsTargetTarget` with the expectation that
it will effectively be `buildInputs` when the hook is itself used as a
`nativeBuildInput`. This propagates Gtk, which itself propagates the
default Dariwn SDK, making it effectively impossible to override the SDK
when a package depends on Gtk and uses `wrapGAppsHook`.

This rewrite implements the following improvements:

* Cross-compilation should be supported correctly (untested);
* Supports public and private frameworks;
* Supports SDK `libs`;
* Remaps instead of replacing extra (native) build inputs in the stdenv;
* Updates any Darwin framework references in `nix-support`; and
* It updates `xcodebuild` regardless of which input its in.

The implementation avoids recursion for performance reasons. Instead, it
enumerates transitive dependencies and walks the list from the leaf
packages backwards to the parent packages.
2024-03-29 10:03:08 -04:00
Robert Hensing
8f6b396c49 Merge pull request #297711 from hercules-ci/rename-adapters-finalAttrs
pkgs/stdenv/adapters.nix: Rename internal name
2024-03-21 17:15:28 +01:00
Robert Hensing
8da01484cd pkgs/stdenv/adapters.nix: Rename internal name
`finalAttrs` is never the first argument. This should have been
called `prevAttrs` all along.
It confused me for a bit, because the callback _must not_ be strict
in `finalAttrs` (the first of _two_ parameters), or it will
recurse infinitely while trying to figure out what the attrNames are.
2024-03-21 13:51:50 +01:00
github-actions[bot]
36232fff71 Merge master into staging-next 2024-03-20 18:01:02 +00:00
Connor Baker
e871fcf859 stdenvAdapters.useLibsFrom: use targetStdenv.cc.override
As @SomeoneSerge pointed out in https://github.com/NixOS/nixpkgs/pull/281371#discussion_r1531174155,
by avoiding `wrapCCWith` and using `targetStdenv.cc.override`, we avoid roundtrip wrapping and
are able to use `coreutils` from `targetStdenv`.
2024-03-20 16:02:08 +00:00
github-actions[bot]
c160165e60 Merge master into staging-next 2024-03-14 18:01:26 +00:00
Robert Hensing
de516f6f13 make-derivation.nix: Return mkDerivation as an attribute 2024-03-11 17:06:02 +01:00
a-n-n-a-l-e-e
ce789e7e35 llvmPackages_{12,13,14,15,16,17,git}.{libcxx,libcxxabi}: merge libcxxabi into libcxx (#292043)
- merge libcxxabi into libcxx for LLVM 12, 13, 14, 15, 16, 17, and git.
- remove the link time workaround `-lc++ -lc++abi` from 58 packages as it is no longer required.
- fixes https://github.com/NixOS/nixpkgs/issues/166205
- provides alternative fixes for. https://github.com/NixOS/nixpkgs/issues/269548 https://github.com/NixOS/nix/issues/9640
- pkgsCross.x86_64-freebsd builds work again

This change can be represented in 3 stages
1. merge libcxxabi into libcxx -- files: pkgs/development/compilers/llvm/[12, git]/{libcxx, libcxxabi}
2. update stdenv to account for merge -- files: stdenv.{adapters, cc.wrapper, darwin}
3. remove all references to libcxxabi outside of llvm (about 58 packages modified)

### merging libcxxabi into libcxx
- take the union of the libcxxabi and libcxx cmake flags
- eliminate the libcxx-headers-only package - it was only needed to break libcxx <-> libcxxabi circular dependency
- libcxx.cxxabi is removed. external cxxabi (freebsd) will symlink headers / libs into libcxx.
- darwin will re-export the libcxxabi symbols into libcxx so linking `-lc++` is sufficient.
- linux/freebsd `libc++.so` is a linker script `LINK(libc++.so.1, -lc++abi)` making `-lc++` sufficient.
- libcxx/default.nix [12, 17] are identical except for patches and `LIBCXX_ADDITIONAL_LIBRARIES` (only used in 16+)
- git/libcxx/defaul.nix  does not link with -nostdlib when useLLVM is true so flag is removed. this is not much different than before as libcxxabi used -nostdlib where libcxx did not, so libc was linked in anyway.

### stdenv changes
- darwin bootstrap, remove references to libcxxabi and cxxabi
- cc-wrapper: remove c++ link workaround when libcxx.cxxabi doesn't exist (still exists for LLVM pre 12)
- adapter: update overrideLibcxx to account for a pkgs.stdenv that only has libcxx

### 58 package updates
- remove `NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}` as no longer needed
- swift, nodejs_v8 remove libcxxabi references in the clang override

https://github.com/NixOS/nixpkgs/pull/292043
2024-03-11 03:53:37 -07:00
Someone Serge
e6e279913c stdenvAdapters.useLibsFrom: init 2024-01-12 17:38:00 +00:00
Weijia Wang
2f9e98ccf3 Merge branch 'master' into staging-next 2024-01-10 23:12:44 +01:00
Sergei Trofimovich
55249c817f stdenv.adapters: fixx overrideLibcxx to refer to existing compiler-rt
Before the change `pkgsLLVM` attributes were failing to pull in
`compiler-rt` on `x86_64-linux`:

    $ nix build --no-link -f. pkgsLLVM.asciidoc-full
    error:
       error: attribute 'llvmPackages_13' missing

       at pkgs/stdenv/adapters.nix:86:32:

           85|       inherit libcxx;
           86|       extraPackages = [ cxxabi pkgs.pkgsTargetTarget."llvmPackages_${lib.versions.major llvmLibcxxVersion}".compiler-rt ];
             |                                ^
           87|     });

It happens because `pkgs.pkgsTargetTarget` are always empty for
cross-packages like `pkgsLLVM.`, `pkgsCross.*.` or
`--arg crossSystem '...'`.
2024-01-07 22:11:49 +00:00
Robert Scott
dc2247a3b5 stdenvAdapters: add withDefaultHardeningFlags 2023-12-09 16:32:15 +00:00
Weijia Wang
023d20ae64 Merge pull request #265307 from reckenrode/clang16-fixes-batch2
rubyPackages.iconv, v8: fix build with clang 16
2023-11-04 17:14:36 +01:00
Randy Eckenrode
98b8d3474b stdenvAdapters.overrideSDK: special case the 10.12 Libsystem
The 10.12 Libsystem is not located as a sub-attribute of
`darwin.apple_sdk_10_12`. This will be fixed as part of the SDK changes
planned for post-23.11. In the meantime, special case it so the adapter
can be used to change the deployment target.
2023-11-04 01:47:58 -04:00
Randy Eckenrode
cc4fcc147b stdenvAdapters: add overrideLibcxx
This was taken from #264091 to use in the interim before that PR lands
(sometime after the release of 23.11). It allows different versions of
clang to link the same libc++, allowing dependencies to be linked when
they are built with a different version of clang than the stdenv.
2023-11-03 23:11:32 -04:00
Randy Eckenrode
08e1c95e9c stdenvAdapters.overrideSDK: handle non-drv nativeBuildInputs 2023-11-01 12:30:26 -04:00