mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
Merge pull request #912 from vancluever/vancluever-nix-fix-package-build
nix: fix package build
This commit is contained in:
17
flake.lock
generated
17
flake.lock
generated
@ -176,6 +176,22 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"nixpkgs-zig-0-12": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1700381855,
|
||||||
|
"narHash": "sha256-2iN7PIsz7zcGU+va5eUZwNEmBnDGr+sUgoWhpsT5xtw=",
|
||||||
|
"owner": "vancluever",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "d986dbb50cea7804e544ebd77342a2498e399166",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "vancluever",
|
||||||
|
"ref": "vancluever-zig-0-12",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"nixpkgs_2": {
|
"nixpkgs_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1689088367,
|
"lastModified": 1689088367,
|
||||||
@ -214,6 +230,7 @@
|
|||||||
"flake-utils": "flake-utils",
|
"flake-utils": "flake-utils",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"nixpkgs-unstable": "nixpkgs-unstable",
|
"nixpkgs-unstable": "nixpkgs-unstable",
|
||||||
|
"nixpkgs-zig-0-12": "nixpkgs-zig-0-12",
|
||||||
"zig": "zig",
|
"zig": "zig",
|
||||||
"zls-master": "zls-master"
|
"zls-master": "zls-master"
|
||||||
}
|
}
|
||||||
|
21
flake.nix
21
flake.nix
@ -7,9 +7,19 @@
|
|||||||
zig.url = "github:mitchellh/zig-overlay";
|
zig.url = "github:mitchellh/zig-overlay";
|
||||||
zls-master.url = "github:zigtools/zls/master";
|
zls-master.url = "github:zigtools/zls/master";
|
||||||
|
|
||||||
# We want to stay as up to date as possible but need to be careful
|
# This is a nixpkgs mirror (based off of nixos-unstable) that contains
|
||||||
# that the glibc versions used by our dependencies from Nix are compatible
|
# patches for LLVM 17 and Zig 0.12 (master/nightly).
|
||||||
# with the system glibc that the user is building for.
|
#
|
||||||
|
# This gives an up-to-date Zig that contains the nixpkgs patches,
|
||||||
|
# specifically the ones relating to NativeTargetInfo
|
||||||
|
# (https://github.com/ziglang/zig/issues/15898) in addition to the base
|
||||||
|
# hooks. This is used in the package (i.e. packages.ghostty, not the
|
||||||
|
# devShell) to build a Zig that can be included in a NixOS configuration.
|
||||||
|
nixpkgs-zig-0-12.url = "github:vancluever/nixpkgs/vancluever-zig-0-12";
|
||||||
|
|
||||||
|
# We want to stay as up to date as possible but need to be careful that the
|
||||||
|
# glibc versions used by our dependencies from Nix are compatible with the
|
||||||
|
# system glibc that the user is building for.
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/release-23.05";
|
nixpkgs.url = "github:nixos/nixpkgs/release-23.05";
|
||||||
|
|
||||||
# Used for shell.nix
|
# Used for shell.nix
|
||||||
@ -26,6 +36,8 @@
|
|||||||
(final: prev: {
|
(final: prev: {
|
||||||
zigpkgs = inputs.zig.packages.${prev.system};
|
zigpkgs = inputs.zig.packages.${prev.system};
|
||||||
|
|
||||||
|
zig_0_12 = inputs.nixpkgs-zig-0-12.legacyPackages.${prev.system}.zig_0_12;
|
||||||
|
|
||||||
# Latest version of Tracy
|
# Latest version of Tracy
|
||||||
tracy = inputs.nixpkgs-unstable.legacyPackages.${prev.system}.tracy;
|
tracy = inputs.nixpkgs-unstable.legacyPackages.${prev.system}.tracy;
|
||||||
|
|
||||||
@ -36,7 +48,8 @@
|
|||||||
|
|
||||||
# Our supported systems are the same supported systems as the Zig binaries
|
# Our supported systems are the same supported systems as the Zig binaries
|
||||||
systems = builtins.attrNames inputs.zig.packages;
|
systems = builtins.attrNames inputs.zig.packages;
|
||||||
in flake-utils.lib.eachSystem systems (system:
|
in
|
||||||
|
flake-utils.lib.eachSystem systems (system:
|
||||||
let pkgs = import nixpkgs { inherit overlays system; };
|
let pkgs = import nixpkgs { inherit overlays system; };
|
||||||
in rec {
|
in rec {
|
||||||
devShell = pkgs.devShell;
|
devShell = pkgs.devShell;
|
||||||
|
147
nix/package.nix
147
nix/package.nix
@ -1,79 +1,122 @@
|
|||||||
# TODO(mitchellh): This currently doesn't fully work. It generates a binary
|
{ lib
|
||||||
# that smashes the stack on run. I'm not sure why.
|
, stdenv
|
||||||
{ stdenv
|
|
||||||
, lib
|
, bzip2
|
||||||
|
, expat
|
||||||
|
, fontconfig
|
||||||
|
, freetype
|
||||||
|
, harfbuzz
|
||||||
|
, libpng
|
||||||
|
, pixman
|
||||||
|
, zlib
|
||||||
|
|
||||||
, libGL
|
, libGL
|
||||||
, libX11
|
, libX11
|
||||||
, libXcursor
|
, libXcursor
|
||||||
, libXi
|
, libXi
|
||||||
, libXrandr
|
, libXrandr
|
||||||
, libXxf86vm
|
|
||||||
, libxcb
|
, glib
|
||||||
, pkg-config
|
, gtk4
|
||||||
, zig
|
, libadwaita
|
||||||
|
|
||||||
, git
|
, git
|
||||||
|
, ncurses
|
||||||
|
, pkg-config
|
||||||
|
, zig_0_12
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
# These are the libraries that need to be added to the rpath for
|
# This hash is the computation of the zigCache fixed-output derivation. This
|
||||||
# the binary so that they run properly on NixOS.
|
# allows us to use remote package dependencies without breaking the sandbox.
|
||||||
rpathLibs = [
|
#
|
||||||
libGL
|
# This will need updating whenever dependencies get updated (e.g. changes are
|
||||||
] ++ lib.optionals stdenv.isLinux [
|
# made to zig.build.zon). If you see that the main build is trying to reach
|
||||||
libX11
|
# out to the internet and failing, this is likely the cause. Change this
|
||||||
libXcursor
|
# value back to lib.fakeHash, and re-run. The build failure should emit the
|
||||||
libXi
|
# updated hash, which of course, should be validated before updating here.
|
||||||
libXrandr
|
#
|
||||||
libXxf86vm
|
# (It's also possible that you might see a hash mismatch - without the
|
||||||
libxcb
|
# 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.)
|
||||||
in
|
zigCacheHash = "sha256-2zDoQ4AKHJal7njTvt38RVEkTyPHNNX90QFibKq/xh4=";
|
||||||
|
|
||||||
stdenv.mkDerivation rec {
|
zigCache = src: stdenv.mkDerivation {
|
||||||
pname = "ghostty";
|
inherit src;
|
||||||
version = "0.1.0";
|
name = "ghostty-cache";
|
||||||
|
nativeBuildInputs = [ git zig_0_12.hook ];
|
||||||
src = ./..;
|
|
||||||
|
|
||||||
nativeBuildInputs = [ git pkg-config zig ];
|
|
||||||
|
|
||||||
buildInputs = rpathLibs ++ [
|
|
||||||
# Nothing yet
|
|
||||||
];
|
|
||||||
|
|
||||||
dontConfigure = true;
|
dontConfigure = true;
|
||||||
dontPatchELF = true;
|
dontUseZigBuild = true;
|
||||||
|
dontUseZigInstall = true;
|
||||||
|
dontFixup = true;
|
||||||
|
|
||||||
# The Zig cache goes into $HOME, so we set this to be writable
|
|
||||||
preBuild = ''
|
|
||||||
export HOME=$TMPDIR
|
|
||||||
'';
|
|
||||||
|
|
||||||
# Build we do nothing except run hooks
|
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
runHook preBuild
|
runHook preBuild
|
||||||
|
|
||||||
|
zig build --fetch
|
||||||
|
|
||||||
runHook postBuild
|
runHook postBuild
|
||||||
'';
|
'';
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
runHook preInstall
|
runHook preInstall
|
||||||
|
|
||||||
export MACH_SDK_PATH=${src}/vendor/mach-sdk
|
cp -r --reflink=auto $ZIG_GLOBAL_CACHE_DIR $out
|
||||||
zig build \
|
|
||||||
-Dcpu=baseline \
|
|
||||||
-Dversion-string="${version}-nixdev" \
|
|
||||||
--prefix $out \
|
|
||||||
install
|
|
||||||
|
|
||||||
strip -S $out/bin/ghostty
|
|
||||||
patchelf \
|
|
||||||
--set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
|
|
||||||
--set-rpath "${lib.makeLibraryPath rpathLibs}" \
|
|
||||||
$out/bin/ghostty
|
|
||||||
|
|
||||||
runHook postInstall
|
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" ];
|
outputs = [ "out" ];
|
||||||
|
|
||||||
meta = with lib; {
|
meta = with lib; {
|
||||||
@ -81,4 +124,4 @@ stdenv.mkDerivation rec {
|
|||||||
license = licenses.mit;
|
license = licenses.mit;
|
||||||
platforms = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ];
|
platforms = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ];
|
||||||
};
|
};
|
||||||
}
|
})
|
||||||
|
Reference in New Issue
Block a user