forked from rmk-rs/rmk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
183 lines (164 loc) · 5.33 KB
/
Copy pathflake.nix
File metadata and controls
183 lines (164 loc) · 5.33 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
{
description = "RMK Rust development environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
nixpkgs,
fenix,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = nixpkgs.legacyPackages.${system};
lib = pkgs.lib;
fenixPkgs = fenix.packages.${system};
embeddedTargets = [
"thumbv6m-none-eabi"
"thumbv7m-none-eabi"
"thumbv7em-none-eabi"
"thumbv7em-none-eabihf"
"thumbv8m.main-none-eabihf"
"riscv32imc-unknown-none-elf"
"riscv32imac-unknown-none-elf"
];
stableToolchain = fenixPkgs.combine (
[
fenixPkgs.stable.cargo
fenixPkgs.stable.clippy
fenixPkgs.stable.llvm-tools
fenixPkgs.stable.rust-src
fenixPkgs.stable.rustc
fenixPkgs.stable.rustfmt
fenixPkgs.stable.rust-analyzer
]
++ map (target: fenixPkgs.targets.${target}.stable.rust-std) embeddedTargets
);
# RMK uses nightly for formatting and for a small smoke-check matrix.
nightlyToolchain = fenixPkgs.combine [
fenixPkgs.latest.cargo
fenixPkgs.latest.rustc
fenixPkgs.latest.rustfmt
];
# The repository's scripts intentionally use rustup-style invocations
# such as `cargo +stable` and `rustfmt +nightly`. Keep that interface
# while sourcing those toolchains from Fenix. The Xtensa-only `+esp`
# toolchain remains managed by espup and is delegated to rustup.
mkToolchainDispatcher = command:
pkgs.writeShellScriptBin command ''
toolchain=${lib.escapeShellArg (toString stableToolchain)}
case "''${1:-}" in
+stable)
shift
;;
+nightly)
toolchain=${lib.escapeShellArg (toString nightlyToolchain)}
shift
;;
+esp)
shift
exec ${pkgs.rustup}/bin/rustup run esp ${command} "$@"
;;
+*)
echo "unsupported Rust toolchain: $1" >&2
exit 2
;;
esac
export PATH="$toolchain/bin:$PATH"
export RUSTC="$toolchain/bin/rustc"
export RUSTDOC="$toolchain/bin/rustdoc"
exec "$toolchain/bin/${command}" "$@"
'';
toolchainDispatchers = pkgs.symlinkJoin {
name = "rmk-rust-toolchain-dispatchers";
paths = map mkToolchainDispatcher [
"cargo"
"clippy-driver"
"rustc"
"rustdoc"
"rustfmt"
];
};
# cargo-batch is not packaged in nixpkgs. This implements the subset
# used by .github/ci/check.sh, preserving its shared target directory
# while running each `---`-delimited Cargo command in order.
cargoBatch = pkgs.writeShellScriptBin "cargo-batch" ''
set -euo pipefail
if [[ "''${1:-}" == batch ]]; then
shift
fi
common_args=()
while (( $# > 0 )) && [[ "$1" != --- ]]; do
common_args+=("$1")
shift
done
while (( $# > 0 )); do
[[ "$1" == --- ]] || {
echo "cargo-batch: expected ---, got $1" >&2
exit 2
}
shift
(( $# > 0 )) || {
echo "cargo-batch: missing Cargo command after ---" >&2
exit 2
}
cargo_command="$1"
shift
command_args=()
while (( $# > 0 )) && [[ "$1" != --- ]]; do
command_args+=("$1")
shift
done
${toolchainDispatchers}/bin/cargo \
"$cargo_command" \
"''${common_args[@]}" \
"''${command_args[@]}"
done
'';
shellPackages = [
toolchainDispatchers
stableToolchain
cargoBatch
pkgs.cargo-binutils
pkgs.cargo-expand
pkgs.cargo-make
pkgs.cargo-nextest
pkgs.espflash
pkgs.espup
pkgs.flip-link
pkgs.just
pkgs.probe-rs-tools
];
in {
formatter = pkgs.alejandra;
checks.toolchains =
pkgs.runCommand "rmk-toolchains-check" {
nativeBuildInputs = shellPackages;
} ''
${toolchainDispatchers}/bin/cargo +stable --version
${toolchainDispatchers}/bin/cargo +nightly --version
${toolchainDispatchers}/bin/rustfmt +nightly --version
cargo-nextest --version
cargo-expand --version
touch "$out"
'';
devShells.default = pkgs.mkShell {
packages = shellPackages;
env = {
CARGO_NET_GIT_FETCH_WITH_CLI = "true";
RUST_MIN_STACK = "67108864";
RUST_SRC_PATH = "${stableToolchain}/lib/rustlib/src/rust/library";
};
shellHook = ''
export PATH="${toolchainDispatchers}/bin:$PATH"
'';
};
}
);
}