-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathflake.nix
211 lines (190 loc) · 6.01 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
{
description = "Description for the project";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
crane.url = "github:ipetkov/crane";
fenix.url = "github:nix-community/fenix/monthly";
fenix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
inputs@{
crane,
fenix,
flake-parts,
nixpkgs,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ ];
systems = [
"x86_64-linux"
"aarch64-linux"
];
perSystem =
{
config,
self',
inputs',
lib,
pkgs,
system,
...
}:
let
toolchain =
with fenix.packages.${system};
combine [
complete.toolchain
targets.aarch64-unknown-linux-gnu.latest.rust-std
targets.aarch64-unknown-linux-musl.latest.rust-std
targets.x86_64-unknown-linux-gnu.latest.rust-std
targets.x86_64-unknown-linux-musl.latest.rust-std
];
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
# https://github.com/ipetkov/crane/blob/master/docs/source-filtering.md
src = lib.cleanSourceWith {
name = "source";
src = ./.;
filter =
path: type:
(lib.hasInfix "/contrib/" path)
|| (lib.hasInfix "/crates/backend/assets/" path)
|| (lib.hasInfix "/crates/frontend/assets/" path)
|| (craneLib.filterCargoSources path type);
};
commonArgs = {
inherit src;
strictDeps = true;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
cargoFmt = craneLib.cargoFmt {
inherit src;
};
cargoClippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- -W clippy::pedantic -W clippy::nursery -A clippy::missing-errors-doc -A clippy::module_name_repetitions";
}
);
cargoNextest = craneLib.cargoNextest (
commonArgs
// {
inherit cargoArtifacts;
partitions = 1;
partitionType = "count";
}
);
# TODO: cargoHakari = craneLib.mkCargoDerivation
# https://crane.dev/examples/quick-start-workspace.html
buildHatsu =
args:
craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
}
// lib.optionalAttrs (!isNull args) args
);
hatsu = buildHatsu { };
in
{
checks = {
inherit
cargoFmt
cargoClippy
cargoNextest
hatsu
;
};
packages =
let
aarch64Args =
let
inherit (pkgs.pkgsCross.aarch64-multiplatform.stdenv) cc;
in
{
depsBuildBuild = [
cc
pkgs.qemu
];
HOST_CC = "${cc.nativePrefix}cc";
TARGET_CC = "${cc.targetPrefix}cc";
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER = "qemu-aarch64";
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = "${cc}/bin/${cc.targetPrefix}cc";
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUNNER = "qemu-aarch64";
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER = "${cc}/bin/${cc.targetPrefix}cc";
};
x86_64Args =
let
inherit (pkgs.stdenv) cc;
in
{
depsBuildBuild = [ cc ];
HOST_CC = "${cc.nativePrefix}cc";
TARGET_CC = "${cc.targetPrefix}cc";
};
muslArgs = {
# TODO: fix musl build
# https://crane.dev/examples/cross-musl.html
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
};
in
{
default = hatsu;
aarch64-unknown-linux-gnu = buildHatsu (
{
CARGO_BUILD_TARGET = "aarch64-unknown-linux-gnu";
}
// aarch64Args
);
aarch64-unknown-linux-musl = buildHatsu (
{
CARGO_BUILD_TARGET = "aarch64-unknown-linux-musl";
}
// aarch64Args
// muslArgs
);
x86_64-unknown-linux-gnu = buildHatsu (
{
CARGO_BUILD_TARGET = "x86_64-unknown-linux-gnu";
}
// x86_64Args
);
x86_64-unknown-linux-musl = buildHatsu (
{
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
}
// x86_64Args
// muslArgs
);
};
devShells.default = craneLib.devShell {
# checks = self'.checks.${system};
inputsFrom = [ hatsu ];
packages =
(with pkgs; [
mdbook # ./docs/
# cargo-*
cargo-hakari
cargo-nextest
cargo-watch
# sea-orm
sea-orm-cli
just
# mold
# sccache
])
++ (with fenix.packages.${system}; [
rust-analyzer
]);
};
};
flake = {
# The usual flake attributes can be defined here, including system-
# agnostic ones like nixosModule and system-enumerating ones, although
# those are more easily expressed in perSystem.
};
};
}