-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
219 lines (190 loc) · 6.42 KB
/
Copy pathflake.nix
File metadata and controls
219 lines (190 loc) · 6.42 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
{
description = "littlefs2-tool";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{
self,
nixpkgs,
rust-overlay,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
cargoTomlTool = fromTOML (builtins.readFile "${self}/littlefs2-tool/Cargo.toml");
cDeps = with pkgs; [
clang
# clang_22
cmake
gnumake
gcc
];
rustDeps = with pkgs; [
pkg-config
];
buildDeps = with pkgs; [
mdbook
cargo-semver-checks
];
cLibs = with pkgs; [
libclang.lib
# llvmPackages_22.libclang.lib
];
bindgenEnv = {
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_gnu = toString [
"-isystem"
"${pkgs.glibc.dev}/include"
"-isystem"
"${pkgs.libclang.lib}/lib/clang/${pkgs.lib.versions.major pkgs.libclang.version}/include"
"-target"
"x86_64-unknown-linux-gnu"
];
};
cEnv = bindgenEnv // {
AR = "ar";
CC = "gcc";
# Picked up by both `devShells.default` and `packages.default`'s
# checkPhase (`cargo test`). Referencing pkgs.mklittlefs here is
# what makes Nix build/fetch it as part of either closure — no
# need to also list it in buildInputs/checkInputs separately.
MKLITTLEFS_CPP = "${pkgs.mklittlefs}/bin/mklittlefs";
};
in
with pkgs;
{
devShells.default = mkShell (
cEnv
// {
name = "lfs2-tool";
buildInputs = [
rust-bin.stable.latest.default
pkgs.mklittlefs # puts `mklittlefs` on PATH too, for cross_compat.sh
]
++ cDeps
++ cLibs
++ rustDeps
++ buildDeps;
LD_LIBRARY_PATH = "${lib.makeLibraryPath (cDeps ++ cLibs)}";
}
);
devShells.rp = mkShell (
bindgenEnv # ← was cEnv — drops the global CC="gcc" and AR="ar"
// {
name = "lfs2-rp";
buildInputs = [
self.packages.${system}.default
probe-rs-tools
picotool
gcc-arm-embedded # ← provides arm-none-eabi-gcc
(pkgs.rust-bin.stable.latest.default.override {
extensions = [
"rust-src"
"clippy"
"rust-analyzer"
];
targets = [
"thumbv8m.main-none-eabihf"
];
})
]
++ cDeps
++ cLibs
++ rustDeps;
# Tell the cc crate to use the ARM cross-compiler for this target
CC_thumbv8m_main_none_eabihf = "arm-none-eabi-gcc";
AR_thumbv8m_main_none_eabihf = "arm-none-eabi-ar";
LD_LIBRARY_PATH = lib.makeLibraryPath (cDeps ++ cLibs ++ [ stdenv.cc.cc.lib ]);
shellHook = ''
if [ ! -f /etc/udev/rules.d/69-probe-rs.rules ]; then
echo "⚠ No probe-rs udev rules found. Run once to fix:"
echo " curl -o /tmp/69-probe-rs.rules https://probe.rs/files/69-probe-rs.rules"
echo " sudo cp /tmp/69-probe-rs.rules /etc/udev/rules.d/"
echo " sudo udevadm control --reload-rules && sudo udevadm trigger"
echo ""
echo " Or if you're on NixOS, add a udev rule to your configuration:"
echo " services.udev.packages = ["
echo " (pkgs.writeTextFile {"
echo " name = \"probe-rs-udev-rules\";"
echo " destination = \"/etc/udev/rules.d/69-probe-rs.rules\"";
echo " text = '''"
echo " # Raspberry Pi / RP2350 (bootloader and debug probe)"
echo " ATTRS{idVendor}==\"2e8a\", MODE=\"0666\", GROUP=\"plugdev\""
echo " ''';"
echo " })"
echo " ];"
fi
'';
}
);
devShells.esp = mkShell (
bindgenEnv
// {
name = "lfs2-esp";
buildInputs = [
self.packages.${system}.default
# Don't include rust-bin here — espup manages the toolchain
rustup
espup
# ESP tooling
esptool
espflash
esp-generate
# Probe / debug
probe-rs-tools
openocd
python3
]
++ cDeps
++ cLibs
++ rustDeps;
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
LD_LIBRARY_PATH = lib.makeLibraryPath (
cDeps ++ cLibs ++ [ stdenv.cc.cc.lib ] # provides libstdc++.so.6
);
# Don't set CC or AR globally — let the cc crate
# find the xtensa cross-compiler from espup's PATH
shellHook = ''
if [ -f "$HOME/export-esp.sh" ]; then
source "$HOME/export-esp.sh"
fi
# Set CC for the xtensa target only, leaving host CC alone
export CC_xtensa_esp32s3_none_elf=xtensa-esp32s3-elf-gcc
export AR_xtensa_esp32s3_none_elf=xtensa-esp32s3-elf-ar
'';
}
);
packages.default = rustPlatform.buildRustPackage (
cEnv
// {
pname = cargoTomlTool.package.name;
version = cargoTomlTool.package.version;
src = self;
meta.mainProgram = "littlefs";
cargoLock = {
lockFile = "${self}/Cargo.lock";
outputHashes = { };
};
nativeBuildInputs = [ pkg-config ] ++ cDeps;
buildInputs = cLibs;
cargoBuildFlags = [
"--package"
"littlefs2-tool"
];
cargoTestFlags = [
"--package"
"littlefs2-tool"
];
postInstall = "";
}
);
}
);
}