build: add nix script to make cache tarball

Run `nix run .#make-cache` to create a directory `blob/` with
a tarball of the Zig deps.
This commit is contained in:
Jeffrey C. Ollie
2025-02-13 09:57:50 -06:00
parent 9f6067d899
commit 4cd2d5e0e5
3 changed files with 34 additions and 5 deletions

1
.gitignore vendored
View File

@ -19,3 +19,4 @@ glad.zip
/Box_test_diff.ppm
/ghostty.qcow2
/build.zig.zon2json-lock
/blob

View File

@ -45,6 +45,8 @@
builtins.foldl' nixpkgs-stable.lib.recursiveUpdate {} (
builtins.map (
system: let
version = "1.1.1";
revision = self.shortRev or self.dirtyShortRev or "dirty";
pkgs-stable = nixpkgs-stable.legacyPackages.${system};
pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
in {
@ -56,12 +58,12 @@
packages.${system} = let
mkArgs = optimize: {
inherit optimize;
revision = self.shortRev or self.dirtyShortRev or "dirty";
inherit optimize version revision;
};
in rec {
deps = pkgs-stable.callPackage ./build.zig.zon.nix {};
deps = pkgs-stable.callPackage ./build.zig.zon.nix {
name = "ghostty-cache-${version}-${revision}";
};
ghostty-debug = pkgs-stable.callPackage ./nix/package.nix (mkArgs "Debug");
ghostty-releasesafe = pkgs-stable.callPackage ./nix/package.nix (mkArgs "ReleaseSafe");
ghostty-releasefast = pkgs-stable.callPackage ./nix/package.nix (mkArgs "ReleaseFast");
@ -99,6 +101,31 @@
x11-gnome = runVM ./nix/vm/x11-gnome.nix;
x11-plasma6 = runVM ./nix/vm/x11-plasma6.nix;
x11-xfce = runVM ./nix/vm/x11-xfce.nix;
make-cache = let
program = pkgs-stable.writeShellScript "make-cache" ''
set -e
mkdir -p blob
WORK_DIR=$(mktemp -d)
if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
echo "Could not create temp dir"
exit 1
fi
function cleanup {
rm -rf "$WORK_DIR"
}
trap cleanup EXIT
ln -s "${self.packages.${system}.deps}" "$WORK_DIR/cache"
pushd "$WORK_DIR/cache" > /dev/null
tar --create --file "$WORK_DIR/temp.tar.gz" */*
popd > /dev/null
HASH=$(sha256sum "$WORK_DIR/temp.tar.gz" | awk "NR == 1 { print \$1 }; NR>1 { exit }")
mv "$WORK_DIR/temp.tar.gz" "blob/$HASH.tar.gz"
ln -sf "$HASH.tar.gz" "blob/ghostty-cache-${version}-${revision}.tar.gz"
'';
in {
type = "app";
program = "${program}";
};
};
}
# Our supported systems are the same supported systems as the Zig binaries.

View File

@ -23,6 +23,7 @@
pkg-config,
zig_0_13,
pandoc,
version,
revision ? "dirty",
optimize ? "Debug",
enableX11 ? true,
@ -48,7 +49,7 @@
in
stdenv.mkDerivation (finalAttrs: {
pname = "ghostty";
version = "1.1.1";
inherit version;
# We limit source like this to try and reduce the amount of rebuilds as possible
# thus we only provide the source that is needed for the build