From 2ef0a8b71038917e22240928c50a77f03883a934 Mon Sep 17 00:00:00 2001 From: Bernardo Magri Date: Fri, 10 Jul 2026 08:41:18 +0100 Subject: [PATCH] feat(hw): #58 nomarchy-detect-hw post-install re-probe CLI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Package the installer’s pure hardware-db probe as nomarchy-detect-hw: prints suggested hardwareProfile and system.nix snippets (or --raw protocol lines). Does not rewrite the flake. On PATH via the distro module; docs/HARDWARE.md §8 updated. Close #58. Verified: V1 (build + run on AMD laptop with fingerprint/NPU/IR cam). --- agent/BACKLOG.md | 12 +- agent/JOURNAL.md | 10 ++ docs/HARDWARE.md | 14 +- flake.nix | 2 + modules/nixos/default.nix | 1 + pkgs/nomarchy-detect-hw/default.nix | 43 ++++++ pkgs/nomarchy-detect-hw/nomarchy-detect-hw.sh | 134 ++++++++++++++++++ 7 files changed, 199 insertions(+), 17 deletions(-) create mode 100644 pkgs/nomarchy-detect-hw/default.nix create mode 100644 pkgs/nomarchy-detect-hw/nomarchy-detect-hw.sh diff --git a/agent/BACKLOG.md b/agent/BACKLOG.md index 9e5e6b3..26b2f84 100644 --- a/agent/BACKLOG.md +++ b/agent/BACKLOG.md @@ -77,15 +77,6 @@ last log lines + `nomarchy-doctor` instead of a raw Nix wall. Likely home: menu rebuild wrapper and/or control-center path. Cost: medium pkgs/menu; V1 + V2 smoke of the failure path (can force a bad eval). -### 58. `nomarchy-detect-hw` CLI (post-install re-probe) -HARDWARE.md §8. Installer already has pure `nomarchy_detect_hw` stdout -protocol (MODULE / NOMARCHY / DETAIL). Ship it as a package on PATH that -prints suggested `hardwareProfile = [ … ]` and `system.nix` snippets -without reinstalling — closes the template/migration gap and “I swapped -the Wi‑Fi card.” Does **not** rewrite the flake unless a later `--apply` -is explicitly designed. Cost: extract script + package + man/README -pointer; V0–V1. - ## LATER - **Wallpapers artifact split** (ROADMAP § Faster switches — decided, @@ -496,7 +487,8 @@ _(User password minimum length = 8 → #54.)_ #### Live ISO discoverability (one durable cue) -_(Live: one always-visible “Install Nomarchy” action → **#57**.)_ +_(Live: one always-visible “Install Nomarchy” action → **#57** ✓ 2026-07-10; + V2 pending: live ISO desktop entry smoke.)_ #### Generated config / post-install polish diff --git a/agent/JOURNAL.md b/agent/JOURNAL.md index 961ce69..d80cff9 100644 --- a/agent/JOURNAL.md +++ b/agent/JOURNAL.md @@ -17,6 +17,16 @@ Template: --- +## 2026-07-10 — #58 nomarchy-detect-hw CLI +- **Task:** NEXT #58 — post-install re-probe package (HARDWARE.md §8). +- **Did:** `pkgs/nomarchy-detect-hw` wrapping installer’s hardware-db; + human report + snippets + `--raw` protocol; overlay + systemPackages; + HARDWARE.md §8 updated. Closed #58. +- **Verified:** **V1** — package builds; ran on this AMD laptop: correct + MODULE/NOMARCHY lines (amd cpu/gpu, laptop, ssd, fingerprint, IR cam, + NPU) and printable system.nix snippets. +- **Next suggestion:** #55 fingerprint menu or #56 human rebuild errors. + ## 2026-07-10 — #57 live Install Nomarchy affordance - **Task:** NEXT #57 — durable live-ISO install surface (not only toast). - **Did:** `xdg.desktopEntries.nomarchy-install` (Terminal=true) on live diff --git a/docs/HARDWARE.md b/docs/HARDWARE.md index 63baab9..2530ad8 100644 --- a/docs/HARDWARE.md +++ b/docs/HARDWARE.md @@ -296,15 +296,15 @@ exist in a named nixos-hardware module. See [MIGRATION.md](MIGRATION.md): reuse `hardware-configuration.nix`, set `hardwareProfile`, uncomment `nomarchy.hardware` / power in `system.nix`. -There is **no** post-install re-probe helper yet (queued as -`nomarchy-detect-hw`). +Post-install re-probe (**shipped #58**): -### Re-detect sketch (future) +```sh +nomarchy-detect-hw # human report + suggested snippets +nomarchy-detect-hw --raw # MODULE / NOMARCHY / DETAIL protocol lines +``` -The installer’s `nomarchy_detect_hw` is already a pure probe (stdout -lines only). Exposing it as a package on PATH that prints suggested -`hardwareProfile` + `system.nix` snippets would close the template gap -without reinstalling. +Prints suggested `hardwareProfile` and `system.nix` lines; **does not** +rewrite the flake. Paste after review, then `sudo nixos-rebuild switch`. ## 9. Adding your model to the distro diff --git a/flake.nix b/flake.nix index fc7f225..000b456 100644 --- a/flake.nix +++ b/flake.nix @@ -86,6 +86,7 @@ nomarchy-doctor = final.callPackage ./pkgs/nomarchy-doctor { }; nomarchy-control-center = final.callPackage ./pkgs/nomarchy-control-center { }; nomarchy-battery-notify = final.callPackage ./pkgs/nomarchy-battery-notify { }; + nomarchy-detect-hw = final.callPackage ./pkgs/nomarchy-detect-hw { }; }; nixosModules.nomarchy = { @@ -120,6 +121,7 @@ nomarchy-doctor = pkgs.nomarchy-doctor; nomarchy-control-center = pkgs.nomarchy-control-center; nomarchy-battery-notify = pkgs.nomarchy-battery-notify; + nomarchy-detect-hw = pkgs.nomarchy-detect-hw; default = pkgs.nomarchy-theme-sync; }; diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix index f9f363c..857d289 100644 --- a/modules/nixos/default.nix +++ b/modules/nixos/default.nix @@ -322,6 +322,7 @@ in nomarchy-theme-sync # provided by overlays.default nomarchy-doctor # read-only health check (System › Doctor) nomarchy-control-center # TUI control center + nomarchy-detect-hw # post-install hardware re-probe (HARDWARE.md §8) # Friendly wrappers for the two rebuild paths (README §3). Run as # your user: `nix flake update` must NOT run as root (libgit2 diff --git a/pkgs/nomarchy-detect-hw/default.nix b/pkgs/nomarchy-detect-hw/default.nix new file mode 100644 index 0000000..458b811 --- /dev/null +++ b/pkgs/nomarchy-detect-hw/default.nix @@ -0,0 +1,43 @@ +# Post-install hardware re-probe (BACKLOG #58 / HARDWARE.md §8). +# Same pure nomarchy_detect_hw protocol as the installer; prints suggested +# hardwareProfile + system.nix snippets. Never rewrites the flake. +{ lib +, stdenvNoCC +, makeWrapper +, bash +, coreutils +, pciutils +, usbutils +, util-linux +}: + +stdenvNoCC.mkDerivation { + pname = "nomarchy-detect-hw"; + version = "0.1.0"; + + src = ./.; + + nativeBuildInputs = [ makeWrapper ]; + + installPhase = '' + runHook preInstall + + share=$out/share/nomarchy-detect-hw + install -Dm644 ${../nomarchy-install/hardware-db.sh} "$share/hardware-db.sh" + install -Dm755 nomarchy-detect-hw.sh $out/bin/nomarchy-detect-hw + patchShebangs $out/bin/nomarchy-detect-hw + + wrapProgram $out/bin/nomarchy-detect-hw \ + --prefix PATH : ${lib.makeBinPath [ bash coreutils pciutils usbutils util-linux ]} \ + --set NOMARCHY_DETECT_HW_SHARE "$share" + + runHook postInstall + ''; + + meta = { + description = "Probe hardware and print Nomarchy hardwareProfile / system.nix suggestions"; + license = lib.licenses.mit; + mainProgram = "nomarchy-detect-hw"; + platforms = lib.platforms.linux; + }; +} diff --git a/pkgs/nomarchy-detect-hw/nomarchy-detect-hw.sh b/pkgs/nomarchy-detect-hw/nomarchy-detect-hw.sh new file mode 100644 index 0000000..9486630 --- /dev/null +++ b/pkgs/nomarchy-detect-hw/nomarchy-detect-hw.sh @@ -0,0 +1,134 @@ +#!/usr/bin/env bash +# nomarchy-detect-hw — post-install re-probe (BACKLOG #58 / HARDWARE.md §8). +# +# Runs the same pure nomarchy_detect_hw protocol as the installer and +# prints suggested hardwareProfile + system.nix snippets. Never rewrites +# the flake (no --apply). +# +# Usage: +# nomarchy-detect-hw # human-readable report + snippets +# nomarchy-detect-hw --raw # MODULE / NOMARCHY / DETAIL lines only +set -euo pipefail + +SHARE="${NOMARCHY_DETECT_HW_SHARE:?nomarchy-detect-hw: not run via the packaged wrapper}" +# shellcheck source=/dev/null +source "$SHARE/hardware-db.sh" + +raw=false +case "${1:-}" in + --raw|-r) raw=true ;; + -h|--help) + cat <<'EOF' +Usage: nomarchy-detect-hw [--raw] + +Probe this machine the same way the live installer does and print +suggested flake hardwareProfile and system.nix hardware lines. + + --raw emit only MODULE / NOMARCHY / NOMARCHY-NPU / DETAIL lines + (installer protocol). Default is a human report + snippets. + +Does not modify any files. Paste the snippets into ~/.nomarchy after review. +EOF + exit 0 + ;; + "") ;; + *) + echo "nomarchy-detect-hw: unknown option: $1 (try --help)" >&2 + exit 2 + ;; +esac + +if $raw; then + nomarchy_detect_hw + exit 0 +fi + +profiles=() +nomarchy_lines=() +npu="" +details=() + +while IFS= read -r line; do + case "$line" in + MODULE\ *) profiles+=("${line#MODULE }") ;; + NOMARCHY\ *) nomarchy_lines+=("${line#NOMARCHY }") ;; + NOMARCHY-NPU\ *) npu="${line#NOMARCHY-NPU }" ;; + DETAIL\ *) details+=("${line#DETAIL }") ;; + esac +done < <(nomarchy_detect_hw) + +echo "nomarchy-detect-hw — suggestions for this machine" +echo "(read-only; paste into ~/.nomarchy after review)" +echo + +if ((${#details[@]})); then + echo "## Detected" + for d in "${details[@]}"; do + printf ' · %s\n' "$d" + done + echo +fi + +echo "## flake.nix — hardwareProfile" +if ((${#profiles[@]})); then + echo " hardwareProfile = [" + for p in "${profiles[@]}"; do + printf ' "%s"\n' "$p" + done + echo " ];" +else + echo " # (no modules detected — leave hardwareProfile unset or null)" +fi +echo + +echo "## system.nix — nomarchy.hardware / power (safe defaults active;" +echo "## heavier opt-ins stay commented, same as the installer)" +if ((${#profiles[@]})) && printf '%s\n' "${profiles[@]}" | grep -qx 'common-pc-laptop'; then + echo " nomarchy.system.power.laptop = true;" + echo " # nomarchy.system.power.batteryChargeLimit = 80;" +fi +for nm in "${nomarchy_lines[@]:-}"; do + case "$nm" in + hardware.intel.enable=true) + echo " nomarchy.hardware.intel.enable = true; # GuC/HuC (i915)" + echo " # nomarchy.hardware.intel.computeRuntime = true; # OpenCL/oneVPL (opt-in)" + ;; + hardware.intel.guc=false) + echo " nomarchy.hardware.intel.guc = false; # xe driver → GuC default-on" + ;; + hardware.amd.enable=true) + echo " nomarchy.hardware.amd.enable = true; # amd-pstate + VA-API" + echo " # nomarchy.hardware.amd.rocm.enable = true; # ROCm (multi-GB, opt-in)" + echo ' # nomarchy.hardware.amd.rocm.gfxOverride = ""; # e.g. "11.0.0" for unlisted iGPU' + ;; + hardware.fingerprint.enable=true) + echo " nomarchy.hardware.fingerprint.enable = true; # fprintd (enroll: fprintd-enroll)" + echo " # nomarchy.hardware.fingerprint.pam = true; # login + sudo (opt-in)" + ;; + hardware.camera.hideIrSensor=true) + echo " nomarchy.hardware.camera.hideIrSensor = true; # dual-sensor: hide IR node" + ;; + *) + echo " # (unmapped NOMARCHY line: $nm)" + ;; + esac +done +if [[ -n "$npu" ]]; then + echo " # nomarchy.hardware.npu.enable = true; # $npu NPU (experimental; userspace BYO)" + echo " # nomarchy.hardware.latestKernel = true; # if the NPU driver needs a newer kernel" +fi +if printf '%s\n' "${profiles[@]:-}" | grep -qx 'common-gpu-nvidia'; then + echo " # NVIDIA: common-gpu-nvidia is in hardwareProfile (flake.nix)." + echo " # Hybrid/PRIME, power, open-module — plain NixOS; see docs/HARDWARE.md §6" + echo " # hardware.nvidia.prime = { ... };" + echo " # hardware.nvidia.powerManagement.enable = true;" + echo " # hardware.nvidia.open = false; # or true on newer cards" +fi +if ((${#nomarchy_lines[@]} == 0)) && [[ -z "$npu" ]] \ + && ! printf '%s\n' "${profiles[@]:-}" | grep -qx 'common-gpu-nvidia' \ + && ! printf '%s\n' "${profiles[@]:-}" | grep -qx 'common-pc-laptop'; then + echo " # (no nomarchy.hardware lines suggested)" +fi +echo +echo "Apply with: sudo nixos-rebuild switch --flake \${NOMARCHY_PATH:-\$HOME/.nomarchy}#default" +echo "Docs: docs/HARDWARE.md §8"