Skip to content

ghostty: limit the amount of build cores#446056

Merged
Mic92 merged 1 commit intoNixOS:masterfrom
pluiedev:pluie/jj-wvossqnpmvpy
Sep 26, 2025
Merged

ghostty: limit the amount of build cores#446056
Mic92 merged 1 commit intoNixOS:masterfrom
pluiedev:pluie/jj-wvossqnpmvpy

Conversation

@pluiedev
Copy link
Copy Markdown
Member

@pluiedev pluiedev commented Sep 25, 2025

For some bizarre reason Zig contains a bug where the compiler would crash when a large enough file is embedded AND when the builder has too many cores. (It doesn't matter how many cores Zig has been specified to use via the -j flag — the only way to fix this bug is to use CPU scheduling tools to prevent Zig from using more than 32 cores.) This has been causing Hydra builds to repeatedly fail, while Ofborg and manual testing by maintainers were never able to reproduce the failure. However, given this is preventing Ghostty 1.2 from landing in the binary cache, we need to work around it somehow.

Links to upstream discussions:

Fixes #445326

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@pluiedev pluiedev mentioned this pull request Sep 25, 2025
3 tasks
@pluiedev
Copy link
Copy Markdown
Member Author

pluiedev commented Sep 25, 2025

Cc the folks who reported build failures in the original PR:

@eyJhb @ulrikstrid @Mic92 @Enzime

Could y'all give this a go and see if it works?

@pluiedev
Copy link
Copy Markdown
Member Author

Also I'm not sure who to contact here, but the only one I know who's actively working on Zig stuff is @RossComputerGuy — it seems that the Zig build hook currently doesn't specify the -j flag at all so NIX_BUILD_CORES is being completely ignored in Zig builds right now AFAICT. Should we add that to the hook in a separate PR?

@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Sep 25, 2025
@nix-owners nix-owners bot requested review from getchoo and jcollie September 25, 2025 14:58
@nixpkgs-ci nixpkgs-ci bot added the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Sep 25, 2025
@eyJhb
Copy link
Copy Markdown
Member

eyJhb commented Sep 25, 2025

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 446056
Commit: 5dfa5c8c81d7115a65ecd34990d1011350ee2f77


x86_64-linux

❌ 5 packages failed to build:
  • ghostty
  • ghostty.man
  • ghostty.shell_integration
  • ghostty.terminfo
  • ghostty.vim

Error logs: `x86_64-linux`
ghostty
NO_COLOR=1 pkg-config gtk4-wayland --cflags --libs 
NO_COLOR=1 pkg-config graphene-gobject-1.0 --cflags --libs 
NO_COLOR=1 pkg-config cairo-gobject --cflags --libs 
NO_COLOR=1 pkg-config pangocairo --cflags --libs 
NO_COLOR=1 pkg-config pango --cflags --libs 
NO_COLOR=1 pkg-config harfbuzz-gobject --cflags --libs 
NO_COLOR=1 pkg-config gmodule-2.0 --cflags --libs 
NO_COLOR=1 pkg-config gdk-pixbuf-2.0 --cflags --libs 
/nix/store/7sh77qdzh69644yw7i7s38iihci042q1-zig-0.14.1/bin/zig build-exe @/build/source/.zig-cache/args/c63a57624e650c2fd1a5ba23c5e008585cf336ef2636b410284eb2004824c008 
install
+- install ghostty
   +- zig build-exe ghostty ReleaseFast native-native failure
error: the following command terminated unexpectedly:
/nix/store/7sh77qdzh69644yw7i7s38iihci042q1-zig-0.14.1/bin/zig build-exe @/build/source/.zig-cache/args/c63a57624e650c2fd1a5ba23c5e008585cf336ef2636b410284eb2004824c008 
Build Summary: 154/157 steps succeeded; 1 failed
install transitive failure
+- install ghostty transitive failure
   +- zig build-exe ghostty ReleaseFast native-native failure
error: the following build command failed with exit code 1:
/build/source/.zig-cache/o/c9a5e930a5cb7ccee2a097127e8ca132/build /nix/store/7sh77qdzh69644yw7i7s38iihci042q1-zig-0.14.1/bin/zig /nix/store/7sh77qdzh69644yw7i7s38iihci042q1-zig-0.14.1/lib/zig /build/source /build/source/.zig-cache /build/tmp.m5BuaY6vBm --seed 0x7f4844da -Ze720b2ef844882b5 -Dcpu=baseline -Doptimize=ReleaseFast --color off --system -Dversion-string=1.2.0 -fsys=glslang --search-prefix /nix/store/cyjg0acqk1nr186a5p6sqzfgbsyzp9zg-glslang-15.4.0 -j24 --verbose

@pluiedev
Copy link
Copy Markdown
Member Author

Still no? Hmm... What happens if you turn off parallel building altogether?

@eyJhb
Copy link
Copy Markdown
Member

eyJhb commented Sep 25, 2025

Still no? Hmm... What happens if you turn off parallel building altogether?

What would I need to do, to try that? Also, my comment was wrong in the other PR regarding how many cores I have. I'm building on a remote builder which has 64 cores :)

@pluiedev
Copy link
Copy Markdown
Member Author

pluiedev commented Sep 25, 2025

I think it's --option cores 1 for nix build or just --cores 1 for nix-build - or you could .overrideAttrs { enableParallelBuilding = false; } (scratch that, doesn't seem to work?)

Copy link
Copy Markdown
Member

@getchoo getchoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM. Thanks :)

Comment thread pkgs/by-name/gh/ghostty/package.nix Outdated
@nixpkgs-ci nixpkgs-ci bot removed the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Sep 25, 2025
@pluiedev pluiedev force-pushed the pluie/jj-wvossqnpmvpy branch from 5dfa5c8 to 429c48e Compare September 25, 2025 15:16
@getchoo
Copy link
Copy Markdown
Member

getchoo commented Sep 25, 2025

scratch that, doesn't seem to work?)

This is again because Zig's hook does not correctly (or even really try to...) handle regular controls of build parallelism like other hooks 🫠

@ulrikstrid
Copy link
Copy Markdown
Member

I don't have my computer available right now but will try when I can. i have however tried just adding -j1 to the build flags without success

@pluiedev
Copy link
Copy Markdown
Member Author

I'm honestly surprised that it even worked for other Zig-based software like TigerBeetle and Bun then... Maybe we were all just collectively really lucky that we never ran into any parallelism-based bugs yet

@emilazy
Copy link
Copy Markdown
Member

emilazy commented Sep 25, 2025

I think non‐big-parallel Hydra runners only build with 2 to 4 cores? So I am not sure this would have any effect there.

Edit: Ah, #446056 (comment) would explain it.

@pluiedev
Copy link
Copy Markdown
Member Author

✨ It never worked in the first place ✨

@RossComputerGuy
Copy link
Copy Markdown
Member

This is again because Zig's hook does not correctly (or even really try to...) handle regular controls of build parallelism like other hooks 🫠

I'm actually working on a PR to add that in

I'm honestly surprised that it even worked for other Zig-based software like TigerBeetle and Bun then... Maybe we were all just collectively really lucky that we never ran into any parallelism-based bugs yet

I've tried building Bun and oddly enough, I don't think I've seen this problem on my Ampere hardware which is Arm. Last time I touched Bun, I had 64 cores. I have 128 cores and I remember updating zig and running a nixpkgs-review on it to build everything and Ghostty passing. It's possible this is only a problem on x86. I'm running some builds right now to verify this.

@pluiedev
Copy link
Copy Markdown
Member Author

It's entirely plausible that Bun isn't (ab)using @embedFile nearly as heavily as we are — we use it for animation frames, Unicode lookup tables, etc., all of which are quite large. It's probably the same reason why upstream seemingly only took it seriously after Ghostty 1.2 came out, since initially it was stuck in upcoming jail for quite a long time during Zig 0.14's development

@RossComputerGuy
Copy link
Copy Markdown
Member

Hmm, and it's always possible because I've got Arm cores that the difference in performance compared to x86 could have an impact. I've seen this, my individual cores are slower than most x86 hardware but together they're strong.

@justDeeevin
Copy link
Copy Markdown
Contributor

justDeeevin commented Sep 25, 2025

I said in #445326 but i'll say here as well: this pr allows for successful build on my machine

@RossComputerGuy
Copy link
Copy Markdown
Member

I just opened #446063 to add support for using --cores. However I can't test build ghostty because the zig version it uses crashes due to me running with a 64k page size. If it was using 0.14, I could test it. I was at least able to verify it is using the flag now.

@pluiedev
Copy link
Copy Markdown
Member Author

Ghostty 1.2 is on Zig 0.14, though. 1.1.3 wouldn't work for sure

@RossComputerGuy
Copy link
Copy Markdown
Member

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 446056
Commit: 429c48e2a62c02d5e92ad7bb1e0087d75cf50840


aarch64-linux

❌ 5 packages failed to build:
  • ghostty
  • ghostty.man
  • ghostty.shell_integration
  • ghostty.terminfo
  • ghostty.vim
✅ 1 package built:
  • nixpkgs-manual

Error logs: `aarch64-linux`
ghostty
NO_COLOR=1 pkg-config gtk4-wayland --cflags --libs 
NO_COLOR=1 pkg-config graphene-gobject-1.0 --cflags --libs 
NO_COLOR=1 pkg-config cairo-gobject --cflags --libs 
NO_COLOR=1 pkg-config pangocairo --cflags --libs 
NO_COLOR=1 pkg-config pango --cflags --libs 
NO_COLOR=1 pkg-config harfbuzz-gobject --cflags --libs 
NO_COLOR=1 pkg-config gmodule-2.0 --cflags --libs 
NO_COLOR=1 pkg-config gdk-pixbuf-2.0 --cflags --libs 
/nix/store/ilpzihsg7avag4a0z4arwgkzar3h5jzq-zig-0.14.1/bin/zig build-exe @/build/source/.zig-cache/args/ea5af3d6daad594c61beb5917ee46d616c4d20b1f4f44822b59e8e7523e9477f 
install
+- install ghostty
   +- zig build-exe ghostty ReleaseFast native-native failure
error: the following command terminated unexpectedly:
/nix/store/ilpzihsg7avag4a0z4arwgkzar3h5jzq-zig-0.14.1/bin/zig build-exe @/build/source/.zig-cache/args/ea5af3d6daad594c61beb5917ee46d616c4d20b1f4f44822b59e8e7523e9477f 
Build Summary: 154/157 steps succeeded; 1 failed
install transitive failure
+- install ghostty transitive failure
   +- zig build-exe ghostty ReleaseFast native-native failure
error: the following build command failed with exit code 1:
/build/source/.zig-cache/o/eec229b1f8bb9f00e165fd2d494bab17/build /nix/store/ilpzihsg7avag4a0z4arwgkzar3h5jzq-zig-0.14.1/bin/zig /nix/store/ilpzihsg7avag4a0z4arwgkzar3h5jzq-zig-0.14.1/lib/zig /build/source /build/source/.zig-cache /build/tmp.6AA9tMHdTv --seed 0xcfc3f440 -Z34691887ebfc6d50 -Dcpu=baseline -Doptimize=ReleaseFast --color off --system -Dversion-string=1.2.0 -fsys=glslang --search-prefix /nix/store/7fxg13l7zr7v4wpzm9r5vhkd9fgpb153-glslang-15.4.0 -j24 --verbose

@justDeeevin
Copy link
Copy Markdown
Contributor

Disregard my success report—it was run on my laptop which has 16 cores so the bug doesn't apply

@pluiedev
Copy link
Copy Markdown
Member Author

Oh that is disgusting. But it should work. At this point since I'm not nearly qualified enough to try to fix the bug at its source, I'm tempted to go with this anyways so we can at least get Ghostty in Hydra first.

@pluiedev pluiedev force-pushed the pluie/jj-wvossqnpmvpy branch from b6766fe to b58cdc0 Compare September 25, 2025 22:59
@pluiedev
Copy link
Copy Markdown
Member Author

@Mic92 I modified your approach and used a shell script wrapper instead of manually replicating what the hook currently does. Could you give it a whirl?

@pluiedev pluiedev force-pushed the pluie/jj-wvossqnpmvpy branch from b58cdc0 to 43c085b Compare September 25, 2025 23:02
For some bizarre reason Zig contains a bug where the compiler would crash
when a large enough file is embedded AND when too many cores are used
during compilation. This has been causing Hydra builds to repeatedly
fail, while Ofborg and manual testing by maintainers were never able to
reproduce the failure. However, given this is preventing Ghostty 1.2 from
landing in the binary cache, we need to work around it somehow. 24 cores
should be *more* than enough for now, but if it still doesn't work we can
lower the threshold even further.

Links to upstream discussions:
 * ziglang/zig#25297
 * ziglang/zig#22867
 * ghostty-org/ghostty#8676

Fixes NixOS#445326
@qubitnano
Copy link
Copy Markdown
Contributor

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 446056
Commit: fb8d932c8622103c17640fd65234e52e5b1e3e78


x86_64-linux

✅ 5 packages built:
  • ghostty
  • ghostty.man
  • ghostty.shell_integration
  • ghostty.terminfo
  • ghostty.vim

@RossComputerGuy
Copy link
Copy Markdown
Member

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 446056
Commit: fb8d932c8622103c17640fd65234e52e5b1e3e78


aarch64-linux

✅ 5 packages built:
  • ghostty
  • ghostty.man
  • ghostty.shell_integration
  • ghostty.terminfo
  • ghostty.vim

@pluiedev
Copy link
Copy Markdown
Member Author

Let's freaking go

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Sep 26, 2025
Copy link
Copy Markdown
Contributor

@qubitnano qubitnano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @pluiedev @Mic92

@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 12.approvals: 1 This PR was reviewed and approved by one person. labels Sep 26, 2025
@ulrikstrid
Copy link
Copy Markdown
Member

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 446056
Commit: fb8d932c8622103c17640fd65234e52e5b1e3e78


x86_64-linux

✅ 5 packages built:
  • ghostty
  • ghostty.man
  • ghostty.shell_integration
  • ghostty.terminfo
  • ghostty.vim

@ulrikstrid
Copy link
Copy Markdown
Member

Builds on my Threadripper now, 64 physical cores

@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 3+ This PR was reviewed and approved by three or more persons. and removed 12.approvals: 2 This PR was reviewed and approved by two persons. labels Sep 26, 2025
@SuperSandro2000
Copy link
Copy Markdown
Member

Shouldn't we limit this in zig itself as this could effect any package big enough?

@pluiedev
Copy link
Copy Markdown
Member Author

Not really. The only way this triggers is if you embed a lot of strings directly into the binary, which apparently is not the case for TigerBeetle, Bun, River, etc. It also heavily depends on just how many strings are embedded - in Ghostty 1.2 we added new Unicode tables that I suspected brought our total usage over the "limit". In reality there isn't a single limit, but rather the limit decreases as core count goes up, so the limit we want to set is completely dependent on the needs of any given project.

Given all of this and the fact that upstream Zig has marked the root issue as something they'd like to iron out for 0.15.2, I don't think it makes sense to add this wrapper to the compiler itself. If that fix does land in 0.15.2 I might even consider backporting the 1.2.x releases to use Zig 0.15 instead of 0.14 — my original plan is to switch to Zig 0.15 for 1.3.x, but plans might have to change now.

@Mic92
Copy link
Copy Markdown
Member

Mic92 commented Sep 26, 2025

Not really. The only way this triggers is if you embed a lot of strings directly into the binary, which apparently is not the case for TigerBeetle, Bun, River, etc. It also heavily depends on just how many strings are embedded - in Ghostty 1.2 we added new Unicode tables that I suspected brought our total usage over the "limit". In reality there isn't a single limit, but rather the limit decreases as core count goes up, so the limit we want to set is completely dependent on the needs of any given project.

Given all of this and the fact that upstream Zig has marked the root issue as something they'd like to iron out for 0.15.2, I don't think it makes sense to add this wrapper to the compiler itself. If that fix does land in 0.15.2 I might even consider backporting the 1.2.x releases to use Zig 0.15 instead of 0.14 — my original plan is to switch to Zig 0.15 for 1.3.x, but plans might have to change now.

However what we should introduce in our zig builder is -j$NIX_BUILD_CORES... but this is orthogonal to this PR.

@pluiedev
Copy link
Copy Markdown
Member Author

I'd be happy to see this merged given that multiple people have confirmed that this works for them :) (I don't have the perms myself. Yet.)

@Mic92 Mic92 added this pull request to the merge queue Sep 26, 2025
@pluiedev
Copy link
Copy Markdown
Member Author

However what we should introduce in our zig builder is -j$NIX_BUILD_CORES... but this is orthogonal to this PR.

That would be #446063 I believe

Merged via the queue into NixOS:master with commit b765170 Sep 26, 2025
34 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes. 12.approvals: 3+ This PR was reviewed and approved by three or more persons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build failure: ghostty

10 participants