Skip to content

treewide: Fix Meson CPU names for powerpc CPUs#13514

Merged
xokdvium merged 1 commit intoNixOS:masterfrom
OPNA2608:fix/meson-powerpc-cpu-names
Jul 21, 2025
Merged

treewide: Fix Meson CPU names for powerpc CPUs#13514
xokdvium merged 1 commit intoNixOS:masterfrom
OPNA2608:fix/meson-powerpc-cpu-names

Conversation

@OPNA2608
Copy link
Contributor

(Still building on my machine, will undraft when it finishes & builtins.currentSystem returns the correct value)

Motivation

Meson's cpu_family() function returns ppc* on POWER systems, while Nixpkgs expects the previously-used powerpc* to be the CPU name:

puna@HC ~/D/nixpkgs (wip/ppc64-elfv1)> nix repl --file .
Nix 2.28.4
Type :? for help.
error:
       … while evaluating a branch condition
         at /home/puna/Development/nixpkgs/pkgs/stdenv/booter.nix:68:9:
           67|         pred: n:
           68|         if n == len then
             |         ^
           69|           rnul pred

       … while calling the 'length' builtin
         at /home/puna/Development/nixpkgs/pkgs/stdenv/booter.nix:65:13:
           64|     let
           65|       len = builtins.length list;
             |             ^
           66|       go =

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: Unknown CPU type: ppc64

Fix this discrepancy.

Context

Closes #12769

No real experience with Meson, so happy about better-looking suggestions.


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@OPNA2608 OPNA2608 force-pushed the fix/meson-powerpc-cpu-names branch from e57fa7b to ec3747f Compare July 21, 2025 12:14
@xokdvium xokdvium marked this pull request as ready for review July 21, 2025 12:15
@xokdvium xokdvium requested a review from Ericson2314 as a code owner July 21, 2025 12:15
@OPNA2608
Copy link
Contributor Author

OPNA2608 commented Jul 21, 2025

Gives me lots of errors like this when trying to run the tests:

this derivation will be built:
  /build/nix-test/main/optimise-store/store/v3f4rsnzwic866sr81m41x3jzzdzxbmh-foo1.drv
error: a 'ppc64-linux' with features {} is required to build '/build/nix-test/main/optimise-store/store/v3f4rsnzwic866sr81m41x3jzzdzxbmh-foo1.drv', but I am a 'powerpc64-linux' with features {benchmark, big-parallel, nixos-test, uid-range}

So this call prolly also needs to be fixed:

'system': host_machine.cpu_family() + '-' + host_machine.system(),

I assume I can just move default_nix_local_system_cpu to a higher-level meson.build and reference it in multiple lower-level places, so I'll try that.

Edit: Well, this turned out abit is less pretty than I was hoping…

@OPNA2608 OPNA2608 force-pushed the fix/meson-powerpc-cpu-names branch from ec3747f to 714d40b Compare July 21, 2025 16:28
@OPNA2608 OPNA2608 requested a review from edolstra as a code owner July 21, 2025 16:28
@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Jul 21, 2025
@OPNA2608 OPNA2608 changed the title src/libstore/meson.build: Fix CPU names for powerpc CPUs meson.build: Fix CPU names for powerpc CPUs Jul 21, 2025
@OPNA2608 OPNA2608 force-pushed the fix/meson-powerpc-cpu-names branch from 714d40b to 1767644 Compare July 21, 2025 16:45
@OPNA2608 OPNA2608 changed the title meson.build: Fix CPU names for powerpc CPUs treewide: Fix Meson CPU names for powerpc CPUs Jul 21, 2025
@OPNA2608
Copy link
Contributor Author

Oh, do the subprojects get built directly without going through the main meson.build as well? Hmm… Copy-pasting it is then :s.

@xokdvium

This comment was marked as resolved.

@OPNA2608 OPNA2608 force-pushed the fix/meson-powerpc-cpu-names branch from 1767644 to d2dd465 Compare July 21, 2025 17:01
@OPNA2608 OPNA2608 force-pushed the fix/meson-powerpc-cpu-names branch from d2dd465 to 6db6190 Compare July 21, 2025 17:04
@xokdvium
Copy link
Contributor

@OPNA2608, which nixpkgs revision and what powerpc target triple can I use to build this? Are you using cross?

@OPNA2608
Copy link
Contributor Author

I'm working on bootstrapping ELFv1 ppc64 & fixing big-endian and ABI issues with packages. I have this branch in my Nixpkgs fork with all my changes so far applied so I can continue testing builds while changes slowly work their way into Nixpkgs.

I'm currently on OPNA2608/nixpkgs@c879d60 using the ppc64-elfv1 config in lib.systems.examples - which is powerpc64-unknown-linux-gnuabielfv1. Using just powerpc64-linux will currently go with the ELFv2 ABI which might work as well, though I haven't really tested it.

I'm using an old POWER machine, so not cross. I had to cross-compiled a Nix installer from x86_64 a long while ago, everything else has been built natively.

@xokdvium
Copy link
Contributor

ELFv2 ABI which might work as well

Openssl cross doesn't seem to work there. I'll give your branch a shot for cross, but it's a pretty huge rebuild.

With these changes nix builds (modulo AWS) and tests pass on powerpc64-unknown-linux-gnuabielfv1 natively for you, right?

@xokdvium xokdvium added backport 2.28-maintenance Automatically creates a PR against the branch backport 2.29-maintenance Automatically creates a PR against the branch backport 2.30-maintenance Automatically creates a PR against the branch labels Jul 21, 2025
@xokdvium
Copy link
Contributor

Alright, so with your branch I was able to build cross nix with the patch:

diff --git a/flake.nix b/flake.nix
index 2b93429e9..c08a5f5fe 100644
--- a/flake.nix
+++ b/flake.nix
@@ -54,6 +54,7 @@
         # "x86_64-unknown-netbsd"
         "x86_64-unknown-freebsd"
         "x86_64-w64-mingw32"
+        "powerpc64-unknown-linux-gnuabielfv1"
       ];
 
       stdenvs = [

And your original command works:

nix build .\#nix-cli-powerpc64-unknown-linux-gnuabielfv1 -L --override-input nixpkgs github:OPNA2608/nixpkgs/c879d608e311bf02b06b62b96f89bb6cbb53386d
qemu-ppc64 result/bin/nix eval --file ../nixpkgs hello

@OPNA2608
Copy link
Contributor Author

nix builds (modulo AWS) and tests pass on powerpc64-unknown-linux-gnuabielfv1 natively for you, right?

One of the earlier iterations previously built with passing tests. Currently checking the latest one juuust to make sure, but I think the previous one just had the obsolete default_nix_local_system_cpu block, so I expect it to still be passing.

@OPNA2608
Copy link
Contributor Author

checking for references to /build/ in /nix/store/rc7jxky02ps4gp8bfv9xk7jmqvpjx9gh-nix-2.28.4-doc...
patching script interpreter paths in /nix/store/rc7jxky02ps4gp8bfv9xk7jmqvpjx9gh-nix-2.28.4-doc
/nix/store/lss2pmn2ilvypz28mnfkpsxxzl43a368-nix-2.28.4
puna@HC ~/D/nixpkgs (wip/ppc64-elfv1)> /nix/store/lss2pmn2ilvypz28mnfkpsxxzl43a368-nix-2.28.4/bin/nix-instantiate --eval --strict --expr 'builtins.currentSystem'
"powerpc64-linux"
puna@HC ~/D/nixpkgs (wip/ppc64-elfv1)>

Seems fine!

@xokdvium
Copy link
Contributor

Seems fine!

Thanks @OPNA2608. I'll backport this up to 2.28, so that the default nix version in nixpkgs has this fix.

@xokdvium xokdvium merged commit e2b0ff1 into NixOS:master Jul 21, 2025
13 checks passed
mergify bot added a commit that referenced this pull request Jul 21, 2025
…3514

treewide: Fix Meson CPU names for powerpc CPUs (backport #13514)
mergify bot added a commit that referenced this pull request Jul 21, 2025
…3514

treewide: Fix Meson CPU names for powerpc CPUs (backport #13514)
mergify bot added a commit that referenced this pull request Jul 21, 2025
…3514

treewide: Fix Meson CPU names for powerpc CPUs (backport #13514)
@xokdvium
Copy link
Contributor

Argh, I didn't look at the meson docs hard enough. ppcle isn't a thing there, you'd need to check the .endian(). This should be correct #13520.

@OPNA2608
Copy link
Contributor Author

OPNA2608 commented Jul 27, 2025

ppcle isn't a thing there, you'd need to check the .endian().

So funny thing: In Nixpkgs, under cross, it actually is a thing. I imagine due to a similar misunderstanding of these details (or just lack of interest/testing).

https://github.com/NixOS/nixpkgs/blob/bec36361e29d8512853ee488fbccc6874a395200/pkgs/build-support/lib/meson.nix#L6-L15

When targeting POWER via cross, the cross file for Meson will be set up to use stdenv.hostPlatform.uname.processor. So:

puna@Carlos:~/Development/nixpkgs
↪ nix-instantiate --eval --strict --expr 'with import ./. { crossSystem = "powerpcle-linux"; }; stdenv.hostPlatform.uname.processor'
"ppcle"

puna@Carlos:~/Development/nixpkgs
↪ nix-instantiate --eval --strict --expr 'with import ./. { crossSystem = "powerpc64le-linux"; }; stdenv.hostPlatform.uname.processor'
"ppc64le"

Oops! I'll submit a PR there to add special handling for POWER targets.

@xokdvium
Copy link
Contributor

Ah this is a mess. Funny thing is that MIPS does the right thing in nixpkgs.

lf- pushed a commit to lix-project/lix that referenced this pull request Jul 29, 2025
Nixpkgs expects the `builtin.currentSystem` for POWER CPUs to be:

`powerpc[64][le]-linux`

But using `host_machine.cpu_family()` for the CPU part of the system
string on POWER produces this instead:

`ppc[64]-linux`

So evaluating Nixpkgs errors out on:

`error: Unknown CPU type: ppc64`

To fix this, change
`ppc` -> `powerpc`
`ppc64` -> `powerpc64`
and append `le` if `host_machine.endian() == 'little'`.

I can't actually test this on hardware rn due to hitting a kernel bug
on the host system when linking big things[1], but the approach here
is similar to how it was fixed in cppnix[2][3], so it *should* be fine.

[1] https://git.adelielinux.org/adelie/packages/-/issues/1315
[2] NixOS/nix#13514
[3] NixOS/nix#13520

Change-Id: Ib82839cdaf2198bf18b89e82caaa1217f88e11ed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 2.28-maintenance Automatically creates a PR against the branch backport 2.29-maintenance Automatically creates a PR against the branch backport 2.30-maintenance Automatically creates a PR against the branch with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

after moving to meson build no longer possible to build on ppc64le host

2 participants