-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathflake.nix
230 lines (217 loc) · 7.39 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
{
description = "tui-term - a pseudoterminal widget for ratatui";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
inputs.rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
inputs.crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
outputs = {
self,
nixpkgs,
flake-utils,
rust-overlay,
crane,
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = nixpkgs.legacyPackages.${system};
stdenv =
if pkgs.stdenv.isLinux
then pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv
else pkgs.stdenv;
overlays = [(import rust-overlay)];
rustPkgs = import nixpkgs {inherit system overlays;};
src = self;
RUST_TOOLCHAIN = src + "/rust-toolchain.toml";
RUSTFMT_TOOLCHAIN = src + "/.rustfmt-toolchain.toml";
cargoTOML = builtins.fromTOML (builtins.readFile (src + "/Cargo.toml"));
inherit (cargoTOML.package) name rust-version version;
rustToolchainTOML = rustPkgs.rust-bin.fromRustupToolchainFile RUST_TOOLCHAIN;
# toolchainTOML = builtins.fromTOML (builtins.readFile RUST_TOOLCHAIN);
# toolchainVersion = toolchainTOML.toolchain.channel;
# rustToolchainTOML = rustPkgs.rust-bin.stable.${toolchainVersion}.minimal;
rustFmtToolchainTOML =
rustPkgs.rust-bin.fromRustupToolchainFile
RUSTFMT_TOOLCHAIN;
rustToolchainDevTOML = rustToolchainTOML.override {
extensions = [
"clippy"
"rust-analysis"
"rust-docs"
];
targets = [];
};
rustToolchainMSRV = rustPkgs.rust-bin.stable.${rust-version}.default.override {
extensions = [
"rustfmt"
"clippy"
"rust-analysis"
"rust-docs"
];
targets = [];
};
# the example targets
examples = [
"simple_ls_chan"
"simple_ls_rw"
"smux"
"long_running"
"nested_shell"
"nested_shell_async"
];
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchainTOML;
craneLibMSRV = (crane.mkLib pkgs).overrideToolchain rustToolchainMSRV;
mkExample = {example, ...}:
craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts stdenv;
pname = example;
cargoExtraArgs = "--example ${example}";
# Prevent cargo test and nextest from duplicating tests
doCheck = false;
}
);
# Common arguments for the crane build
commonArgs = {
src = craneLib.cleanCargoSource (craneLib.path ./.);
inherit stdenv version;
};
# Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
cargoArtifactsMSRV = craneLibMSRV.buildDepsOnly commonArgs;
cargoNextest = craneLib.cargoNextest {
inherit cargoArtifacts src;
partitions = 1;
partitionType = "count";
cargoNextestExtraArgs = "--features unstable";
};
cargoDoc = craneLib.cargoDoc (commonArgs // {inherit cargoArtifacts;});
devInputs = [
rustToolchainDevTOML
rustFmtToolchainTOML
pkgs.just
pkgs.cargo-watch
# snapshot testing
pkgs.cargo-insta
#alternative linker
pkgs.llvmPackages.bintools
pkgs.mold
pkgs.clang
];
msrvDevInputs = [rustToolchainMSRV];
lintInputs = [
pkgs.reuse
pkgs.lychee
pkgs.typos
pkgs.taplo
pkgs.cargo-deny
pkgs.cargo-diet
pkgs.cargo-dist
pkgs.cargo-flamegraph
pkgs.cargo-machete
pkgs.cargo-modules
pkgs.cargo-outdated
pkgs.cargo-tarpaulin
# pkgs.cargo-unused-features
(pkgs.symlinkJoin {
name = "cargo-udeps-wrapped";
paths = [pkgs.cargo-udeps];
nativeBuildInputs = [pkgs.makeWrapper];
postBuild = ''
wrapProgram $out/bin/cargo-udeps \
--prefix PATH : ${
pkgs.lib.makeBinPath [
(rustPkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default))
]
}
'';
})
(pkgs.symlinkJoin {
name = "cargo-careful-wrapped";
paths = [pkgs.cargo-careful];
nativeBuildInputs = [pkgs.makeWrapper];
postBuild = ''
wrapProgram $out/bin/cargo-careful \
--prefix PATH : ${
pkgs.lib.makeBinPath [
(rustPkgs.rust-bin.selectLatestNightlyWith (
toolchain: toolchain.default.override {extensions = ["rust-src"];}
))
]
}
'';
})
(pkgs.symlinkJoin {
name = "cargo-public-api-wrapped";
paths = [pkgs.cargo-public-api];
nativeBuildInputs = [pkgs.makeWrapper];
postBuild = ''
wrapProgram $out/bin/cargo-public-api \
--prefix PATH : ${
pkgs.lib.makeBinPath [
(rustPkgs.rust-bin.selectLatestNightlyWith (
toolchain: toolchain.default.override {extensions = ["rust-src"];}
))
]
}
'';
})
];
shellInputs = [
pkgs.shellcheck
pkgs.actionlint
];
fmtInputs = [
rustFmtToolchainTOML
pkgs.alejandra
pkgs.treefmt
pkgs.taplo
];
editorConfigInputs = [pkgs.editorconfig-checker];
actionlintInputs = [pkgs.actionlint];
in {
devShells = {
default = (pkgs.mkShell.override {inherit stdenv;}) {
buildInputs = shellInputs ++ devInputs ++ fmtInputs;
inherit name;
RUST_BACKTRACE = true;
RUSTFLAGS = "-C linker=clang -C link-arg=-fuse-ld=${pkgs.mold}/bin/mold -C target-cpu=native";
};
msrvShell = (pkgs.mkShell.override {inherit stdenv;}) {
buildInputs = msrvDevInputs;
name = "msrvShell";
RUST_BACKTRACE = true;
RUSTFLAGS = "-C linker=clang -C link-arg=-fuse-ld=${pkgs.mold}/bin/mold -C target-cpu=native";
};
editorConfigShell = pkgs.mkShell {buildInputs = editorConfigInputs;};
actionlintShell = pkgs.mkShell {buildInputs = actionlintInputs;};
fmtShell = pkgs.mkShell {buildInputs = fmtInputs;};
lintShell = pkgs.mkShell {buildInputs = lintInputs;};
};
packages =
{
inherit
cargoArtifacts
cargoArtifactsMSRV
cargoNextest
cargoDoc
;
default = self.outputs.packages.${system}.smux;
}
// pkgs.lib.genAttrs examples (
example: mkExample {inherit example cargoArtifacts craneLib;}
);
formatter = pkgs.alejandra;
apps.default = {
type = "app";
program = "${self.outputs.packages.${system}.smux}/bin/smux";
};
}
);
}