Skip to content

Commit c4ed1f1

Browse files
committed
Use Alejandra to format Nix modules.
1 parent 2f9750a commit c4ed1f1

File tree

7 files changed

+322
-276
lines changed

7 files changed

+322
-276
lines changed

.github/workflows/test.yml

+10
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,13 @@ jobs:
147147
nix_path: nixpkgs=channel:nixos-unstable
148148
- name: prettier check
149149
run: nix develop -c prettier --check .
150+
151+
alejandra:
152+
runs-on: ubuntu-latest
153+
steps:
154+
- uses: actions/checkout@v4 # Check out repo so we can lint it
155+
- uses: cachix/install-nix-action@v24
156+
with:
157+
nix_path: nixpkgs=channel:nixos-unstable
158+
- name: alejandra check
159+
run: nix develop -c alejandra --check .

README.md

+28-1
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@ on vastly improving this experience over time.
492492

493493
### Linting
494494

495+
#### Prettier
496+
495497
Ghostty's docs and resources (not including Zig code) are linted using
496498
[Prettier](https://prettier.io) with out-of-the-box settings. A Prettier CI
497499
check will fail builds with improper formatting. Therefore, if you are
@@ -502,7 +504,32 @@ run this from the repo root before you commit:
502504
prettier --write .
503505
```
504506

505-
Make sure your Prettier version matches the version of in [devShell.nix](https://github.com/mitchellh/ghostty/blob/main/nix/devShell.nix).
507+
Make sure your Prettier version matches the version of Prettier in [devShell.nix](https://github.com/mitchellh/ghostty/blob/main/nix/devShell.nix).
508+
509+
Nix users can use the following command to format with Prettier:
510+
511+
```
512+
nix develop -c prettier --write .
513+
```
514+
515+
#### Alejandra
516+
517+
Nix modules are formatted with [Alejandra](https://github.com/kamadorueda/alejandra/). An Alejandra CI check
518+
will fail builds with improper formatting.
519+
520+
Nix users can use the following command to format with Alejanda:
521+
522+
```
523+
nix develop -c alejandra .
524+
```
525+
526+
Non-Nix users should install Alejandra and use the follwing command to format with Alejanda:
527+
528+
```
529+
alejandra .
530+
```
531+
532+
Make sure your Alejandra version matches the version of Alejandra in [devShell.nix](https://github.com/mitchellh/ghostty/blob/main/nix/devShell.nix).
506533

507534
### Nix Package
508535

flake.nix

+26-25
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,33 @@
3131
};
3232

3333
outputs = {
34-
nixpkgs-unstable
35-
, nixpkgs-stable
36-
, nixpkgs-zig-0-12
37-
, zig
38-
, zls
39-
, ...
40-
}: builtins.foldl' nixpkgs-stable.lib.recursiveUpdate {} (builtins.map (system: let
41-
pkgs-stable = nixpkgs-stable.legacyPackages.${system};
42-
pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
43-
pkgs-zig-0-12 = nixpkgs-zig-0-12.legacyPackages.${system};
44-
in {
45-
devShell.${system} = pkgs-stable.callPackage ./nix/devShell.nix {
46-
inherit (pkgs-unstable) tracy;
47-
inherit (zls.packages.${system}) zls;
48-
49-
zig = zig.packages.${system}.master;
50-
wraptest = pkgs-stable.callPackage ./nix/wraptest.nix {};
51-
};
34+
nixpkgs-unstable,
35+
nixpkgs-stable,
36+
nixpkgs-zig-0-12,
37+
zig,
38+
zls,
39+
...
40+
}:
41+
builtins.foldl' nixpkgs-stable.lib.recursiveUpdate {} (builtins.map (system: let
42+
pkgs-stable = nixpkgs-stable.legacyPackages.${system};
43+
pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
44+
pkgs-zig-0-12 = nixpkgs-zig-0-12.legacyPackages.${system};
45+
in {
46+
devShell.${system} = pkgs-stable.callPackage ./nix/devShell.nix {
47+
inherit (pkgs-unstable) tracy;
48+
inherit (zls.packages.${system}) zls;
49+
50+
zig = zig.packages.${system}.master;
51+
wraptest = pkgs-stable.callPackage ./nix/wraptest.nix {};
52+
};
5253

53-
packages.${system} = rec {
54-
ghostty = pkgs-stable.callPackage ./nix/package.nix {
55-
inherit (pkgs-zig-0-12) zig_0_12;
54+
packages.${system} = rec {
55+
ghostty = pkgs-stable.callPackage ./nix/package.nix {
56+
inherit (pkgs-zig-0-12) zig_0_12;
57+
};
58+
default = ghostty;
5659
};
57-
default = ghostty;
58-
};
5960

60-
# Our supported systems are the same supported systems as the Zig binaries.
61-
}) (builtins.attrNames zig.packages));
61+
# Our supported systems are the same supported systems as the Zig binaries.
62+
}) (builtins.attrNames zig.packages));
6263
}

nix/devShell.nix

+131-125
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,145 @@
11
{
2-
mkShell
3-
, lib
4-
, stdenv
5-
6-
, bashInteractive
7-
, gdb
8-
#, glxinfo # unused
9-
, ncurses
10-
, nodejs
11-
, nodePackages
12-
, oniguruma
13-
, parallel
14-
, pkg-config
15-
, python3
16-
, scdoc
17-
, tracy
18-
, valgrind
19-
#, vulkan-loader # unused
20-
, vttest
21-
, wabt
22-
, wasmtime
23-
, wraptest
24-
, zig
25-
, zip
26-
, zls
27-
, llvmPackages_latest
28-
29-
, bzip2
30-
, expat
31-
, fontconfig
32-
, freetype
33-
, glib
34-
, gtk4
35-
, libadwaita
36-
, harfbuzz
37-
, libpng
38-
, libGL
39-
, libX11
40-
, libXcursor
41-
, libXext
42-
, libXi
43-
, libXinerama
44-
, libXrandr
45-
, pixman
46-
, zlib
47-
}:
48-
let
2+
mkShell,
3+
lib,
4+
stdenv,
5+
bashInteractive,
6+
gdb,
7+
#, glxinfo # unused
8+
ncurses,
9+
nodejs,
10+
nodePackages,
11+
oniguruma,
12+
parallel,
13+
pkg-config,
14+
python3,
15+
scdoc,
16+
tracy,
17+
valgrind,
18+
#, vulkan-loader # unused
19+
vttest,
20+
wabt,
21+
wasmtime,
22+
wraptest,
23+
zig,
24+
zip,
25+
zls,
26+
llvmPackages_latest,
27+
bzip2,
28+
expat,
29+
fontconfig,
30+
freetype,
31+
glib,
32+
gtk4,
33+
libadwaita,
34+
harfbuzz,
35+
libpng,
36+
libGL,
37+
libX11,
38+
libXcursor,
39+
libXext,
40+
libXi,
41+
libXinerama,
42+
libXrandr,
43+
pixman,
44+
zlib,
45+
alejandra,
46+
}: let
4947
# See package.nix. Keep in sync.
50-
rpathLibs = [
51-
libGL
52-
] ++ lib.optionals stdenv.isLinux [
53-
bzip2
54-
expat
55-
fontconfig
56-
freetype
57-
harfbuzz
58-
libpng
59-
oniguruma
60-
pixman
61-
zlib
48+
rpathLibs =
49+
[
50+
libGL
51+
]
52+
++ lib.optionals stdenv.isLinux [
53+
bzip2
54+
expat
55+
fontconfig
56+
freetype
57+
harfbuzz
58+
libpng
59+
oniguruma
60+
pixman
61+
zlib
6262

63-
libX11
64-
libXcursor
65-
libXi
66-
libXrandr
63+
libX11
64+
libXcursor
65+
libXi
66+
libXrandr
6767

68-
libadwaita
69-
gtk4
70-
glib
71-
];
72-
in mkShell {
73-
name = "ghostty";
68+
libadwaita
69+
gtk4
70+
glib
71+
];
72+
in
73+
mkShell {
74+
name = "ghostty";
7475

75-
nativeBuildInputs = [
76-
# For builds
77-
llvmPackages_latest.llvm
78-
ncurses
79-
pkg-config
80-
scdoc
81-
zig
82-
zip
83-
zls
76+
nativeBuildInputs =
77+
[
78+
# For builds
79+
llvmPackages_latest.llvm
80+
ncurses
81+
pkg-config
82+
scdoc
83+
zig
84+
zip
85+
zls
8486

85-
# For web and wasm stuff
86-
nodejs
87+
# For web and wasm stuff
88+
nodejs
8789

88-
# Linting
89-
nodePackages.prettier
90+
# Linting
91+
nodePackages.prettier
92+
alejandra
9093

91-
# Testing
92-
parallel
93-
python3
94-
tracy
95-
vttest
94+
# Testing
95+
parallel
96+
python3
97+
tracy
98+
vttest
9699

97-
# wasm
98-
wabt
99-
wasmtime
100-
] ++ lib.optionals stdenv.isLinux [
101-
# My nix shell environment installs the non-interactive version
102-
# by default so we have to include this.
103-
bashInteractive
100+
# wasm
101+
wabt
102+
wasmtime
103+
]
104+
++ lib.optionals stdenv.isLinux [
105+
# My nix shell environment installs the non-interactive version
106+
# by default so we have to include this.
107+
bashInteractive
104108

105-
gdb
106-
valgrind
107-
wraptest
108-
];
109+
gdb
110+
valgrind
111+
wraptest
112+
];
109113

110-
buildInputs = [
111-
# TODO: non-linux
112-
] ++ lib.optionals stdenv.isLinux [
113-
bzip2
114-
expat
115-
fontconfig
116-
freetype
117-
harfbuzz
118-
libpng
119-
oniguruma
120-
pixman
121-
zlib
114+
buildInputs =
115+
[
116+
# TODO: non-linux
117+
]
118+
++ lib.optionals stdenv.isLinux [
119+
bzip2
120+
expat
121+
fontconfig
122+
freetype
123+
harfbuzz
124+
libpng
125+
oniguruma
126+
pixman
127+
zlib
122128

123-
libX11
124-
libXcursor
125-
libXext
126-
libXi
127-
libXinerama
128-
libXrandr
129+
libX11
130+
libXcursor
131+
libXext
132+
libXi
133+
libXinerama
134+
libXrandr
129135

130-
# Only needed for GTK builds
131-
libadwaita
132-
gtk4
133-
glib
134-
];
136+
# Only needed for GTK builds
137+
libadwaita
138+
gtk4
139+
glib
140+
];
135141

136-
# This should be set onto the rpath of the ghostty binary if you want
137-
# it to be "portable" across the system.
138-
LD_LIBRARY_PATH = lib.makeLibraryPath rpathLibs;
139-
}
142+
# This should be set onto the rpath of the ghostty binary if you want
143+
# it to be "portable" across the system.
144+
LD_LIBRARY_PATH = lib.makeLibraryPath rpathLibs;
145+
}

0 commit comments

Comments
 (0)