Use Alejandra to format Nix modules.

This commit is contained in:
Jeffrey C. Ollie
2023-12-12 11:38:39 -06:00
parent 2f9750ad7f
commit c4ed1f1b80
7 changed files with 322 additions and 276 deletions

View File

@ -147,3 +147,13 @@ jobs:
nix_path: nixpkgs=channel:nixos-unstable nix_path: nixpkgs=channel:nixos-unstable
- name: prettier check - name: prettier check
run: nix develop -c prettier --check . run: nix develop -c prettier --check .
alejandra:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # Check out repo so we can lint it
- uses: cachix/install-nix-action@v24
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: alejandra check
run: nix develop -c alejandra --check .

View File

@ -492,6 +492,8 @@ on vastly improving this experience over time.
### Linting ### Linting
#### Prettier
Ghostty's docs and resources (not including Zig code) are linted using Ghostty's docs and resources (not including Zig code) are linted using
[Prettier](https://prettier.io) with out-of-the-box settings. A Prettier CI [Prettier](https://prettier.io) with out-of-the-box settings. A Prettier CI
check will fail builds with improper formatting. Therefore, if you are check will fail builds with improper formatting. Therefore, if you are
@ -502,7 +504,32 @@ run this from the repo root before you commit:
prettier --write . prettier --write .
``` ```
Make sure your Prettier version matches the version of in [devShell.nix](https://github.com/mitchellh/ghostty/blob/main/nix/devShell.nix). Make sure your Prettier version matches the version of Prettier in [devShell.nix](https://github.com/mitchellh/ghostty/blob/main/nix/devShell.nix).
Nix users can use the following command to format with Prettier:
```
nix develop -c prettier --write .
```
#### Alejandra
Nix modules are formatted with [Alejandra](https://github.com/kamadorueda/alejandra/). An Alejandra CI check
will fail builds with improper formatting.
Nix users can use the following command to format with Alejanda:
```
nix develop -c alejandra .
```
Non-Nix users should install Alejandra and use the follwing command to format with Alejanda:
```
alejandra .
```
Make sure your Alejandra version matches the version of Alejandra in [devShell.nix](https://github.com/mitchellh/ghostty/blob/main/nix/devShell.nix).
### Nix Package ### Nix Package

View File

@ -31,32 +31,33 @@
}; };
outputs = { outputs = {
nixpkgs-unstable nixpkgs-unstable,
, nixpkgs-stable nixpkgs-stable,
, nixpkgs-zig-0-12 nixpkgs-zig-0-12,
, zig zig,
, zls zls,
, ... ...
}: builtins.foldl' nixpkgs-stable.lib.recursiveUpdate {} (builtins.map (system: let }:
pkgs-stable = nixpkgs-stable.legacyPackages.${system}; builtins.foldl' nixpkgs-stable.lib.recursiveUpdate {} (builtins.map (system: let
pkgs-unstable = nixpkgs-unstable.legacyPackages.${system}; pkgs-stable = nixpkgs-stable.legacyPackages.${system};
pkgs-zig-0-12 = nixpkgs-zig-0-12.legacyPackages.${system}; pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
in { pkgs-zig-0-12 = nixpkgs-zig-0-12.legacyPackages.${system};
devShell.${system} = pkgs-stable.callPackage ./nix/devShell.nix { in {
inherit (pkgs-unstable) tracy; devShell.${system} = pkgs-stable.callPackage ./nix/devShell.nix {
inherit (zls.packages.${system}) zls; inherit (pkgs-unstable) tracy;
inherit (zls.packages.${system}) zls;
zig = zig.packages.${system}.master; zig = zig.packages.${system}.master;
wraptest = pkgs-stable.callPackage ./nix/wraptest.nix {}; wraptest = pkgs-stable.callPackage ./nix/wraptest.nix {};
};
packages.${system} = rec {
ghostty = pkgs-stable.callPackage ./nix/package.nix {
inherit (pkgs-zig-0-12) zig_0_12;
}; };
default = ghostty;
};
# Our supported systems are the same supported systems as the Zig binaries. packages.${system} = rec {
}) (builtins.attrNames zig.packages)); ghostty = pkgs-stable.callPackage ./nix/package.nix {
inherit (pkgs-zig-0-12) zig_0_12;
};
default = ghostty;
};
# Our supported systems are the same supported systems as the Zig binaries.
}) (builtins.attrNames zig.packages));
} }

View File

@ -1,139 +1,145 @@
{ {
mkShell mkShell,
, lib lib,
, stdenv stdenv,
bashInteractive,
, bashInteractive gdb,
, gdb #, glxinfo # unused
#, glxinfo # unused ncurses,
, ncurses nodejs,
, nodejs nodePackages,
, nodePackages oniguruma,
, oniguruma parallel,
, parallel pkg-config,
, pkg-config python3,
, python3 scdoc,
, scdoc tracy,
, tracy valgrind,
, valgrind #, vulkan-loader # unused
#, vulkan-loader # unused vttest,
, vttest wabt,
, wabt wasmtime,
, wasmtime wraptest,
, wraptest zig,
, zig zip,
, zip zls,
, zls llvmPackages_latest,
, llvmPackages_latest bzip2,
expat,
, bzip2 fontconfig,
, expat freetype,
, fontconfig glib,
, freetype gtk4,
, glib libadwaita,
, gtk4 harfbuzz,
, libadwaita libpng,
, harfbuzz libGL,
, libpng libX11,
, libGL libXcursor,
, libX11 libXext,
, libXcursor libXi,
, libXext libXinerama,
, libXi libXrandr,
, libXinerama pixman,
, libXrandr zlib,
, pixman alejandra,
, zlib }: let
}:
let
# See package.nix. Keep in sync. # See package.nix. Keep in sync.
rpathLibs = [ rpathLibs =
libGL [
] ++ lib.optionals stdenv.isLinux [ libGL
bzip2 ]
expat ++ lib.optionals stdenv.isLinux [
fontconfig bzip2
freetype expat
harfbuzz fontconfig
libpng freetype
oniguruma harfbuzz
pixman libpng
zlib oniguruma
pixman
zlib
libX11 libX11
libXcursor libXcursor
libXi libXi
libXrandr libXrandr
libadwaita libadwaita
gtk4 gtk4
glib glib
]; ];
in mkShell { in
name = "ghostty"; mkShell {
name = "ghostty";
nativeBuildInputs = [ nativeBuildInputs =
# For builds [
llvmPackages_latest.llvm # For builds
ncurses llvmPackages_latest.llvm
pkg-config ncurses
scdoc pkg-config
zig scdoc
zip zig
zls zip
zls
# For web and wasm stuff # For web and wasm stuff
nodejs nodejs
# Linting # Linting
nodePackages.prettier nodePackages.prettier
alejandra
# Testing # Testing
parallel parallel
python3 python3
tracy tracy
vttest vttest
# wasm # wasm
wabt wabt
wasmtime wasmtime
] ++ lib.optionals stdenv.isLinux [ ]
# My nix shell environment installs the non-interactive version ++ lib.optionals stdenv.isLinux [
# by default so we have to include this. # My nix shell environment installs the non-interactive version
bashInteractive # by default so we have to include this.
bashInteractive
gdb gdb
valgrind valgrind
wraptest wraptest
]; ];
buildInputs = [ buildInputs =
# TODO: non-linux [
] ++ lib.optionals stdenv.isLinux [ # TODO: non-linux
bzip2 ]
expat ++ lib.optionals stdenv.isLinux [
fontconfig bzip2
freetype expat
harfbuzz fontconfig
libpng freetype
oniguruma harfbuzz
pixman libpng
zlib oniguruma
pixman
zlib
libX11 libX11
libXcursor libXcursor
libXext libXext
libXi libXi
libXinerama libXinerama
libXrandr libXrandr
# Only needed for GTK builds # Only needed for GTK builds
libadwaita libadwaita
gtk4 gtk4
glib glib
]; ];
# This should be set onto the rpath of the ghostty binary if you want # This should be set onto the rpath of the ghostty binary if you want
# it to be "portable" across the system. # it to be "portable" across the system.
LD_LIBRARY_PATH = lib.makeLibraryPath rpathLibs; LD_LIBRARY_PATH = lib.makeLibraryPath rpathLibs;
} }

View File

@ -1,30 +1,26 @@
{ {
lib lib,
, stdenv stdenv,
bzip2,
, bzip2 expat,
, expat fontconfig,
, fontconfig freetype,
, freetype harfbuzz,
, harfbuzz libpng,
, libpng pixman,
, pixman zlib,
, zlib libGL,
libX11,
, libGL libXcursor,
, libX11 libXi,
, libXcursor libXrandr,
, libXi glib,
, libXrandr gtk4,
libadwaita,
, glib git,
, gtk4 ncurses,
, libadwaita pkg-config,
zig_0_12,
, git
, ncurses
, pkg-config
, 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.
@ -51,99 +47,103 @@
# 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 ./zigCacheHash.nix; zigCacheHash = import ./zigCacheHash.nix;
zigCache = src: stdenv.mkDerivation { zigCache = src:
inherit src; stdenv.mkDerivation {
name = "ghostty-cache"; inherit src;
nativeBuildInputs = [ git zig_0_12.hook ]; name = "ghostty-cache";
nativeBuildInputs = [git zig_0_12.hook];
dontConfigure = true;
dontUseZigBuild = true;
dontUseZigInstall = true;
dontFixup = true;
buildPhase = ''
runHook preBuild
zig build --fetch
runHook postBuild
'';
installPhase = ''
runHook preInstall
cp -r --reflink=auto $ZIG_GLOBAL_CACHE_DIR $out
runHook postInstall
'';
outputHashMode = "recursive";
outputHash = zigCacheHash;
};
in
stdenv.mkDerivation (finalAttrs: {
pname = "ghostty";
version = "0.1.0";
src = ./..;
nativeBuildInputs = [
git
ncurses
pkg-config
zig012Hook
];
buildInputs =
[
libGL
]
++ lib.optionals stdenv.isLinux [
bzip2
expat
fontconfig
freetype
harfbuzz
libpng
pixman
zlib
libX11
libXcursor
libXi
libXrandr
libadwaita
gtk4
glib
];
dontConfigure = true; dontConfigure = true;
dontUseZigBuild = true;
dontUseZigInstall = true;
dontFixup = true;
buildPhase = '' zigBuildFlags = "-Dversion-string=${finalAttrs.version}";
runHook preBuild
zig build --fetch preBuild = ''
rm -rf $ZIG_GLOBAL_CACHE_DIR
runHook postBuild cp -r --reflink=auto ${zigCache finalAttrs.src} $ZIG_GLOBAL_CACHE_DIR
chmod u+rwX -R $ZIG_GLOBAL_CACHE_DIR
''; '';
installPhase = '' outputs = ["out" "terminfo" "shell_integration"];
runHook preInstall
cp -r --reflink=auto $ZIG_GLOBAL_CACHE_DIR $out postInstall = ''
terminfo_src=${
if stdenv.isDarwin
then ''"$out/Applications/Ghostty.app/Contents/Resources/terminfo"''
else "$out/share/terminfo"
}
runHook postInstall mkdir -p $terminfo/share
cp -r "$terminfo_src" $terminfo/share/terminfo
mkdir -p $shell_integration
cp -r $out/share/shell-integration $shell_integration/shell-integration
''; '';
outputHashMode = "recursive"; meta = with lib; {
outputHash = zigCacheHash; homepage = "https://github.com/mitchellh/ghostty";
}; license = licenses.mit;
in stdenv.mkDerivation (finalAttrs: { platforms = ["x86_64-linux" "aarch64-linux" "aarch64-darwin"];
pname = "ghostty"; };
version = "0.1.0"; })
src = ./..;
nativeBuildInputs = [
git
ncurses
pkg-config
zig012Hook
];
buildInputs = [
libGL
] ++ lib.optionals stdenv.isLinux [
bzip2
expat
fontconfig
freetype
harfbuzz
libpng
pixman
zlib
libX11
libXcursor
libXi
libXrandr
libadwaita
gtk4
glib
];
dontConfigure = true;
zigBuildFlags = "-Dversion-string=${finalAttrs.version}";
preBuild = ''
rm -rf $ZIG_GLOBAL_CACHE_DIR
cp -r --reflink=auto ${zigCache finalAttrs.src} $ZIG_GLOBAL_CACHE_DIR
chmod u+rwX -R $ZIG_GLOBAL_CACHE_DIR
'';
outputs = [ "out" "terminfo" "shell_integration" ];
postInstall = ''
terminfo_src=${
if stdenv.isDarwin
then ''"$out/Applications/Ghostty.app/Contents/Resources/terminfo"''
else "$out/share/terminfo"
}
mkdir -p $terminfo/share
cp -r "$terminfo_src" $terminfo/share/terminfo
mkdir -p $shell_integration
cp -r $out/share/shell-integration $shell_integration/shell-integration
'';
meta = with lib; {
homepage = "https://github.com/mitchellh/ghostty";
license = licenses.mit;
platforms = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ];
};
})

View File

@ -1,9 +1,8 @@
{ {
stdenv stdenv,
, fetchFromGitHub fetchFromGitHub,
, autoPatchelfHook autoPatchelfHook,
}: }:
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
version = "0.1.0-e7a96089"; version = "0.1.0-e7a96089";
pname = "wraptest"; pname = "wraptest";
@ -39,6 +38,6 @@ stdenv.mkDerivation rec {
meta = { 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,12 @@
(import (import
( (
let flake-compat = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.flake-compat; in let
fetchTarball { flake-compat = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.flake-compat;
url = "https://github.com/edolstra/flake-compat/archive/${flake-compat.locked.rev}.tar.gz"; in
sha256 = flake-compat.locked.narHash; fetchTarball {
} url = "https://github.com/edolstra/flake-compat/archive/${flake-compat.locked.rev}.tar.gz";
) sha256 = flake-compat.locked.narHash;
{ src = ./.; }).shellNix }
)
{src = ./.;})
.shellNix