Skip to content

Commit

Permalink
allow building nix package with different optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
jcollie authored and mitchellh committed Mar 17, 2024
1 parent b00d980 commit e9de444
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
14 changes: 13 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,22 @@
};

packages.${system} = rec {
ghostty = pkgs-stable.callPackage ./nix/package.nix {
ghostty-debug = pkgs-stable.callPackage ./nix/package.nix {
inherit (pkgs-zig-0-12) zig_0_12;
revision = self.shortRev or self.dirtyShortRev or "dirty";
optimize = "Debug";
};
ghostty-releasesafe = pkgs-stable.callPackage ./nix/package.nix {
inherit (pkgs-zig-0-12) zig_0_12;
revision = self.shortRev or self.dirtyShortRev or "dirty";
optimize = "ReleaseSafe";
};
ghostty-releasefast = pkgs-stable.callPackage ./nix/package.nix {
inherit (pkgs-zig-0-12) zig_0_12;
revision = self.shortRev or self.dirtyShortRev or "dirty";
optimize = "ReleaseFast";
};
ghostty = ghostty-releasesafe;
default = ghostty;
};

Expand Down
15 changes: 2 additions & 13 deletions nix/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
zig_0_12,
pandoc,
revision ? "dirty",
optimize ? "Debug",
}: let
# The Zig hook has no way to select the release type without actual
# overriding of the default flags.
Expand All @@ -34,7 +35,7 @@
# ultimately acted on and has made its way to a nixpkgs implementation, this
# can probably be removed in favor of that.
zig012Hook = zig_0_12.hook.overrideAttrs {
zig_default_flags = "-Dcpu=baseline -Doptimize=ReleaseFast";
zig_default_flags = "-Dcpu=baseline -Doptimize=${optimize}";
};

# This hash is the computation of the zigCache fixed-output derivation. This
Expand Down Expand Up @@ -132,18 +133,6 @@ in
chmod u+rwX -R $ZIG_GLOBAL_CACHE_DIR
'';

buildPhase = ''
runHook preBuild
zig build -Dcpu=baseline -Doptimize=ReleaseSafe -Dversion-string=${finalAttrs.version}-${revision}-nix
runHook postBuild
'';

installPhase = ''
runHook preInstall
zig build install -Dcpu=baseline -Doptimize=ReleaseSafe -Dversion-string=${finalAttrs.version}-${revision}-nix --prefix $out
runHook postInstall
'';

outputs = ["out" "terminfo" "shell_integration"];

postInstall = ''
Expand Down

0 comments on commit e9de444

Please sign in to comment.