From ec7d9c7907b75cd25442017998f0922371c3925e Mon Sep 17 00:00:00 2001 From: nandi Date: Fri, 31 Jul 2026 13:30:01 -0700 Subject: [PATCH] Add nix run .#build for local cargo build via devshell tools Runs cargo build --release with rustc/cargo and egui LD_LIBRARY_PATH from the flake, without pure sandbox or remote builders. --- README.md | 18 ++++++++++++++---- flake.nix | 48 +++++++++++++++++++++++++++++++++++++++++++++++- src/app.rs | 4 ++-- 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f62591b..500e7c7 100644 --- a/README.md +++ b/README.md @@ -7,15 +7,24 @@ Dark charcoal shell, accent-blue arcs, auto-scaling ceilings, and a per-device b ## Run ```bash -nix run # apps.default → usage +nix run # apps.default → usage (Nix-packaged binary) nix run .#usage ``` -Optional (from a checkout next to `../vidya`): +### Build with the devshell toolchain (no remote builders) + +From this checkout (with sibling `../vidya`): + +```bash +nix run .#build # cargo build --release (rustc/cargo from flake) +./target/release/usage +``` + +Optional interactive shell: ```bash nix develop -cargo run +cargo run --release ``` ## What you see @@ -40,7 +49,8 @@ Below the gauges: cards listing individual disks and network interfaces with min | Output | Role | |--------|------| -| `apps.default` / `apps.usage` | Launch the window | +| `apps.default` / `apps.usage` | Launch the window (packaged derivation) | +| `apps.build` | `cargo build --release` via devshell tools (local, no sandbox) | | `packages.default` / `packages.usage` | Wrapped binary (`LD_LIBRARY_PATH` for GL/Wayland) | | `devShells.default` | rustc + cargo + egui runtime libs | diff --git a/flake.nix b/flake.nix index 8fed791..5e6ae97 100644 --- a/flake.nix +++ b/flake.nix @@ -85,7 +85,48 @@ apps = forAllSystems ( system: let + pkgs = nixpkgs.legacyPackages.${system}; + inherit (pkgs) lib; + libs = eguiLibs pkgs; + libPath = lib.makeLibraryPath libs; pkg = self.packages.${system}.usage; + + # Local cargo build with the same toolchain/libs as devShells.default. + # Avoids remote builders / pure sandbox — run from the checkout: + # nix run .#build + build = pkgs.writeShellApplication { + name = "usage-build"; + runtimeInputs = with pkgs; [ + rustc + cargo + pkg-config + ]; + text = '' + set -euo pipefail + export LD_LIBRARY_PATH="${libPath}''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" + + # Prefer the flake checkout when invoked as `nix run .#build` from elsewhere. + if [ ! -f Cargo.toml ] && [ -f "''${FLAKE_ROOT:-}/Cargo.toml" ]; then + cd "$FLAKE_ROOT" + fi + if [ ! -f Cargo.toml ]; then + echo "usage-build: no Cargo.toml here (cwd=$PWD)" >&2 + echo " cd into the usage checkout, then: nix run .#build" >&2 + exit 1 + fi + if [ ! -d ../vidya ]; then + echo "usage-build: expected sibling ../vidya (Cargo path dep)" >&2 + echo " clone vidya next to usage, or use: nix build .#usage" >&2 + exit 1 + fi + + echo "→ cargo build --release $*" + cargo build --release "$@" + echo "✓ target/release/usage" + echo " run: LD_LIBRARY_PATH=${libPath}:\''${LD_LIBRARY_PATH:-} ./target/release/usage" + echo " or: nix develop -c cargo run --release" + ''; + }; in { default = { @@ -96,6 +137,10 @@ type = "app"; program = "${pkg}/bin/usage"; }; + build = { + type = "app"; + program = "${build}/bin/usage-build"; + }; } ); @@ -112,11 +157,12 @@ cargo rustfmt clippy + pkg-config ]; buildInputs = libs; LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath libs; shellHook = '' - echo "usage — cargo run | nix run" + echo "usage — cargo run | nix run .#build | nix run" ''; }; } diff --git a/src/app.rs b/src/app.rs index 7cef321..33558cd 100644 --- a/src/app.rs +++ b/src/app.rs @@ -105,9 +105,9 @@ impl eframe::App for UsageApp { .show(ui, |ui| { self.gauges_row(ui, &th); ui.add_space(th.spacing.lg); - self.breakdown(ui, &th); - ui.add_space(th.spacing.lg); self.proc_table(ui, &th); + ui.add_space(th.spacing.lg); + self.breakdown(ui, &th); }); }); } -- 2.51.2