All checks were successful
Check / eval-and-lint (push) Successful in 6m57s
Ten state-mutating sites across seven scripts wrote through a predictable, world-writable temp path (`/tmp/state.json`, `/tmp/system-state.json`) before the atomic `sudo mv`. Because the `>` redirect runs as the invoking user (sudo doesn't cover redirects), the shared fixed path is a symlink/ TOCTOU target and collides if two of these run concurrently. Switch each to a per-invocation `mktemp`; the atomic rename into place is unchanged. nomarchy-theme-set already used a temp var for its home-state write — this makes its system-state write consistent and cleans the temp up on failure. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
49 lines
1.4 KiB
Bash
Executable File
49 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
# Toggle dedicated vs integrated GPU mode via supergfxd (for hybrid gpu laptops, like Asus G14).
|
|
# Declarative enablement + Runtime mode switching for Nomarchy NixOS.
|
|
|
|
STATE_FILE="/etc/nixos/state.json"
|
|
|
|
# Check if supergfxd is enabled in config
|
|
if [[ $(sudo jq -r '.features.hybridGPU // false' "$STATE_FILE") != "true" ]]; then
|
|
if gum confirm "Hybrid GPU support is not enabled. Enable it now? (Requires sys-update)"; then
|
|
tmp=$(mktemp); sudo jq '.features.hybridGPU = true' "$STATE_FILE" > "$tmp" && sudo mv "$tmp" "$STATE_FILE"
|
|
echo "Hybrid GPU support enabled in configuration. Applying changes..."
|
|
sudo nomarchy-sys-update
|
|
echo "Please run this command again after the update."
|
|
exit 0
|
|
fi
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v supergfxctl &> /dev/null; then
|
|
echo "supergfxctl not found. Is the system updated?"
|
|
exit 1
|
|
fi
|
|
|
|
gpu_mode=$(supergfxctl -g)
|
|
echo "Current GPU mode: $gpu_mode"
|
|
|
|
case "$gpu_mode" in
|
|
"Integrated")
|
|
if gum confirm "Switch to Hybrid mode (enables dGPU) and reboot?"; then
|
|
supergfxctl -m Hybrid
|
|
echo "Switching to Hybrid mode..."
|
|
nomarchy-system-reboot
|
|
fi
|
|
;;
|
|
"Hybrid")
|
|
if gum confirm "Switch to Integrated mode (disables dGPU) and reboot?"; then
|
|
supergfxctl -m Integrated
|
|
echo "Switching to Integrated mode..."
|
|
nomarchy-system-reboot
|
|
fi
|
|
;;
|
|
*)
|
|
echo "Hybrid GPU in unknown mode: $gpu_mode. Try 'supergfxctl -m Hybrid' manually."
|
|
exit 1
|
|
;;
|
|
esac
|