Commit Graph

184 Commits

Author SHA1 Message Date
John Ericson
33589cc0c6 lib/systems: derive more platform metadata instead of restating it
`examples.nix` had settings that only repeated what the `config` already
implied. They read as if the platform were special, when it ought to be
the default. Now the default logic in `default.nix` ought to handle the
setting in question in a rule-based way so it is.

 Change:

- `useLLVM` now covers
  - UEFI
  - MSVC CRT and C++ ABI
  - Windows on AArch64 as well as FreeBSD and OpenBSD

- `libc` gains a UEFI case

hat retires seven `useLLVM` settings, eighteen `libc = "newlib"`, one
`libc = "bionic"`, and the `libc`/`linker` pair on the UEFI examples.

The remaining `libc`s in examples now means"this differs from what the
triple implies", which is true of the seven left: `newlib-nano`, the
mingw `msvcrt`/`ucrt` pairs those entries exist to distinguish, and
`mmix`, whose OS is `mmixware` rather than `none` so the bare-metal
default does not reach it. That one gains a comment.

No functional change. Elaborating all 87 platforms in
`lib.systems.examples` before and after gives byte-identical `config`,
`system`, `useLLVM`, `useGccNG`, `libc`, `linker` and
`rust.rustcTarget`. `mmix` surfaced that way, having regressed to
`native/impure`.

Assisted-by: Claude Code (Claude Opus 5)
2026-08-12 19:38:22 -04:00
John Ericson
92144940a3 gcc/ng: let a platform opt in with useGccNG
Nothing could select the split GCC package set, so none of the fixes
below this commit were reachable from a normal build.

Add `useGccNG` alongside the existing `useLLVM`/`useZig`/`useArocc`
choices, and honour it where a compiler is picked: the cross stdenv takes
`gccNGPackages.gcc`, and `stdenvNoLibs`/`stdenvNoLibc` map to
`gccNoLibgcc` and `gccWithLibgcc`. That last pair is the point of the
split. Both currently fall back to `gccCrossLibcStdenv`, because the
monolithic compiler cannot distinguish them; `lib/systems/default.nix`
says as much next to `linker`, noting that we would like to choose the C
compiler and runtime library orthogonally but "due to the monolithic GCC
build we cannot actually make those choices independently". This is what
lifts that, the way the LLVM set already splits `clangNoCompilerRt` from
`clangNoLibc`.

`gccNGPackages` tracks `default-gcc-version` rather than naming a
release, so the split set and the monolithic `gcc` stay on the same one.

`useGccNG` defaults to `false` and no platform derives it, so no existing
build changes. Setting it on a platform spec is enough to exercise the
whole stack:

    nix-build . -A stdenv.cc --arg crossSystem \
      '{ config = "aarch64-unknown-linux-musl"; useGccNG = true; }'

The intent is to switch obscure low-tier platforms over to it soon --
NetBSD first -- so `ng` gets dogfooded somewhere the blast radius is
small. Those switches come separately.

Assisted-by: Claude Code (Claude Opus 5)
2026-08-12 16:46:18 -04:00
Artemis Tosini
c41cd7fd36 lib.systems: add GOARCH for big-endian mips64 (#539363) 2026-08-03 15:19:39 +00:00
·𐑑𐑴𐑕𐑑𐑩𐑤
5241238f68 lib/systems: add picolibc 2026-07-28 22:33:36 -07:00
Sam Pointon
629b4ee093 systems: rename extant wasi targets to wasip1
Wasi P2 is different enough to Wasi P1 to warrant being treated entirely 
separately, rather than as two minor variants of the same thing. P3 will 
likewise want to be a different target.

I've left aliases in place; maybe eventually, those can be deprecated 
and removed. I've tested this, but it's possible there might be breakage 
somewhere (e.g., the canonical doubles for P1 have changed, though I 
can't imagine why anyone would rely on that).

Fixes https://github.com/NixOS/nixpkgs/issues/435954
2026-07-28 19:50:03 +01:00
Amaan Qureshi
7e81743aa6 lib.systems: add GOARCH for big-endian mips64 2026-07-07 15:30:40 -04:00
Matt Sturgeon
437220a111 lib/systems: gate linux-kernel assertion behind oldestSupportedRelease (#532194) 2026-06-17 11:44:55 +00:00
Matt Sturgeon
f5f59e0c4a lib/systems: gate linux-kernel assertion behind oldestSupportedRelease
A platform elaborated by another supported revision of Nixpkgs would
trip the assertion when it is re-elaborated.

Avoid this, by checking `oldestSupportedReleaseIsAtLeast 2511`, as 25.11
is the version that stopped adding `linux-kernel` to elaborated systems.
2026-06-16 06:43:14 +01:00
Sam Pointon
4a3079eda3 systems: set rust.platform.env as rustc does
rustc allows code to perform compile-time tests against target_env [0], 
which is a function of the target triple. There isn't provision in 
Nixpkgs for learning target_env, however. That doesn't affect rustc's 
evaluation of cfg guards in Rust code - rustc knows perfectly well what 
target_env is - but it _does_ affect the env vars passed to a build 
script set by buildRustCrate, which is presently hard-coded to gnu, and 
also affects any Nix code looking to branch on target_env.

Being able to access target_env is very relevant to, for example, WASI 
as (using Rust terminology) wasm32-wasip1 and wasm32-wasip2 differ only 
by target_env, with identical target_arch and target_os values. Properly 
reflecting target_env may also fix some random musl issues if you're a 
bit lucky.

This commit adds a new attr, rust.platform.env, which reflects the 
target_env that rustc will set for the target, and wires it up in 
buildRustCrate. In isolation, this change mostly only affects build 
scripts checking target_env, but crate2nix will greatly benefit from 
being able to accurately resolve the dep graph (which can also vary 
depending on target_env).

The target triple -> target_env function resists Kolmogorov compression: 
it's irregular and, though there are some patterns, there are lots of 
special cases. So, I have done the stupidest possible thing and scraped 
out all of the targets with non-empty target_env values and dumped that 
into an attrset. This attrset will progressively get out of date as 
rustc adds new platforms, but updating it should be simple enough - I've 
included the generation script as a comment.

There are some other configuration options not being reflected in Nix. I 
have left those alone, but, in the future, maybe this can be extended to 
just dumping all of them into an attrset and then reflecting them in 
rust.platform. It might even make sense to convert the existing code 
producing rust.platform to just looking up from an attrset and to 'do 
what rustc does'.

I would have liked to have added a test targetting a platform with a 
non-empty non-GNU target_env, but all of the yaks were quite hairy.

Fixes https://github.com/NixOS/nixpkgs/issues/436832

[0]: https://doc.rust-lang.org/reference/conditional-compilation.html#r-cfg.target_env
2026-06-15 16:21:13 +01:00
Emily
31d1d80b3f lib/systems: move kernel configuration out of the platform structure
Currently, you need to override `stdenv.hostPlatform` to request a
compressed kernel on AArch64, and the kernel configuration is split
between the central structured configuration and string snippets in
platform definitions. This has consequently made the latter bitrot
terribly. Since the platform‐specific logic is now very limited after
cleaning up the detritus, we can move it into the kernel derivation
and expose the relevant configuration there for anyone who wants to
customize it further or needs to read it out.

Co-authored-by: zowoq <59103226+zowoq@users.noreply.github.com>
2026-06-10 11:17:38 +10:00
Emily
ba777b3b20 lib.systems.equals: fix euqality on re-elaborated platform (#521043) 2026-05-16 18:39:00 +00:00
Mix
cadca751c4 lib.systems.equals: fix euqality on re-elaborated platform 2026-05-17 02:14:48 +08:00
adisbladis
5a4597cc83 lib.systems: foldl -> foldl' 2026-05-16 15:51:29 +12:00
Emily
036199b38a lib.systems.equals: only filter functions once (#513844) 2026-05-13 00:56:58 +00:00
eveeifyeve
a8f0a99212 nim: deprecate and move os and cpu to stdenv.targetPlatform.nim
This change makes it more accesssable to using nim cpu and os without
referencing nim.
2026-05-06 22:29:23 +10:00
Eman Resu
833f05d099 lib.systems.elaborate: prevent unnecessary attrset merges 2026-05-03 08:04:34 -04:00
Eman Resu
a9c0a094f7 lib.systems.elaborate: avoid optionalAttrs merge 2026-05-03 08:04:34 -04:00
Eman Resu
0f0f29fcf1 lib/systems: store version of elaborated system without functions 2026-04-26 23:56:51 -04:00
Eman Resu
590d99ed5f lib/systems: remove old isCompatible 2026-04-26 22:14:48 -04:00
Ben Siraphob
0fcb031c25 lib/systems: add SH4 (SuperH) cross-compilation target
Add sh4 CPU type (32-bit, little-endian, family "sh"), isSh4 predicate,
"sh4-linux" system double, cross-compilation example (sh4-unknown-linux-gnu),
linuxArch mapping to "sh", and test entry.
2026-04-20 13:02:20 -07:00
zimbatm
03b9d66f3d lib.systems.equals: use lib imports instead of builtins
Use lib.filter and lib.attrNames instead of builtins.* directly,
consistent with the rest of the file's style.

Follow-up to #506588, incorporating review feedback from #507232.
2026-04-06 18:53:16 +02:00
zimbatm
878a387240 lib.systems.equals: optimize removeFunctions
Replace filterAttrs + lib.isFunction with removeAttrs + builtins.filter
+ builtins.isFunction. System attrs are never __functor-style attrsets,
so lib.isFunction's wrapper is unnecessary overhead. The double negation
(!pred ∘ !isFunction) also cancels out.

NIX_SHOW_STATS delta on hello.drvPath:

  nrFunctionCalls:  229,883 -> 154,411   (-32.8%)
  envs.number:      250,215 -> 174,743   (-30.2%)
  envs.bytes:         4.6M -> 3.4M       (-26.4%)
  nrAvoided:        291,314 -> 216,054   (-25.8%)
  gc.totalBytes:     49.7M -> 48.5M      (-2.4%)

Repro:

  NIX_SHOW_STATS=1 nix-instantiate --eval \
    -E '(import ./. {}).hello.drvPath' 2>stats.json >/dev/null
  jq . stats.json
2026-04-04 14:19:54 +02:00
Amaan Qureshi
e0801cae76 lib/systems: fix qemuArch for aarch64_be
`qemuArch` returned "aarch64" for both LE and BE, causing binfmt to
register `qemu-aarch64` for `aarch64_be` binaries. QEMU ships separate
`qemu-aarch64` and `qemu-aarch64_be` binaries, so the wrong interpreter
was used, failing with "Invalid ELF image for this architecture".

Since QEMU distinguishes endianness in the binary name, this adds the
"_be" suffix via `isBigEndian`, which is similar to the approach MIPS 
uses a few lines below.
2026-03-16 23:49:50 -04:00
dramforever
60ac986e49 lib.systems: rust: Make rustcTargetSpec the primary entrypoint
Make rustcTargetSpec the primary entrypoint for setting a custom target,
and wire up all the other stuff so they are hopefully as working and as
broken as before.

In particular, to specify a custom target, the user now just specifies
rust.rustcTargetSpec. rust.platform and rust.cargoShortTarget are
populated from rust.rustcTargetSpec now. In addition, rust.rustcTarget
defaults to rust.cargoShortTarget. (rust.rustcTarget and
rust.cargoShortTarget really should always be the same, but I think we
can deal with that later).

This allows the user to more easily control the basename of
rust.rustcTargetSpec by passing e.g.
"${./rust}/mips64el_mips3-unknown-linux-gnuabi64.json", which allows
cc-rs and in turn std to work.
2026-02-27 13:34:31 +08:00
dramforever
550a1b8eb5 lib.systems: Refactor rust.platform generation
In preparation for a future commit, refactor rust.platform somewhat.

No functional changes intended. Most of the diff here is whitespace
changes.
2026-02-25 11:18:23 +08:00
Alexandre Esteves
4255fb08c9 lib.systems: fix path to wine executable 2026-02-10 20:16:44 +00:00
Alexandre Esteves
03a5813e98 lib/systems: Add nodejs as emulator for pkgsCross.ghcjs 2026-01-25 23:16:19 +00:00
aleksana
38be8c6c9b lib.systems: correct and simplify canExecute condition regarding march 2026-01-13 18:44:51 +08:00
nixpkgs-ci[bot]
584512ec5c Merge staging-next into staging 2025-10-25 12:06:42 +00:00
OPNA2608
8b06bf875c lib.systems: Simplify ABI on POWER for rust.rustcTarget
Rust does not know how to parse "gnuabielfv{1,2}", so simplify those down to just "gnu".
This obsoletes the manual rustcTarget fix in the ppc64-elfv1 example.
2025-10-11 20:48:52 +02:00
Randy Eckenrode
2ab175889a lib.systems.darwinMinVersion: 11.3 -> 14.0 2025-10-09 18:23:26 -04:00
Randy Eckenrode
cf45eef8ec lib.systems.darwinSdkVersion: 11.3 -> 14.4 2025-10-09 18:23:26 -04:00
Philip Taron
44998896c6 lib: remove optional builtins prefixes from prelude functions (#447402) 2025-09-30 16:28:04 +00:00
NAHO
6177c4ad72 lib: 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 . lib --exec-batch sed --in-place --regexp-extended "
      s/\<builtins\.($(
        printf '%s\n' "${builtins[@]}" |
          paste --delimiter '|' --serial -
      ))\>/\1/g
    "

    nix fmt
2025-09-30 09:02:59 +02:00
David McFarland
39fd8e4adf cygwin: init as a target toolchain
The old cygwin support used -pc-windows-cygnus as the config.  This is
supported by LLVM, but not by GNU. This will change it to -pc-cygwin,
which is more generally supported.

Because the kernel is now 'cygwin' rather than 'windows', isWindows will
return false. There are lots of different reasons isWindows is used in
nixpkgs, but in my experience they often have to do with posix
compatibility and don't apply to cygwin.

Co-authored-by: Brian McKenna <brian@brianmckenna.org>
2025-09-27 13:29:44 -03:00
nixpkgs-ci[bot]
c0dd2454fa Merge staging-next into staging 2025-08-01 00:21:45 +00:00
Ross Smyth
4af7c6bdee lib.systems: Add examples & helpers for MSVC 2025-07-31 11:41:15 -04:00
Wolfgang Walther
90604d95bc Merge branch 'staging-next' into staging 2025-07-24 14:33:09 +02:00
Wolfgang Walther
5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
Colin
b3daf8c3a5 nodejs: split destCPU into stdenv.$platform.node
this architecture mapping is used broadly in the node ecosystem.
an assortment of tools and hooks, like buildNpmPackage or
pnpm.configHook, will benefit from reusing these values. placing them in
stdenv makes sense because (1) several of these tools don't currently
depend on nodejs, and may even be available where nodejs is not and (2)
`stdenv.{build,host,target}Platform` seems to be less error-prone than
`pkgs*.nodejs.{os,arch}` -- especially for setup hooks where the offsets
are shifted.
2025-07-07 03:07:58 +00:00
Alyssa Ross
f4c841ae5e lib.systems: don't throw if go unsupported
Better to have a value that can actually be checked for, rather than
throwing, so optional Go support can be disabled when unsupported.
2025-05-30 14:57:33 +02:00
Gutyina Gergő
b3b0fd266b lib: prefer replaceString over replaceStrings 2025-05-28 00:20:57 +02:00
Aleksana
b2fc900a32 lib.systems.elaborate.canExecute: handle different gcc.arch (#403549) 2025-05-23 09:59:10 +08:00
aleksana
1802f697e4 lib.systems.elaborate.canExecute: handle different gcc.arch 2025-05-22 18:57:28 +08:00
Morgan Jones
9d3c069cbd lib/systems: remove android cruft
These used legacy names for Android SDK and NDK versions, so now we can
do away with them.
2025-05-12 23:43:16 -07:00
aleksana
e1828f9668 lib.systems: add golang platform dialect 2025-04-30 22:05:32 +08:00
zowoq
0931f4e861 Revert "pkgs/top-level/stage.nix: add pkgsLLVMLibc"
This reverts commit 41b14024d2.
2025-04-24 14:04:25 +10:00
Alyssa Ross
904b79c696 lib.systems: force qemuArch to "aarch64" on aarch64
qemu architecture names are fixed — we're using uname here just
because it's more likely to be correct than CPU name (see e.g. POWER).
This means that aarch64 is always called aarch64, even on Darwin where
uname reports arm64.

Fixes: 61582c7043 ("lib/systems: use Darwin architecture names for `config` and `uname`")
2025-04-11 10:32:19 +02:00
Emily
61582c7043 lib/systems: use Darwin architecture names for config and uname
`aarch64-apple-darwin` no longer works with LLVM 20.
2025-04-02 21:22:47 +01:00
Silvan Mosberger
e52d633a63 Merge remote-tracking branch 'upstream/staging-next' into staging 2025-04-02 18:30:54 +02:00