ghostty/flake.nix
Chris Marchesi 2671215211 nix: fix package build
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.
2023-11-19 14:21:34 -08:00

61 lines
2.1 KiB
Nix

{
description = "ghostty";
inputs = {
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
zig.url = "github:mitchellh/zig-overlay";
zls-master.url = "github:zigtools/zls/master";
# This is a nixpkgs mirror (based off of nixos-unstable) that contains
# patches for LLVM 17 and Zig 0.12 (master/nightly).
#
# 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";
# Used for shell.nix
flake-compat = { url = github:edolstra/flake-compat; flake = false; };
};
outputs = { self, nixpkgs, flake-utils, ... }@inputs:
let
overlays = [
# Our repo overlay
(import ./nix/overlay.nix)
# Other overlays
(final: prev: {
zigpkgs = inputs.zig.packages.${prev.system};
zig_0_12 = inputs.nixpkgs-zig-0-12.legacyPackages.${prev.system}.zig_0_12;
# Latest version of Tracy
tracy = inputs.nixpkgs-unstable.legacyPackages.${prev.system}.tracy;
# Latest version of ZLS
zls = inputs.zls-master.packages.${prev.system}.zls;
})
];
# Our supported systems are the same supported systems as the Zig binaries
systems = builtins.attrNames inputs.zig.packages;
in
flake-utils.lib.eachSystem systems (system:
let pkgs = import nixpkgs { inherit overlays system; };
in rec {
devShell = pkgs.devShell;
packages.ghostty = pkgs.ghostty;
defaultPackage = packages.ghostty;
}
);
}