diff --git a/README.md b/README.md index 500e7c7..e7e11e0 100644 --- a/README.md +++ b/README.md @@ -6,20 +6,16 @@ Dark charcoal shell, accent-blue arcs, auto-scaling ceilings, and a per-device b ## Run -```bash -nix run # apps.default → usage (Nix-packaged binary) -nix run .#usage -``` - -### 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 +nix run # apps.default → cargo build --release && run +nix run .#usage # same +nix run .#build # cargo build --release only ``` +`apps.usage` / `apps.default` use the **devshell toolchain** (`rustc`/`cargo` + egui libs) in the working tree — no pure sandbox, no remote builders. Incremental builds go into `./target/`. + Optional interactive shell: ```bash @@ -27,6 +23,13 @@ nix develop cargo run --release ``` +Packaged install (pure Nix derivation — may use remote builders): + +```bash +nix build .#usage +./result/bin/usage +``` + ## What you see | Gauge | Source | @@ -49,12 +52,12 @@ Below the gauges: cards listing individual disks and network interfaces with min | Output | Role | |--------|------| -| `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) | +| `apps.default` / `apps.usage` | Devshell: `cargo build --release` then run | +| `apps.build` | Devshell: `cargo build --release` only | +| `packages.default` / `packages.usage` | Pure packaged binary (`nix build`) | | `devShells.default` | rustc + cargo + egui runtime libs | -Flake input `vidya` is staged beside the crate so `path = "../vidya"` resolves under `nix build` / `nix run`. +Apps need a live checkout next to `../vidya`. The packaged `packages.usage` stages flake input `vidya` for pure builds. ## License diff --git a/flake.nix b/flake.nix index 5e6ae97..931adeb 100644 --- a/flake.nix +++ b/flake.nix @@ -33,6 +33,26 @@ libxi libxrandr ]; + + # Shared by apps.build / apps.usage: enter checkout + set link path. + cargoPreamble = libPath: '' + set -euo pipefail + export LD_LIBRARY_PATH="${libPath}''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" + + if [ ! -f Cargo.toml ] && [ -f "''${FLAKE_ROOT:-}/Cargo.toml" ]; then + cd "$FLAKE_ROOT" + fi + if [ ! -f Cargo.toml ]; then + echo "usage: no Cargo.toml here (cwd=$PWD)" >&2 + echo " cd into the usage checkout, then: nix run .#usage" >&2 + exit 1 + fi + if [ ! -d ../vidya ]; then + echo "usage: expected sibling ../vidya (Cargo path dep)" >&2 + echo " clone vidya next to usage, or: nix build .#usage" >&2 + exit 1 + fi + ''; in { packages = forAllSystems ( @@ -42,7 +62,8 @@ inherit (pkgs) lib; libs = eguiLibs pkgs; - # Cargo.toml expects path = "../vidya" (sibling of the package root). + # Packaged binary for `nix build` / install — pure, remote-builder capable. + # Day-to-day: prefer `nix run .#usage` (devshell cargo path below). srcTree = pkgs.runCommand "usage-src" { } '' mkdir -p $out/usage $out/vidya cp -a ${lib.cleanSource ./.}/. $out/usage/ @@ -89,53 +110,45 @@ inherit (pkgs) lib; libs = eguiLibs pkgs; libPath = lib.makeLibraryPath libs; - pkg = self.packages.${system}.usage; + cargoTools = with pkgs; [ + rustc + cargo + pkg-config + ]; - # Local cargo build with the same toolchain/libs as devShells.default. - # Avoids remote builders / pure sandbox — run from the checkout: - # nix run .#build + # Local cargo build (devshell tools; no pure sandbox / remote upload lock). build = pkgs.writeShellApplication { name = "usage-build"; - runtimeInputs = with pkgs; [ - rustc - cargo - pkg-config - ]; + runtimeInputs = cargoTools; 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 - + ${cargoPreamble libPath} 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" + ''; + }; + + # Build (if needed) and run via the same toolchain as `nix develop`. + usageApp = pkgs.writeShellApplication { + name = "usage"; + runtimeInputs = cargoTools; + text = '' + ${cargoPreamble libPath} + echo "→ cargo build --release" + cargo build --release + echo "→ target/release/usage $*" + exec ./target/release/usage "$@" ''; }; in { default = { type = "app"; - program = "${pkg}/bin/usage"; + program = "${usageApp}/bin/usage"; }; usage = { type = "app"; - program = "${pkg}/bin/usage"; + program = "${usageApp}/bin/usage"; }; build = { type = "app"; @@ -162,7 +175,7 @@ buildInputs = libs; LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath libs; shellHook = '' - echo "usage — cargo run | nix run .#build | nix run" + echo "usage — nix run | nix run .#build | nix develop" ''; }; }