mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00

This fixes the Nix *package* build (read: not devShell, which is not touched) so that it builds, and also conforms to what is generally seen for a Zig project in nixpkgs. The highlights: * We use a Zig 0.12 derivation that I constructed from the Zig 0.11 derivation, in addition to LLVM 17 updates found in NixOS/nixpkgs#258614. This specifically includes the patches that address ziglang/zig#15898, and also allows us to take advantage of the build hooks included in the Zig toolchain there. * We pre-download the cache using "zig build --fetch" and a fixed-output derivation. This is similar to how the Go builders work in nixpkgs and I could see Zig ultimately going in a similar path, given that the fetcher part of the build system seems to be shaping up to having a Go module system-style DX (mind you, this is a naive opinion right now). * Finally, cleaned up the derivation so that there's no special fixups happening outside of what is defined in the basic nixpkgs workflow. This is similar to other Zig projects I looked at (notably River) that seem to just include their dependencies in buildInputs and call it a day. One specific change that is worth noting is that this changes the build mode from ReleaseFast to ReleaseSafe - this is the current default within the Zig build hook in nixpkgs. If we need ReleaseFast, we'll have to override this.
128 lines
2.5 KiB
Nix
128 lines
2.5 KiB
Nix
{ lib
|
|
, stdenv
|
|
|
|
, bzip2
|
|
, expat
|
|
, fontconfig
|
|
, freetype
|
|
, harfbuzz
|
|
, libpng
|
|
, pixman
|
|
, zlib
|
|
|
|
, libGL
|
|
, libX11
|
|
, libXcursor
|
|
, libXi
|
|
, libXrandr
|
|
|
|
, glib
|
|
, gtk4
|
|
, libadwaita
|
|
|
|
, git
|
|
, ncurses
|
|
, pkg-config
|
|
, zig_0_12
|
|
}:
|
|
|
|
let
|
|
# This hash is the computation of the zigCache fixed-output derivation. This
|
|
# allows us to use remote package dependencies without breaking the sandbox.
|
|
#
|
|
# This will need updating whenever dependencies get updated (e.g. changes are
|
|
# made to zig.build.zon). If you see that the main build is trying to reach
|
|
# out to the internet and failing, this is likely the cause. Change this
|
|
# value back to lib.fakeHash, and re-run. The build failure should emit the
|
|
# updated hash, which of course, should be validated before updating here.
|
|
#
|
|
# (It's also possible that you might see a hash mismatch - without the
|
|
# network errors - if you don't have a previous instance of the cache
|
|
# derivation in your store already. If so, just update the value as above.)
|
|
zigCacheHash = "sha256-2zDoQ4AKHJal7njTvt38RVEkTyPHNNX90QFibKq/xh4=";
|
|
|
|
zigCache = src: stdenv.mkDerivation {
|
|
inherit src;
|
|
name = "ghostty-cache";
|
|
nativeBuildInputs = [ git zig_0_12.hook ];
|
|
|
|
dontConfigure = true;
|
|
dontUseZigBuild = true;
|
|
dontUseZigInstall = true;
|
|
dontFixup = true;
|
|
|
|
buildPhase = ''
|
|
runHook preBuild
|
|
|
|
zig build --fetch
|
|
|
|
runHook postBuild
|
|
'';
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
|
|
cp -r --reflink=auto $ZIG_GLOBAL_CACHE_DIR $out
|
|
|
|
runHook postInstall
|
|
'';
|
|
|
|
outputHashMode = "recursive";
|
|
outputHash = zigCacheHash;
|
|
};
|
|
in
|
|
|
|
stdenv.mkDerivation (finalAttrs: {
|
|
pname = "ghostty";
|
|
version = "0.1.0";
|
|
|
|
src = ./..;
|
|
|
|
nativeBuildInputs = [
|
|
git
|
|
ncurses
|
|
pkg-config
|
|
zig_0_12.hook
|
|
];
|
|
|
|
buildInputs = [
|
|
libGL
|
|
] ++ lib.optionals stdenv.isLinux [
|
|
bzip2
|
|
expat
|
|
fontconfig
|
|
freetype
|
|
harfbuzz
|
|
libpng
|
|
pixman
|
|
zlib
|
|
|
|
libX11
|
|
libXcursor
|
|
libXi
|
|
libXrandr
|
|
|
|
libadwaita
|
|
gtk4
|
|
glib
|
|
];
|
|
|
|
dontConfigure = true;
|
|
|
|
zigBuildFlags = "-Dversion-string=${finalAttrs.version}";
|
|
|
|
preBuild = ''
|
|
rm -rf $ZIG_GLOBAL_CACHE_DIR
|
|
cp -r --reflink=auto ${zigCache finalAttrs.src} $ZIG_GLOBAL_CACHE_DIR
|
|
chmod u+rwX -R $ZIG_GLOBAL_CACHE_DIR
|
|
'';
|
|
|
|
outputs = [ "out" ];
|
|
|
|
meta = with lib; {
|
|
homepage = "https://github.com/mitchellh/ghostty";
|
|
license = licenses.mit;
|
|
platforms = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ];
|
|
};
|
|
})
|