features/desktop/nightlight.nix previously set
`services.hyprsunset.enable = lib.mkDefault true` unconditionally and
baked the temperature (4000K when toggles.nightlight, 6500K otherwise)
into extraArgs at Nix-eval time. The toggle script bypassed systemd:
pkill on disable, `hyprctl dispatch exec hyprsunset --temperature 4000`
on enable — racing the systemd-managed instance and hardcoding 4000K
regardless of nomarchy.nightlightTemperature. The "Always enabled, we
control via IPC and state" comment was misleading: no IPC, the
temperature was rebuild-time, and the script forked a parallel
process.
Path (b) from the Later row:
- services.hyprsunset.enable now follows config.nomarchy.toggles.
nightlight — symmetric with services.hypridle.enable ← toggles.idle.
Disabled toggle = no process running.
- extraArgs always reads from config.nomarchy.nightlightTemperature.
Drops the 6500K neutralising fork; when off the unit just doesn't
start.
- nomarchy-toggle-nightlight flips the running systemd user unit via
`systemctl --user start/stop hyprsunset.service` for instant
feedback, reads nightlightTemperature from state.json for the
notify-send line, and writes .nightlight back to state.json so the
next rebuild realigns services.hyprsunset.enable.
`nix flake check --no-build` + `bash -n` clean.
32 lines
1.1 KiB
Bash
Executable File
32 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
# Toggles the nightlight (hyprsunset). Writes the new state to state.json
|
|
# (so the next home-manager rebuild realigns services.hyprsunset.enable
|
|
# via features/desktop/nightlight.nix) and flips the running systemd
|
|
# user unit for instant feedback. Reads nightlightTemperature from
|
|
# state.json so the value the user picked is honoured instead of a
|
|
# hardcoded constant.
|
|
|
|
STATE_DIR="$HOME/.config/nomarchy"
|
|
STATE_FILE="$STATE_DIR/state.json"
|
|
mkdir -p "$STATE_DIR"
|
|
|
|
[[ ! -f $STATE_FILE ]] && echo "{}" > "$STATE_FILE"
|
|
|
|
if [[ $NOMARCHY_TOGGLE_NIGHTLIGHT == "false" ]]; then
|
|
NEW_VALUE="true"
|
|
systemctl --user start hyprsunset.service 2>/dev/null || true
|
|
TEMP=$(jq -r '.nightlightTemperature // 4000' "$STATE_FILE")
|
|
notify-send -u low " Nightlight enabled (${TEMP}K)"
|
|
else
|
|
NEW_VALUE="false"
|
|
systemctl --user stop hyprsunset.service 2>/dev/null || true
|
|
notify-send -u low " Nightlight disabled"
|
|
fi
|
|
|
|
TMP_JSON=$(mktemp)
|
|
jq --argjson val "$NEW_VALUE" '.nightlight = $val' "$STATE_FILE" > "$TMP_JSON" && mv "$TMP_JSON" "$STATE_FILE"
|
|
|
|
echo "Nightlight state set to $NEW_VALUE."
|