Merge pull request #1025 from RGBCube/main

Clean up Nix code, WIP: Create checks in Nix and package for Darwin
This commit is contained in:
Mitchell Hashimoto
2023-12-08 08:03:19 -08:00
committed by GitHub
11 changed files with 128 additions and 219 deletions

View File

@ -49,6 +49,7 @@ beta users using Ghostty as their primary terminal. See more in
| ------------------ | ------------------------------------------------------------------------ | -------------------------- |
| macOS | [Tip ("Nightly")](https://github.com/mitchellh/ghostty/releases/tag/tip) | MacOS 12+ Universal Binary |
| Linux | [Build from Source](#developing-ghostty) | |
| Linux (NixOS/Nix) | [Use the Flake](#nix-package) | |
| Windows | [Build from Source](#developing-ghostty) | [Notes](#windows-notes) |
### Configuration
@ -505,50 +506,42 @@ Make sure your Prettier version matches the version of in [devshell.nix](https:/
### Nix Package
> [!WARNING]
> The Nix package currently depends on versions of LLVM and Zig that are
> currently not in cache.nixos.org and will be built from source. This can take
> a very long time, especially in situations where CPU is at a premium. Most
> people should follow the instructions in [Developing
> Ghostty](#developing-ghostty) instead.
There is Nix package that can be used in the flake (`packages.ghostty` or `packages.default`).
It can be used in NixOS configurations and otherwise built off of.
There is a functional Nix package that can be used in the `flake.nix` file
(`packages.ghostty`). It can be used in NixOS configurations and otherwise
built off of (however, please heed the above warning).
Below is a sample on how to add it to a NixOS overlay:
Below is an example:
```nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# NOTE: This will require your git SSH access to the repo
# NOTE: This will require your git SSH access to the repo.
#
# WARNING: Do NOT pin the `nixpkgs` input, as that will
# declare the cache useless. If you do, you will have
# to compile LLVM, Zig and Ghostty itself on your machine,
# which will take a very very long time.
ghostty = {
url = "git+ssh://git@github.com/mitchellh/ghostty";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { nixpkgs, ghostty, ... }: {
nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
nixosConfigurations.mysystem = nixpkgs.lib.nixosSystem {
modules = [
{
nixpkgs.overlays = [
(final: prev: {
ghostty = ghostty.packages.${prev.system}.ghostty;
})
environment.systemPackages = [
ghostty.packages.x86_64-linux.default
];
}
# Other modules here...
];
};
};
}
```
You can also test the build of the nix package at any time by running `nix build .`
You can also test the build of the nix package at any time by running `nix build .`.
#### Updating the Zig Cache Fixed-Output Derivation Hash
@ -567,5 +560,5 @@ To update it, you can run the following in the repository root:
./nix/build-support/check-zig-cache-hash.sh --update
```
This will write out the `nix/zig_cache_hash.nix` file with the updated hash
This will write out the `nix/zigCacheHash.nix` file with the updated hash
that can then be committed and pushed to fix the builds.

111
flake.lock generated
View File

@ -3,11 +3,11 @@
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1648199409,
"narHash": "sha256-JwPKdC2PoVBkG6E+eWw3j6BMR6sL3COpYWfif7RVb8Y=",
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "64a525ee38886ab9028e6f61790de0832aa3ef03",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"type": "github"
},
"original": {
@ -32,38 +32,7 @@
"type": "github"
}
},
"flake-compat_3": {
"flake": false,
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"locked": {
"lastModified": 1656065134,
"narHash": "sha256-oc6E6ByIw3oJaIyc67maaFcnjYOz1mMcOtHxbEf9NwQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "bee6a7250dd1b01844a2de7e02e4df7d8a0a206c",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
@ -78,7 +47,7 @@
"type": "github"
}
},
"flake-utils_3": {
"flake-utils_2": {
"inputs": {
"systems": "systems"
},
@ -96,7 +65,7 @@
"type": "github"
}
},
"flake-utils_4": {
"flake-utils_3": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
@ -114,7 +83,7 @@
"gitignore": {
"inputs": {
"nixpkgs": [
"zls-master",
"zls",
"nixpkgs"
]
},
@ -144,13 +113,13 @@
"url": "https://raw.githubusercontent.com/ziglang/zig/63bd2bff12992aef0ce23ae4b344e9cb5d65f05d/doc/langref.html.in"
}
},
"nixpkgs": {
"nixpkgs-stable": {
"locked": {
"lastModified": 1691950488,
"narHash": "sha256-iUNEeudc4dGjx+HsHccnGiuZUVE/nhjXuQ1DVCsHIUY=",
"lastModified": 1702049175,
"narHash": "sha256-c/q2+tGHbmLgzT3sXyUKVJR98h1CTks2+nkVaoZPRM0=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "720e61ed8de116eec48d6baea1d54469b536b985",
"rev": "b15508bd65870620f1df5864e8e861dffbc4e428",
"type": "github"
},
"original": {
@ -192,47 +161,13 @@
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1689088367,
"narHash": "sha256-Y2tl2TlKCWEHrOeM9ivjCLlRAKH3qoPUE/emhZECU14=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5c9ddb86679c400d6b7360797b8a22167c2053f8",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "release-23.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1701336116,
"narHash": "sha256-kEmpezCR/FpITc6yMbAh4WrOCiT2zg5pSjnKrq51h5Y=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "f5c27c6136db4d76c30e533c20517df6864c46ee",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"nixpkgs-stable": "nixpkgs-stable",
"nixpkgs-unstable": "nixpkgs-unstable",
"nixpkgs-zig-0-12": "nixpkgs-zig-0-12",
"zig": "zig",
"zls-master": "zls-master"
"zls": "zls"
}
},
"systems": {
@ -252,9 +187,11 @@
},
"zig": {
"inputs": {
"flake-compat": "flake-compat_2",
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_2"
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"nixpkgs": [
"nixpkgs-stable"
]
},
"locked": {
"lastModified": 1701908568,
@ -272,10 +209,10 @@
},
"zig-overlay": {
"inputs": {
"flake-compat": "flake-compat_3",
"flake-utils": "flake-utils_4",
"flake-compat": "flake-compat_2",
"flake-utils": "flake-utils_3",
"nixpkgs": [
"zls-master",
"zls",
"nixpkgs"
]
},
@ -293,12 +230,14 @@
"type": "github"
}
},
"zls-master": {
"zls": {
"inputs": {
"flake-utils": "flake-utils_3",
"flake-utils": "flake-utils_2",
"gitignore": "gitignore",
"langref": "langref",
"nixpkgs": "nixpkgs_3",
"nixpkgs": [
"nixpkgs-stable"
],
"zig-overlay": "zig-overlay"
},
"locked": {

View File

@ -1,11 +1,13 @@
{
description = "ghostty";
description = "👻";
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";
# 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-stable.url = "github:nixos/nixpkgs/release-23.05";
# This is a nixpkgs mirror (based off of nixos-unstable) that contains
# patches for LLVM 17 and Zig 0.12 (master/nightly).
@ -17,54 +19,44 @@
# 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";
zig = {
url = "github:mitchellh/zig-overlay";
inputs.nixpkgs.follows = "nixpkgs-stable";
};
# Used for shell.nix
flake-compat = { url = github:edolstra/flake-compat; flake = false; };
zls = {
url = "github:zigtools/zls/master";
inputs.nixpkgs.follows = "nixpkgs-stable";
};
};
outputs = { self, nixpkgs, flake-utils, ... }@inputs:
let
overlays = [
# Our repo overlay
(import ./nix/overlay.nix)
outputs = {
nixpkgs-unstable
, nixpkgs-stable
, nixpkgs-zig-0-12
, zig
, zls
, ...
}: builtins.foldl' nixpkgs-stable.lib.recursiveUpdate {} (builtins.map (system: let
pkgs-stable = nixpkgs-stable.legacyPackages.${system};
pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
pkgs-zig-0-12 = nixpkgs-zig-0-12.legacyPackages.${system};
in {
devShell.${system} = pkgs-stable.callPackage ./nix/devShell.nix {
inherit (pkgs-unstable) tracy;
inherit (zls.packages.${system}) zls;
# Other overlays
(final: prev: {
zigpkgs = inputs.zig.packages.${prev.system};
zig = zig.packages.${system}.master;
wraptest = pkgs-stable.callPackage ./nix/wraptest.nix {};
};
zig_0_12 = inputs.nixpkgs-zig-0-12.legacyPackages.${prev.system}.zig_0_12;
packages.${system} = rec {
ghostty = pkgs-stable.callPackage ./nix/package.nix {
inherit (pkgs-zig-0-12) zig_0_12;
};
default = ghostty;
};
# 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;
# NOTE: using packages.ghostty right out of the flake currently
# requires a build of LLVM 17 and Zig master from source. This will
# take quite a bit of time. Until LLVM 17 and an upcoming Zig 0.12 are
# up in nixpkgs, most folks will want to continue to use the devShell
# and the instructions found at:
#
# https://github.com/mitchellh/ghostty/tree/main#developing-ghostty
#
packages.ghostty = pkgs.ghostty;
packages.default = packages.ghostty;
defaultPackage = packages.ghostty;
}
);
# Our supported systems are the same supported systems as the Zig binaries.
}) (builtins.attrNames zig.packages));
}

6
garnix.yaml Normal file
View File

@ -0,0 +1,6 @@
builds:
exclude: []
include:
- "*.aarch64-darwin.*"
- "*.aarch64-linux.*"
- "*.x86_64-linux.*"

View File

@ -3,15 +3,15 @@
# Nothing in this script should fail.
set -e
CACHE_HASH_FILE="$(realpath "$(dirname "$0")/../zig_cache_hash.nix")"
CACHE_HASH_FILE="$(realpath "$(dirname "$0")/../zigCacheHash.nix")"
help() {
echo ""
echo "To fix, please (manually) re-run the script from the repository root,"
echo "commit, and push the update:"
echo ""
echo " ./nix/build-support/check-zig-cache-hash.sh --update"
echo " git add nix/zig_cache_hash.nix"
echo " ./nix/build-support/check-zigCacheHash.sh --update"
echo " git add nix/zigCacheHash.nix"
echo " git commit -m \"nix: update Zig cache hash\""
echo " git push"
echo ""
@ -52,7 +52,7 @@ fi
# Write out the cache file
cat > "${CACHE_HASH_FILE}" <<EOS
# This file is auto-generated! check build-support/check-zig-cache-hash.sh for
# This file is auto-generated! check build-support/check-zigCacheHash.sh for
# more details.
"${ZIG_CACHE_HASH}"
EOS

View File

@ -1,8 +1,11 @@
{ mkShell, lib, stdenv
{
mkShell
, lib
, stdenv
, bashInteractive
, gdb
, glxinfo
#, glxinfo # unused
, ncurses
, nodejs
, nodePackages
@ -13,7 +16,7 @@
, scdoc
, tracy
, valgrind
, vulkan-loader
#, vulkan-loader # unused
, vttest
, wabt
, wasmtime
@ -66,7 +69,7 @@ let
gtk4
glib
];
in mkShell rec {
in mkShell {
name = "ghostty";
nativeBuildInputs = [

View File

@ -1,27 +0,0 @@
final: prev: rec {
# Notes:
#
# When determining a SHA256, use this to set a fake one until we know
# the real value:
#
# vendorSha256 = nixpkgs.lib.fakeSha256;
#
devShell = prev.callPackage ./devshell.nix { };
ghostty = prev.callPackage ./package.nix { };
wraptest = prev.callPackage ./wraptest.nix { };
# Last known working self-hosted with -fstage1, due to
# https://github.com/ziglang/zig/issues/12944
# I ended up finding a workaround for this but I still feel
# weird about it so I'm going to keep this around in case
# we want to rollback.
#zig = final.zigpkgs.master-2022-09-13;
# zig we want to be the latest nightly since 0.9.0 is not released yet.
zig = final.zigpkgs.master;
# last known working stage1 build, the rest in the future are stage3
#zig = final.zigpkgs.master-2022-08-19;
}

View File

@ -1,11 +1,5 @@
# NOTE: using this derivation right out of the flake currently requires a build
# of LLVM 17 and Zig master from source. This will take quite a bit of time.
# Until LLVM 17 and an upcoming Zig 0.12 are up in nixpkgs, most folks will
# want to continue to use the devShell and the instructions found at:
#
# https://github.com/mitchellh/ghostty/tree/main#developing-ghostty
#
{ lib
{
lib
, stdenv
, bzip2
@ -31,9 +25,7 @@
, ncurses
, pkg-config
, zig_0_12
}:
let
}: let
# The Zig hook has no way to select the release type without actual
# overriding of the default flags.
#
@ -57,7 +49,7 @@ let
# (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 = import ./zig_cache_hash.nix;
zigCacheHash = import ./zigCacheHash.nix;
zigCache = src: stdenv.mkDerivation {
inherit src;
@ -88,9 +80,7 @@ let
outputHashMode = "recursive";
outputHash = zigCacheHash;
};
in
stdenv.mkDerivation (finalAttrs: {
in stdenv.mkDerivation (finalAttrs: {
pname = "ghostty";
version = "0.1.0";

View File

@ -1,11 +1,16 @@
{ lib, stdenv, fetchFromGitHub, autoPatchelfHook }:
{
stdenv
, fetchFromGitHub
, autoPatchelfHook
}:
stdenv.mkDerivation rec {
version = "0.1.0-e7a96089";
pname = "wraptest";
src = fetchFromGitHub {
owner = "mattiase";
repo = "wraptest";
repo = pname;
rev = "e7a960892873035d2ef56b9770c32b43635821fb";
sha256 = "sha256-+v6xpPCmvKfsDkPmBSv6+6yAg2Kzame5Zwx2WKjQreI=";
};
@ -15,15 +20,23 @@ stdenv.mkDerivation rec {
];
buildPhase = ''
gcc -o wraptest wraptest.c
runHook preBuild
cc -O3 -o wraptest wraptest.c
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp wraptest $out/bin
cp wraptest $out/bin/
runHook postInstall
'';
meta = with lib; {
meta = {
description = "Test of DEC VT terminal line-wrapping semantics";
homepage = "https://github.com/mattiase/wraptest";
platforms = [ "aarch64-linux" "i686-linux" "x86_64-linux" ];

View File

@ -1,9 +1,9 @@
(import
(
let flake-compat = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.flake-compat; in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${flake-compat.locked.rev}.tar.gz";
sha256 = flake-compat.locked.narHash;
}
)
{ src = ./.; }).shellNix
(
let flake-compat = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.flake-compat; in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${flake-compat.locked.rev}.tar.gz";
sha256 = flake-compat.locked.narHash;
}
)
{ src = ./.; }).shellNix