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
- name: 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
#### Prettier
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
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 .
```
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

View File

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

View File

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

View File

@ -1,30 +1,26 @@
{
lib
, stdenv
, bzip2
, expat
, fontconfig
, freetype
, harfbuzz
, libpng
, pixman
, zlib
, libGL
, libX11
, libXcursor
, libXi
, libXrandr
, glib
, gtk4
, libadwaita
, git
, ncurses
, pkg-config
, zig_0_12
lib,
stdenv,
bzip2,
expat,
fontconfig,
freetype,
harfbuzz,
libpng,
pixman,
zlib,
libGL,
libX11,
libXcursor,
libXi,
libXrandr,
glib,
gtk4,
libadwaita,
git,
ncurses,
pkg-config,
zig_0_12,
}: let
# The Zig hook has no way to select the release type without actual
# overriding of the default flags.
@ -51,10 +47,11 @@
# derivation in your store already. If so, just update the value as above.)
zigCacheHash = import ./zigCacheHash.nix;
zigCache = src: stdenv.mkDerivation {
zigCache = src:
stdenv.mkDerivation {
inherit src;
name = "ghostty-cache";
nativeBuildInputs = [ git zig_0_12.hook ];
nativeBuildInputs = [git zig_0_12.hook];
dontConfigure = true;
dontUseZigBuild = true;
@ -80,7 +77,8 @@
outputHashMode = "recursive";
outputHash = zigCacheHash;
};
in stdenv.mkDerivation (finalAttrs: {
in
stdenv.mkDerivation (finalAttrs: {
pname = "ghostty";
version = "0.1.0";
@ -93,9 +91,11 @@ in stdenv.mkDerivation (finalAttrs: {
zig012Hook
];
buildInputs = [
buildInputs =
[
libGL
] ++ lib.optionals stdenv.isLinux [
]
++ lib.optionals stdenv.isLinux [
bzip2
expat
fontconfig
@ -125,7 +125,7 @@ in stdenv.mkDerivation (finalAttrs: {
chmod u+rwX -R $ZIG_GLOBAL_CACHE_DIR
'';
outputs = [ "out" "terminfo" "shell_integration" ];
outputs = ["out" "terminfo" "shell_integration"];
postInstall = ''
terminfo_src=${
@ -144,6 +144,6 @@ in stdenv.mkDerivation (finalAttrs: {
meta = with lib; {
homepage = "https://github.com/mitchellh/ghostty";
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
, fetchFromGitHub
, autoPatchelfHook
stdenv,
fetchFromGitHub,
autoPatchelfHook,
}:
stdenv.mkDerivation rec {
version = "0.1.0-e7a96089";
pname = "wraptest";
@ -39,6 +38,6 @@ stdenv.mkDerivation rec {
meta = {
description = "Test of DEC VT terminal line-wrapping semantics";
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
(
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 {
url = "https://github.com/edolstra/flake-compat/archive/${flake-compat.locked.rev}.tar.gz";
sha256 = flake-compat.locked.narHash;
}
)
{ src = ./.; }).shellNix
{src = ./.;})
.shellNix