-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
354 lines (290 loc) · 11 KB
/
flake.nix
File metadata and controls
354 lines (290 loc) · 11 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
{
description = "Hardware Report - A tool for generating hardware information reports";
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;
config = {
# Increase download buffer size to prevent warnings
download-buffer-size = 256 * 1024 * 1024; # 256 MB
};
};
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" ];
};
nativeBuildInputs = with pkgs; [
rustToolchain
pkg-config
];
buildInputs = with pkgs; [
openssl
] ++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.SystemConfiguration
];
# Runtime dependencies that the binary needs
runtimeDeps = with pkgs; [
numactl
ipmitool
ethtool
util-linux # for lscpu
pciutils # for lspci
dmidecode # for system/BIOS/memory information
];
hardware_report_unwrapped = pkgs.rustPlatform.buildRustPackage {
pname = "hardware_report_unwrapped";
version = "0.1.7";
src = builtins.path {
path = ./.;
name = "hardware-report-source";
};
cargoLock = {
lockFile = ./Cargo.lock;
};
inherit nativeBuildInputs buildInputs;
# Speed up builds in CI
CARGO_BUILD_JOBS = "4"; # Reduce parallelism to avoid OOM
CARGO_INCREMENTAL = "0"; # Disable incremental compilation in CI
# Use less memory during linking
CARGO_PROFILE_RELEASE_LTO = "thin";
CARGO_PROFILE_RELEASE_CODEGEN_UNITS = "16";
meta = with pkgs.lib; {
description = "A tool for generating hardware information reports";
homepage = "https://github.com/yourusername/hardware_report";
license = licenses.mit;
maintainers = [ ];
};
};
in
{
packages.default = pkgs.writeShellScriptBin "hardware_report" ''
export PATH="${pkgs.lib.makeBinPath runtimeDeps}:$PATH"
exec ${hardware_report_unwrapped}/bin/hardware_report "$@"
'';
packages.hardware_report = self.packages.${system}.default;
packages.deb = pkgs.stdenv.mkDerivation {
pname = "hardware-report";
version = "0.1.7";
src = self.packages.${system}.default;
nativeBuildInputs = with pkgs; [ dpkg ];
unpackPhase = "true";
buildPhase = ''
# Create debian package structure
mkdir -p hardware-report_0.1.7_amd64/{DEBIAN,usr/bin,usr/share/doc/hardware-report}
# Copy the actual binary (not the wrapper)
cp ${hardware_report_unwrapped}/bin/hardware_report hardware-report_0.1.7_amd64/usr/bin/
# Create control file
cat > hardware-report_0.1.7_amd64/DEBIAN/control << EOF
Package: hardware-report
Version: 0.1.7
Architecture: amd64
Maintainer: Kenny Sheridan <kenny@sfcompute.com>
Description: Hardware information collection tool
A tool for generating detailed hardware information reports from Linux servers,
outputting the data in TOML format for infrastructure standardization.
Depends: numactl, ipmitool, ethtool, util-linux, pciutils, dmidecode
Priority: optional
Section: utils
EOF
# Create copyright file
cat > hardware-report_0.1.7_amd64/usr/share/doc/hardware-report/copyright << EOF
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: hardware_report
Source: https://github.com/sfcompute/hardware_report
Files: *
Copyright: 2024 Kenny Sheridan
License: MIT
EOF
# Build the deb package
dpkg-deb --build hardware-report_0.1.7_amd64
'';
installPhase = ''
mkdir -p $out
cp hardware-report_0.1.7_amd64.deb $out/
'';
};
# Docker image
packages.dockerImage = pkgs.dockerTools.buildImage {
name = "hardware-report";
tag = "latest";
copyToRoot = pkgs.buildEnv {
name = "image-root";
paths = [ self.packages.${system}.default ] ++ runtimeDeps;
pathsToLink = [ "/bin" ];
};
config = {
Cmd = [ "/bin/hardware_report" ];
};
};
# Static binary for Alpine/musl
packages.static = let
muslPkgs = import nixpkgs {
inherit system;
crossSystem = {
config = "x86_64-unknown-linux-musl";
};
};
in muslPkgs.rustPlatform.buildRustPackage {
pname = "hardware_report-static";
version = "0.1.7";
src = builtins.path {
path = ./.;
name = "hardware-report-source";
};
cargoLock = {
lockFile = ./Cargo.lock;
};
nativeBuildInputs = with muslPkgs; [
pkg-config
];
buildInputs = with muslPkgs; [
openssl.dev
];
OPENSSL_STATIC = "1";
OPENSSL_LIB_DIR = "${muslPkgs.openssl.out}/lib";
OPENSSL_INCLUDE_DIR = "${muslPkgs.openssl.dev}/include";
meta = with pkgs.lib; {
description = "Static build of hardware_report";
homepage = "https://github.com/sfcompute/hardware_report";
license = licenses.mit;
};
};
# RPM package
packages.rpm = pkgs.stdenv.mkDerivation {
pname = "hardware-report";
version = "0.1.7";
src = self.packages.${system}.default;
nativeBuildInputs = with pkgs; [ rpm ];
unpackPhase = "true";
buildPhase = ''
mkdir -p rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
cat > rpmbuild/SPECS/hardware-report.spec << EOF
Name: hardware-report
Version: 0.1.7
Release: 1%{?dist}
Summary: Hardware information collection tool
License: MIT
URL: https://github.com/sfcompute/hardware_report
%description
A tool for generating detailed hardware information reports from Linux servers,
outputting the data in TOML format for infrastructure standardization.
%install
mkdir -p %{buildroot}%{_bindir}
cp ${hardware_report_unwrapped}/bin/hardware_report %{buildroot}%{_bindir}/
%files
%{_bindir}/hardware_report
%changelog
* $(date +"%a %b %d %Y") Kenny Sheridan <kenny@sfcompute.com> - 0.1.7-1
- Initial RPM release
EOF
rpmbuild --define "_topdir $(pwd)/rpmbuild" \
--define "_bindir /usr/bin" \
--define "buildroot $(pwd)/buildroot" \
-bb rpmbuild/SPECS/hardware-report.spec
'';
installPhase = ''
mkdir -p $out
cp rpmbuild/RPMS/*/*.rpm $out/
'';
};
devShells.default = pkgs.mkShell {
inherit buildInputs;
nativeBuildInputs = nativeBuildInputs ++ runtimeDeps ++ (with pkgs; [
rustToolchain
rust-analyzer
cargo-watch
cargo-edit
]);
shellHook = ''
echo "Hardware Report development environment"
echo "Run 'cargo build' to build the project"
echo "Run 'cargo run' to run the project"
echo ""
echo "Runtime dependencies are available in PATH:"
echo "- numactl, ipmitool, ethtool, lscpu, lspci, dmidecode"
'';
};
# CI checks
checks = {
# Build the package
package = self.packages.${system}.default;
# Run cargo tests using the same vendored deps as the main build
cargo-test = pkgs.stdenv.mkDerivation {
name = "cargo-test";
src = builtins.path {
path = ./.;
name = "hardware-report-source";
};
inherit nativeBuildInputs buildInputs;
cargoDeps = pkgs.rustPlatform.importCargoLock {
lockFile = ./Cargo.lock;
};
buildPhase = ''
export HOME=$TMPDIR
# Link vendor directory
ln -s $cargoDeps vendor
# Configure cargo to use vendored deps
mkdir -p .cargo
cat > .cargo/config.toml << EOF
[source.crates-io]
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "vendor"
EOF
${rustToolchain}/bin/cargo test --release --offline
'';
installPhase = ''
touch $out
'';
};
# Check formatting
cargo-fmt = pkgs.runCommand "cargo-fmt-check" {
inherit nativeBuildInputs;
src = builtins.path {
path = ./.;
name = "hardware-report-source";
};
} ''
cd $src
${rustToolchain}/bin/cargo fmt -- --check
touch $out
'';
# Run clippy using vendored deps
cargo-clippy = pkgs.stdenv.mkDerivation {
name = "cargo-clippy";
src = builtins.path {
path = ./.;
name = "hardware-report-source";
};
inherit nativeBuildInputs buildInputs;
cargoDeps = pkgs.rustPlatform.importCargoLock {
lockFile = ./Cargo.lock;
};
buildPhase = ''
export HOME=$TMPDIR
# Link vendor directory
ln -s $cargoDeps vendor
# Configure cargo to use vendored deps
mkdir -p .cargo
cat > .cargo/config.toml << EOF
[source.crates-io]
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "vendor"
EOF
${rustToolchain}/bin/cargo clippy --all-targets --offline -- -D warnings
'';
installPhase = ''
touch $out
'';
};
};
});
}