-
-
Notifications
You must be signed in to change notification settings - Fork 218
/
flake.nix
338 lines (304 loc) · 10.2 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# SPDX-FileCopyrightText: 2024 Christina Sørensen
# SPDX-License-Identifier: EUPL-1.2
#
# SPDX-FileCopyrightText: 2014-2024 Christina Sørensen, eza contributors
# SPDX-License-Identifier: MIT
{
description = "eza: a modern, maintained replacement for ls";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
flake-utils = {
url = "github:numtide/flake-utils";
inputs = {
systems.follows = "systems";
};
};
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
powertest = {
url = "github:eza-community/powertest";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
naersk.follows = "naersk";
treefmt-nix.follows = "treefmt-nix";
rust-overlay.follows = "rust-overlay";
};
};
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
};
outputs =
{
self,
flake-utils,
naersk,
nixpkgs,
treefmt-nix,
rust-overlay,
powertest,
pre-commit-hooks,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
overlays = [ (import rust-overlay) ];
pkgs = (import nixpkgs) {
inherit system overlays;
};
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
naersk' = pkgs.callPackage naersk {
cargo = toolchain;
rustc = toolchain;
clippy = toolchain;
};
treefmtEval = treefmt-nix.lib.evalModule pkgs .config/treefmt.nix;
darwinBuildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin [
pkgs.libiconv
pkgs.darwin.apple_sdk.frameworks.Security
];
buildInputs = [ pkgs.zlib ] ++ darwinBuildInputs;
in
rec {
# For `nix fmt`
formatter = treefmtEval.config.build.wrapper;
packages = {
# For `nix build` `nix run`, & `nix profile install`:
default = naersk'.buildPackage rec {
pname = "eza";
version = "git";
src = ./.;
doCheck = true; # run `cargo test` on build
inherit buildInputs;
nativeBuildInputs = with pkgs; [
cmake
pkg-config
installShellFiles
pandoc
];
buildNoDefaultFeatures = true;
buildFeatures = "git";
postInstall = ''
for page in eza.1 eza_colors.5 eza_colors-explanation.5; do
sed "s/\$version/${version}/g" "man/$page.md" |
pandoc --standalone -f markdown -t man >"man/$page"
done
installManPage man/eza.1 man/eza_colors.5 man/eza_colors-explanation.5
installShellCompletion \
--bash completions/bash/eza \
--fish completions/fish/eza.fish \
--zsh completions/zsh/_eza
'';
meta = with pkgs.lib; {
description = "A modern, maintained replacement for ls";
longDescription = ''
eza is a modern replacement for ls. It uses colours for information by
default, helping you distinguish between many types of files, such as
whether you are the owner, or in the owning group. It also has extra
features not present in the original ls, such as viewing the Git status
for a directory, or recursing into directories with a tree view. eza is
written in Rust, so it’s small, fast, and portable.
'';
homepage = "https://github.com/eza-community/eza";
license = licenses.mit;
mainProgram = "eza";
maintainers = with maintainers; [ cafkafk ];
};
};
# Run `nix build .#check` to check code
check = naersk'.buildPackage {
src = ./.;
mode = "check";
inherit buildInputs;
};
# Run `nix build .#test` to run tests
test = naersk'.buildPackage {
src = ./.;
mode = "test";
inherit buildInputs;
};
# Run `nix build .#clippy` to lint code
clippy = naersk'.buildPackage {
src = ./.;
mode = "clippy";
inherit buildInputs;
};
# Run `nix build .#trycmd` to run integration tests
trycmd = naersk'.buildPackage {
src = ./.;
mode = "test";
doCheck = true;
# No reason to wait for release build
release = false;
# buildPhase files differ between dep and main phase
singleStep = true;
# generate testing files
buildPhase = ''
bash devtools/dir-generator.sh tests/test_dir && echo "Dir generated"
bash devtools/generate-timestamp-test-dir.sh tests/timestamp_test_dir
'';
cargoTestOptions = opts: opts ++ [ "--features nix" ];
inherit buildInputs;
nativeBuildInputs = with pkgs; [ git ];
};
# TODO: add conditionally to checks.
# Run `nix build .#trycmd` to run integration tests
trycmd-local = naersk'.buildPackage {
src = ./.;
mode = "test";
doCheck = true;
# No reason to wait for release build
release = false;
# buildPhase files differ between dep and main phase
singleStep = true;
# set itests files creation date to unix epoch
buildPhase = ''
bash devtools/dir-generator.sh tests/test_dir
bash devtools/generate-timestamp-test-dir.sh tests/timestamp_test_dir
touch --date=@0 tests/itest/*
touch --date=@0 tests/ptests/*;
fd -e stdout -e stderr -H -t file -X sed -i 's/[CWD]\//\/build\/source\//g'
'';
cargoTestOptions =
opts:
opts
++ [
"--features nix"
"--features nix-local"
"--features powertest"
];
inherit buildInputs;
nativeBuildInputs = with pkgs; [ git ];
};
# Run `nix build .#trydump` to dump testing files
trydump = naersk'.buildPackage rec {
src = ./.;
mode = "test";
doCheck = true;
# No reason to wait for release build
release = false;
# buildPhase files differ between dep and main phase
singleStep = true;
# set itests files creation date to unix epoch
buildPhase = ''
bash devtools/dir-generator.sh tests/test_dir
bash devtools/generate-timestamp-test-dir.sh tests/timestamp_test_dir
touch --date=@0 tests/itest/*;
rm tests/cmd/*.stdout || echo;
rm tests/cmd/*.stderr || echo;
touch --date=@0 tests/ptests/*;
rm tests/ptests/*.stdout || echo;
rm tests/ptests/*.stderr || echo;
'';
cargoTestOptions =
opts:
opts
++ [
"--features nix"
"--features nix-local"
"--features powertest"
#"-F trycmd/debug"
];
TRYCMD = "dump";
postInstall = ''
fd -e stdout -e stderr -H -t file -X sed -i 's/\/build\/source\//[CWD]\//g'
cp dump $out -r
'';
inherit buildInputs;
nativeBuildInputs = with pkgs; [
fd
gnused
git
];
};
};
# For `nix develop`:
devShells.default = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
nativeBuildInputs =
with pkgs;
[
# cargo
# clippy
rustup
toolchain
just
pandoc
convco
zip
reuse
# For releases
b3sum
cargo-bump
# For generating demo
vhs
powertest.packages.${pkgs.system}.default
cargo-hack
cargo-udeps
cargo-outdated
]
++ darwinBuildInputs;
};
# For `nix flake check`
checks = {
pre-commit-check =
let
# some treefmt formatters are not supported in pre-commit-hooks we
# filter them out for now.
toFilter = [
"yamlfmt"
"nixfmt"
"taplo"
];
filterFn = n: _v: (!builtins.elem n toFilter);
treefmtFormatters = pkgs.lib.mapAttrs (_n: v: { inherit (v) enable; }) (
pkgs.lib.filterAttrs filterFn (import .config/treefmt.nix).programs
);
in
pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = treefmtFormatters // {
nixfmt-rfc-style.enable = true;
convco.enable = true; # not in treefmt
reuse = {
enable = true;
name = "reuse";
entry = with pkgs; "${reuse}/bin/reuse lint";
pass_filenames = false;
};
};
};
formatting = treefmtEval.config.build.check self;
build = packages.check;
inherit (packages)
default
test
trycmd
;
lint = packages.clippy;
};
}
);
}