#!/usr/bin/env bash

# Toggles wifi power saving declaratively.
# Usage: nomarchy-wifi-powersave <on|off>

STATE_FILE="/etc/nixos/state.json"

case "$1" in
on)  value="true" ;;
off) value="false" ;;
*) echo "Usage: nomarchy-wifi-powersave <on|off>"; exit 1 ;;
esac

sudo jq --argjson val "$value" '.wifi.powersave = $val' "$STATE_FILE" > /tmp/state.json && sudo mv /tmp/state.json "$STATE_FILE"

echo "Wifi powersave set to $1. Applying changes..."
sudo nomarchy-sys-update
