-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
203 lines (182 loc) · 5.49 KB
/
Copy pathflake.nix
File metadata and controls
203 lines (182 loc) · 5.49 KB
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
{
description = "rayon_tutorial";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
crane.url = "github:ipetkov/crane";
rustOverlay.url = "github:oxalica/rust-overlay";
devshell.url = "github:numtide/devshell";
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
};
outputs = {
self,
nixpkgs,
crane,
rustOverlay,
devshell,
advisory-db,
}: let
forAllSystems = function:
nixpkgs.lib.genAttrs [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
] (system: function rec {
pkgs = import nixpkgs {
inherit system;
overlays = [
(import rustOverlay)
devshell.overlays.default
];
};
rustToolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain:
toolchain.default.override {
extensions = ["rust-src"];
});
craneLib = crane.lib.${system}.overrideToolchain rustToolchain;
src = craneLib.cleanCargoSource ./.;
craneCommon = {
inherit src;
RUSTFLAGS = [
# Lint groups
["-D" "clippy::correctness"]
["-D" "clippy::complexity"]
["-D" "clippy::perf"]
["-D" "clippy::style"]
["-D" "clippy::nursery"]
["-D" "clippy::pedantic"]
# Allowed by default
["-D" "clippy::cognitive_complexity"]
["-D" "clippy::expect_used"]
["-D" "clippy::unwrap_used"]
["-D" "clippy::print_stderr"]
["-D" "clippy::print_stdout"]
["-D" "clippy::pub_use"]
["-D" "clippy::redundant_closure_for_method_calls"]
["-D" "clippy::single_char_lifetime_names"]
["-D" "clippy::str_to_string"]
["-D" "clippy::string_to_string"]
["-D" "clippy::unwrap_in_result"]
["-D" "clippy::wildcard_enum_match_arm"]
# Allow certain rules
["-A" "clippy::missing_errors_doc"]
["-A" "clippy::module_name_repetitions"]
# No warnings
# ["-D" "warnings"]
];
};
cargoArtifacts = craneLib.buildDepsOnly craneCommon;
rayon_tutorial = craneLib.buildPackage (craneCommon
// {
inherit cargoArtifacts;
});
});
in {
checks = forAllSystems ({
rayon_tutorial,
craneLib,
craneCommon,
cargoArtifacts,
src, ...
}: {
inherit rayon_tutorial;
rayon_tutorial-clippy = craneLib.cargoClippy (craneCommon
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets";
});
# Check formatting
rayon_tutorial-fmt = craneLib.cargoFmt {
inherit src;
};
# Audit dependencies
rayon_tutorial-audit = craneLib.cargoAudit {
inherit src advisory-db;
};
});
formatter = forAllSystems ({ pkgs, ... }: pkgs.alejandra);
packages = forAllSystems ({ rayon_tutorial, ... }: {
inherit rayon_tutorial;
default = rayon_tutorial;
});
apps = forAllSystems ({system, ...}: {
rayon_tutorial = {
type = "app";
program = "${self.packages.${system}.rayon_tutorial}/bin/rayon_tutorial";
};
default = self.apps.${system}.rayon_tutorial;
});
devShells = forAllSystems ({
craneCommon,
rustToolchain,
pkgs,
...
}: {
default = pkgs.devshell.mkShell {
commands = let
categories = {
hygiene = "hygiene";
development = "development";
};
in [
{
help = "Check rustc and clippy warnings";
name = "check";
command = ''
set -x
cargo check --all-targets
cargo clippy --all-targets
'';
category = categories.hygiene;
}
{
help = "Automatically fix rustc and clippy warnings";
name = "fix";
command = ''
set -x
cargo fix --all-targets --allow-dirty --allow-staged
cargo clippy --all-targets --fix --allow-dirty --allow-staged
'';
category = categories.hygiene;
}
{
help = "Run cargo in watch mode";
name = "watch";
command = "cargo watch";
category = categories.development;
}
];
imports = ["${devshell}/extra/language/rust.nix"];
language.rust = {
packageSet = rustToolchain;
tools = ["rustc"];
enableDefaultToolchain = false;
};
devshell = {
name = "rayon_tutorial-devshell";
packages = with pkgs; [
# Rust build inputs
clang
coreutils
# LSP's
rust-analyzer
# Tools
cargo-watch
rustToolchain
alejandra
#random
];
};
env = [
{
name = "RUSTFLAGS";
eval = "\"${builtins.toString craneCommon.RUSTFLAGS}\"";
}
];
};
});
};
}