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,13 +31,14 @@
}; };
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 }:
builtins.foldl' nixpkgs-stable.lib.recursiveUpdate {} (builtins.map (system: let
pkgs-stable = nixpkgs-stable.legacyPackages.${system}; pkgs-stable = nixpkgs-stable.legacyPackages.${system};
pkgs-unstable = nixpkgs-unstable.legacyPackages.${system}; pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
pkgs-zig-0-12 = nixpkgs-zig-0-12.legacyPackages.${system}; pkgs-zig-0-12 = nixpkgs-zig-0-12.legacyPackages.${system};

View File

@ -1,55 +1,55 @@
{ {
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 libGL
] ++ lib.optionals stdenv.isLinux [ ]
++ lib.optionals stdenv.isLinux [
bzip2 bzip2
expat expat
fontconfig fontconfig
@ -69,10 +69,12 @@ let
gtk4 gtk4
glib glib
]; ];
in mkShell { in
mkShell {
name = "ghostty"; name = "ghostty";
nativeBuildInputs = [ nativeBuildInputs =
[
# For builds # For builds
llvmPackages_latest.llvm llvmPackages_latest.llvm
ncurses ncurses
@ -87,6 +89,7 @@ in mkShell {
# Linting # Linting
nodePackages.prettier nodePackages.prettier
alejandra
# Testing # Testing
parallel parallel
@ -97,7 +100,8 @@ in mkShell {
# wasm # wasm
wabt wabt
wasmtime wasmtime
] ++ lib.optionals stdenv.isLinux [ ]
++ lib.optionals stdenv.isLinux [
# My nix shell environment installs the non-interactive version # My nix shell environment installs the non-interactive version
# by default so we have to include this. # by default so we have to include this.
bashInteractive bashInteractive
@ -107,9 +111,11 @@ in mkShell {
wraptest wraptest
]; ];
buildInputs = [ buildInputs =
[
# TODO: non-linux # TODO: non-linux
] ++ lib.optionals stdenv.isLinux [ ]
++ lib.optionals stdenv.isLinux [
bzip2 bzip2
expat expat
fontconfig fontconfig
@ -136,4 +142,4 @@ in mkShell {
# 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,10 +47,11 @@
# 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:
stdenv.mkDerivation {
inherit src; inherit src;
name = "ghostty-cache"; name = "ghostty-cache";
nativeBuildInputs = [ git zig_0_12.hook ]; nativeBuildInputs = [git zig_0_12.hook];
dontConfigure = true; dontConfigure = true;
dontUseZigBuild = true; dontUseZigBuild = true;
@ -80,7 +77,8 @@
outputHashMode = "recursive"; outputHashMode = "recursive";
outputHash = zigCacheHash; outputHash = zigCacheHash;
}; };
in stdenv.mkDerivation (finalAttrs: { in
stdenv.mkDerivation (finalAttrs: {
pname = "ghostty"; pname = "ghostty";
version = "0.1.0"; version = "0.1.0";
@ -93,9 +91,11 @@ in stdenv.mkDerivation (finalAttrs: {
zig012Hook zig012Hook
]; ];
buildInputs = [ buildInputs =
[
libGL libGL
] ++ lib.optionals stdenv.isLinux [ ]
++ lib.optionals stdenv.isLinux [
bzip2 bzip2
expat expat
fontconfig fontconfig
@ -125,7 +125,7 @@ in stdenv.mkDerivation (finalAttrs: {
chmod u+rwX -R $ZIG_GLOBAL_CACHE_DIR chmod u+rwX -R $ZIG_GLOBAL_CACHE_DIR
''; '';
outputs = [ "out" "terminfo" "shell_integration" ]; outputs = ["out" "terminfo" "shell_integration"];
postInstall = '' postInstall = ''
terminfo_src=${ terminfo_src=${
@ -144,6 +144,6 @@ in stdenv.mkDerivation (finalAttrs: {
meta = with lib; { meta = with lib; {
homepage = "https://github.com/mitchellh/ghostty"; homepage = "https://github.com/mitchellh/ghostty";
license = licenses.mit; license = licenses.mit;
platforms = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ]; 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
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