feat(hw): #58 nomarchy-detect-hw post-install re-probe CLI
All checks were successful
Check / eval (push) Successful in 2m52s
All checks were successful
Check / eval (push) Successful in 2m52s
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).
This commit is contained in:
43
pkgs/nomarchy-detect-hw/default.nix
Normal file
43
pkgs/nomarchy-detect-hw/default.nix
Normal file
@@ -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;
|
||||
};
|
||||
}
|
||||
134
pkgs/nomarchy-detect-hw/nomarchy-detect-hw.sh
Normal file
134
pkgs/nomarchy-detect-hw/nomarchy-detect-hw.sh
Normal file
@@ -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"
|
||||
Reference in New Issue
Block a user