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 | | macOS | [Tip ("Nightly")](https://github.com/mitchellh/ghostty/releases/tag/tip) | MacOS 12+ Universal Binary |
| Linux | [Build from Source](#developing-ghostty) | | | Linux | [Build from Source](#developing-ghostty) | |
| Linux (NixOS/Nix) | [Use the Flake](#nix-package) | |
| Windows | [Build from Source](#developing-ghostty) | [Notes](#windows-notes) | | Windows | [Build from Source](#developing-ghostty) | [Notes](#windows-notes) |
### Configuration ### Configuration
@ -505,50 +506,42 @@ Make sure your Prettier version matches the version of in [devshell.nix](https:/
### Nix Package ### Nix Package
> [!WARNING] There is Nix package that can be used in the flake (`packages.ghostty` or `packages.default`).
> The Nix package currently depends on versions of LLVM and Zig that are It can be used in NixOS configurations and otherwise built off of.
> 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 a functional Nix package that can be used in the `flake.nix` file Below is an example:
(`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:
```nix ```nix
{ {
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 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 = { ghostty = {
url = "git+ssh://git@github.com/mitchellh/ghostty"; url = "git+ssh://git@github.com/mitchellh/ghostty";
inputs.nixpkgs.follows = "nixpkgs";
}; };
}; };
outputs = { nixpkgs, ghostty, ... }: { outputs = { nixpkgs, ghostty, ... }: {
nixosConfigurations.nixos = nixpkgs.lib.nixosSystem { nixosConfigurations.mysystem = nixpkgs.lib.nixosSystem {
modules = [ modules = [
{ {
nixpkgs.overlays = [ environment.systemPackages = [
(final: prev: { ghostty.packages.x86_64-linux.default
ghostty = ghostty.packages.${prev.system}.ghostty;
})
]; ];
} }
# 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 #### 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 ./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. that can then be committed and pushed to fix the builds.

111
flake.lock generated
View File

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

View File

@ -1,11 +1,13 @@
{ {
description = "ghostty"; description = "👻";
inputs = { inputs = {
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable"; nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
zig.url = "github:mitchellh/zig-overlay"; # We want to stay as up to date as possible but need to be careful that the
zls-master.url = "github:zigtools/zls/master"; # 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 # This is a nixpkgs mirror (based off of nixos-unstable) that contains
# patches for LLVM 17 and Zig 0.12 (master/nightly). # 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. # 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"; 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 zig = {
# glibc versions used by our dependencies from Nix are compatible with the url = "github:mitchellh/zig-overlay";
# system glibc that the user is building for. inputs.nixpkgs.follows = "nixpkgs-stable";
nixpkgs.url = "github:nixos/nixpkgs/release-23.05"; };
# Used for shell.nix zls = {
flake-compat = { url = github:edolstra/flake-compat; flake = false; }; url = "github:zigtools/zls/master";
inputs.nixpkgs.follows = "nixpkgs-stable";
};
}; };
outputs = { self, nixpkgs, flake-utils, ... }@inputs: outputs = {
let nixpkgs-unstable
overlays = [ , nixpkgs-stable
# Our repo overlay , nixpkgs-zig-0-12
(import ./nix/overlay.nix) , 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 zig = zig.packages.${system}.master;
(final: prev: { wraptest = pkgs-stable.callPackage ./nix/wraptest.nix {};
zigpkgs = inputs.zig.packages.${prev.system}; };
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 # Our supported systems are the same supported systems as the Zig binaries.
tracy = inputs.nixpkgs-unstable.legacyPackages.${prev.system}.tracy; }) (builtins.attrNames zig.packages));
# 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;
}
);
} }

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

View File

@ -1,8 +1,11 @@
{ mkShell, lib, stdenv {
mkShell
, lib
, stdenv
, bashInteractive , bashInteractive
, gdb , gdb
, glxinfo #, glxinfo # unused
, ncurses , ncurses
, nodejs , nodejs
, nodePackages , nodePackages
@ -13,7 +16,7 @@
, scdoc , scdoc
, tracy , tracy
, valgrind , valgrind
, vulkan-loader #, vulkan-loader # unused
, vttest , vttest
, wabt , wabt
, wasmtime , wasmtime
@ -66,7 +69,7 @@ let
gtk4 gtk4
glib glib
]; ];
in mkShell rec { in mkShell {
name = "ghostty"; name = "ghostty";
nativeBuildInputs = [ 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. lib
# 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
, stdenv , stdenv
, bzip2 , bzip2
@ -31,9 +25,7 @@
, ncurses , ncurses
, pkg-config , pkg-config
, zig_0_12 , zig_0_12
}: }: let
let
# The Zig hook has no way to select the release type without actual # The Zig hook has no way to select the release type without actual
# overriding of the default flags. # overriding of the default flags.
# #
@ -57,7 +49,7 @@ let
# (It's also possible that you might see a hash mismatch - without the # (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 # 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.) # 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 { zigCache = src: stdenv.mkDerivation {
inherit src; inherit src;
@ -88,9 +80,7 @@ let
outputHashMode = "recursive"; outputHashMode = "recursive";
outputHash = zigCacheHash; outputHash = zigCacheHash;
}; };
in in stdenv.mkDerivation (finalAttrs: {
stdenv.mkDerivation (finalAttrs: {
pname = "ghostty"; pname = "ghostty";
version = "0.1.0"; version = "0.1.0";

View File

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

View File

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