-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
491 lines (430 loc) · 17.9 KB
/
flake.nix
File metadata and controls
491 lines (430 loc) · 17.9 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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
{
description = "Starla - A Rust implementation of the RIPE Atlas Software Probe";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
git-hooks = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, rust-overlay, flake-utils, git-hooks }:
flake-utils.lib.eachDefaultSystem
(system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
rustToolchain = pkgs.rust-bin.nightly.latest.default.override {
extensions = [ "rust-src" "rust-analyzer" "clippy" "rustfmt" ];
targets = [
"x86_64-unknown-linux-gnu"
"aarch64-unknown-linux-gnu"
"armv7-unknown-linux-gnueabihf"
];
};
# Common build inputs for the Rust package
nativeBuildInputs = with pkgs; [
pkg-config
rustToolchain
clang
];
buildInputs = with pkgs; [
openssl
] ++ lib.optionals stdenv.isLinux [
glib
gtk3
libayatana-appindicator
xdotool
];
# Development shell packages
devPackages = with pkgs; [
# Version control
git
git-lfs
# Build essentials
pkg-config
openssl
gcc
gnumake
# Performance analysis
hyperfine
tokei
# Network tools (for testing)
netcat
curl
# Utilities
jq
ripgrep
fd
bat
eza
direnv
# Documentation
mdbook
graphviz
# Cargo tools
cargo-audit
cargo-outdated
cargo-watch
cargo-tarpaulin
# Signing
cosign
# Fuzzing
cargo-fuzz
] ++ lib.optionals stdenv.isLinux [
# Linux-specific
iproute2
tcpdump
];
pre-commit-check = git-hooks.lib.${system}.run {
src = ./.;
hooks = {
check-json.enable = true;
check-merge-conflicts.enable = true;
check-toml.enable = true;
check-yaml.enable = true;
detect-private-keys.enable = true;
end-of-file-fixer.enable = true;
mixed-line-endings.enable = true;
trim-trailing-whitespace.enable = true;
nixpkgs-fmt.enable = true;
rustfmt = {
enable = true;
packageOverrides.cargo = rustToolchain;
packageOverrides.rustfmt = rustToolchain;
};
# clippy is handled by checks.default and checks.minimal
# which use buildRustPackage with vendored dependencies.
# The pre-commit hook can't fetch crates in the nix sandbox.
};
};
in
{
packages = {
default = pkgs.rustPlatform.buildRustPackage {
pname = "starla";
version = "0.3.0";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
inherit nativeBuildInputs buildInputs;
doCheck = false;
meta = with pkgs.lib; {
description = "Starla - A Rust implementation of the RIPE Atlas Software Probe";
homepage = "https://github.com/ananthb/starla";
license = licenses.agpl3Only;
maintainers = [ ];
};
};
oci = pkgs.dockerTools.buildLayeredImage {
name = "ghcr.io/ananthb/starla";
tag = "latest";
contents = [
self.packages.${system}.default
pkgs.cacert
];
config = {
Entrypoint = [ "/bin/starla" ];
Env = [ "SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" ];
};
};
# Minimal build without observability features
minimal = pkgs.rustPlatform.buildRustPackage {
pname = "starla-minimal";
version = "0.3.0";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
inherit nativeBuildInputs buildInputs;
buildNoDefaultFeatures = true;
buildFeatures = [ "minimal" ];
doCheck = false;
meta = with pkgs.lib; {
description = "Starla (minimal build) - A Rust implementation of the RIPE Atlas Software Probe";
homepage = "https://github.com/ananthb/starla";
license = licenses.agpl3Only;
maintainers = [ ];
};
};
starla-tray = pkgs.rustPlatform.buildRustPackage {
pname = "starla-tray";
version = "0.3.0";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
inherit nativeBuildInputs buildInputs;
cargoBuildFlags = [ "-p" "starla-tray" ];
doCheck = false;
postInstall = pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
# macOS .app bundle for the tray: gives it a dock icon,
# proper app lifecycle, and allows launchd to manage it.
mkdir -p "$out/Applications/Starla Tray.app/Contents/MacOS"
mkdir -p "$out/Applications/Starla Tray.app/Contents/Resources"
cp $src/packaging/Info.plist "$out/Applications/Starla Tray.app/Contents/"
cp $src/assets/logo.icns "$out/Applications/Starla Tray.app/Contents/Resources/icon.icns"
cp $out/bin/starla-tray "$out/Applications/Starla Tray.app/Contents/MacOS/"
'';
meta = with pkgs.lib; {
description = "Starla system tray app";
homepage = "https://github.com/ananthb/starla";
license = licenses.agpl3Only;
maintainers = [ ];
};
};
} // pkgs.lib.optionalAttrs pkgs.stdenv.isLinux {
release =
let
pkg = self.packages.${system}.default;
tray = self.packages.${system}.starla-tray;
arch = if system == "x86_64-linux" then "amd64" else "arm64";
in
pkgs.runCommand "starla-${arch}.tar.gz"
{
nativeBuildInputs = [ pkgs.gzip pkgs.patchelf ];
} ''
mkdir -p starla
cp ${pkg}/bin/starla starla/starla
cp ${tray}/bin/starla-tray starla/starla-tray
chmod +w starla/starla starla/starla-tray
patchelf --remove-rpath starla/starla
patchelf --remove-rpath starla/starla-tray
cp ${./config.toml.example} starla/config.toml.example
cp ${./starla.service} starla/starla.service
cp ${./packaging/starla-tray.desktop} starla/starla-tray.desktop
tar -czvf $out -C . starla
'';
appimage =
let
tray = self.packages.${system}.starla-tray;
arch = if system == "x86_64-linux" then "x86_64" else "aarch64";
appimageRuntime = pkgs.fetchurl (if system == "x86_64-linux" then {
url = "https://github.com/AppImage/type2-runtime/releases/download/20251108/runtime-x86_64";
hash = "sha256-L8qLRDySUQ8Ug6iD9gBhrQm0a5eLJjHIB82HOkfsJg0=";
} else {
url = "https://github.com/AppImage/type2-runtime/releases/download/20251108/runtime-aarch64";
hash = "sha256-AMvfz5F8xsD/bTNH1Z4Moff0Wm3xpCig1tinhmTYdEQ=";
});
libDeps = with pkgs; [
glib
gtk3
libayatana-appindicator
pango
cairo
gdk-pixbuf
atk
harfbuzz
fontconfig
freetype
xorg.libX11
xorg.libXcursor
xorg.libXrandr
xorg.libXi
xorg.libXext
xorg.libXrender
xorg.libXfixes
xorg.libXcomposite
xorg.libXdamage
xorg.libxcb
libxkbcommon
wayland
xdotool
];
in
pkgs.runCommand "starla-tray-${arch}.AppImage"
{
nativeBuildInputs = with pkgs; [ squashfsTools patchelf ];
} ''
mkdir -p AppDir/usr/bin
mkdir -p AppDir/usr/lib
mkdir -p AppDir/usr/share/applications
cp ${tray}/bin/starla-tray AppDir/usr/bin/
chmod +w AppDir/usr/bin/*
patchelf --remove-rpath AppDir/usr/bin/starla-tray
# Bundle shared libraries so the AppImage is self-contained.
for dir in ${pkgs.lib.concatStringsSep " " (map (d: "${d}/lib") libDeps)}; do
if [ -d "$dir" ]; then
for so in "$dir"/*.so "$dir"/*.so.*; do
[ -e "$so" ] || continue
cp -n "$(readlink -f "$so")" "AppDir/usr/lib/$(basename "$so")" 2>/dev/null || true
done
fi
done
cp ${./packaging/starla-tray.desktop} AppDir/starla-tray.desktop
cp ${./packaging/starla-tray.desktop} AppDir/usr/share/applications/
cat > AppDir/AppRun << 'APPRUN'
#!/bin/bash
set -e
SELF=$(readlink -f "$0")
APPDIR=''${SELF%/*}
export LD_LIBRARY_PATH="''${APPDIR}/usr/lib:''${LD_LIBRARY_PATH}"
export GSETTINGS_SCHEMA_DIR="/usr/share/glib-2.0/schemas:''${GSETTINGS_SCHEMA_DIR}"
exec "''${APPDIR}/usr/bin/starla-tray" "$@"
APPRUN
chmod +x AppDir/AppRun
mksquashfs AppDir appimage.squashfs -root-owned -noappend -comp zstd -quiet -no-progress
cat ${appimageRuntime} appimage.squashfs > $out
chmod +x $out
'';
} // pkgs.lib.optionalAttrs pkgs.stdenv.isDarwin {
release =
let
pkg = self.packages.${system}.default;
tray = self.packages.${system}.starla-tray;
arch = if system == "x86_64-darwin" then "amd64" else "arm64";
in
pkgs.runCommand "starla-macos-${arch}.dmg"
{
nativeBuildInputs = [ pkgs.cctools ];
}
''
export PATH="/usr/bin:$PATH"
mkdir -p staging
# Copy the .app bundle from the tray package
cp -rL "${tray}/Applications/Starla Tray.app" staging/
chmod -R u+w staging/
# Add the CLI probe binary into the .app bundle
cp ${pkg}/bin/starla "staging/Starla Tray.app/Contents/MacOS/"
# Rewrite any /nix/store dylib references to /usr/lib
# so binaries work on non-Nix macOS systems.
for bin in "staging/Starla Tray.app/Contents/MacOS/starla" \
"staging/Starla Tray.app/Contents/MacOS/starla-tray"; do
chmod +w "$bin"
for dep in $(otool -L "$bin" | grep /nix/store | awk '{print $1}'); do
base=$(basename "$dep")
install_name_tool -change "$dep" "/usr/lib/$base" "$bin"
done
done
# Include config example and launchd plist
cp ${./config.toml.example} staging/config.toml.example
cp ${./packaging/com.ananthb.starla.plist} staging/com.ananthb.starla.plist
# Install CLI script that symlinks the probe binary
cat > staging/Install\ CLI.command << 'SCRIPT'
#!/bin/bash
set -e
dst="/usr/local/bin/starla"
src="/Applications/Starla Tray.app/Contents/MacOS/starla"
if [ ! -f "$src" ]; then
echo "Error: Starla Tray.app not found in /Applications."
echo "Drag the app to Applications first, then run this again."
exit 1
fi
mkdir -p /usr/local/bin
ln -sf "$src" "$dst"
echo "Installed: $dst -> $src"
SCRIPT
chmod +x staging/Install\ CLI.command
# Applications symlink for drag-and-drop install
ln -s /Applications staging/Applications
hdiutil create -volname "Starla" -srcfolder staging \
-ov -format UDZO $out
'';
};
# CI checks
checks = {
inherit pre-commit-check;
# Build + clippy + tests (all features)
default = pkgs.rustPlatform.buildRustPackage {
pname = "starla-check";
version = "0.0.0";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
inherit nativeBuildInputs buildInputs;
buildPhase = ''
export HOME=$(mktemp -d)
cargo clippy --all-targets --all-features -- -D warnings
'';
doCheck = true;
checkPhase = ''
export HOME=$(mktemp -d)
cargo test --all-features --workspace
'';
installPhase = "touch $out";
};
# Build + clippy + tests (minimal features)
minimal = pkgs.rustPlatform.buildRustPackage {
pname = "starla-check-minimal";
version = "0.0.0";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
inherit nativeBuildInputs buildInputs;
buildPhase = ''
export HOME=$(mktemp -d)
cargo clippy --all-targets --no-default-features --features minimal -- -D warnings
'';
doCheck = true;
checkPhase = ''
export HOME=$(mktemp -d)
cargo test --no-default-features --features minimal --workspace
'';
installPhase = "touch $out";
};
# Full package builds
build = self.packages.${system}.default;
build-minimal = self.packages.${system}.minimal;
};
devShells.default = pkgs.mkShell {
name = "starla-dev";
buildInputs = [ rustToolchain ] ++ devPackages ++ buildInputs;
shellHook = ''
${pre-commit-check.shellHook}
cat << 'EOF'
================================================================
Starla - Nix Development Environment
================================================================
Quick Commands:
cargo build --all-features Build all workspace crates
cargo test --all-features Run all tests
cargo clippy --all-features Run clippy lints
cargo fmt --all Format code
Build Variants:
cargo build --release --all-features Release build
cargo build --no-default-features --features minimal Minimal build
Cross-Compilation Targets:
x86_64-unknown-linux-gnu
aarch64-unknown-linux-gnu
armv7-unknown-linux-gnueabihf
Nix Commands:
nix build Build the default package
nix build .#minimal Build minimal variant
nix flake check Run all CI checks
EOF
echo "Environment:"
echo " Rust: $(rustc --version | cut -d' ' -f2)"
echo " Cargo: $(cargo --version | cut -d' ' -f2)"
echo ""
'';
# Environment variables
RUST_BACKTRACE = "1";
RUST_LOG = "info";
CARGO_INCREMENTAL = "1";
RUST_TEST_THREADS = "4";
};
}
) // {
nixosModules.default = { config, lib, pkgs, ... }: {
imports = [ ./nix/module.nix ];
config = lib.mkIf config.services.starla.enable {
services.starla.package = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.default;
};
};
nixosModules.starla = self.nixosModules.default;
darwinModules.default = { config, lib, pkgs, ... }: {
imports = [ ./nix/darwin-module.nix ];
config = lib.mkIf config.services.starla.enable {
services.starla.package = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.default;
};
};
darwinModules.starla = self.darwinModules.default;
homeManagerModules.default = { config, lib, pkgs, ... }: {
imports = [ ./nix/home-module.nix ];
config = lib.mkIf config.services.starla.enable {
services.starla.package = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.default;
services.starla.trayPackage = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.starla-tray;
};
};
homeManagerModules.starla = self.homeManagerModules.default;
};
}