-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathflake.nix
185 lines (164 loc) · 4.72 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
{
description = "A flake for flake projects";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
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,
flake-utils,
crane,
rustOverlay,
devshell,
advisory-db,
}: let
utils = flake-utils.lib;
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
in
utils.eachSystem supportedSystems (system: let
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.mkLib pkgs).overrideToolchain rustToolchain;
src = craneLib.cleanCargoSource ./.;
craneCommon = {
inherit src;
buildInputs = [
pkgs.pkg-config
pkgs.openssl
] ++ (if pkgs.stdenv.isDarwin then [pkgs.darwin.apple_sdk.frameworks.Security] else []);
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;
template-picker = craneLib.buildPackage (craneCommon
// {
inherit cargoArtifacts;
});
in {
checks = {
inherit template-picker;
template-picker-clippy = craneLib.cargoClippy (craneCommon
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets";
});
# Check formatting
template-picker-fmt = craneLib.cargoFmt {
inherit src;
};
# Audit dependencies
template-picker-audit = craneLib.cargoAudit {
inherit src advisory-db;
};
};
packages.default = template-picker;
apps = {
default = utils.mkApp {
drv = template-picker;
};
};
formatter = pkgs.alejandra;
devShells.default = pkgs.devshell.mkShell {
commands = let
categories = {
hygiene = "hygiene";
};
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;
}
];
imports = ["${devshell}/extra/language/rust.nix"];
language.rust = {
packageSet = rustToolchain;
tools = ["rustc"];
enableDefaultToolchain = false;
};
devshell = {
name = "templates-devshell";
packages = with pkgs; [
# Rust build inputs
clang
coreutils
# LSP's
rust-analyzer
# Tools
cargo-watch
rustToolchain
alejandra
];
};
env = [
{
name = "RUSTFLAGS";
eval = "\"${builtins.toString craneCommon.RUSTFLAGS}\"";
}
];
};
})
// (import ./templates.nix);
}