# Night light — a scheduled blue-light filter via hyprsunset (Hyprland's own # gamma/temperature tool). Warm at night, identity (no shift) by day; # hyprsunset's time-based `profile` entries handle the schedule and pick the # right state on session start. Opt-in via nomarchy.nightlight.enable. # # The hyprsunset HM service module is provided by home-manager; this only # configures it. Override anything with plain services.hyprsunset.* options. # # nomarchy-nightlight is the menu/Waybar toggle: it starts/stops the hyprsunset # *service* (so `systemctl --user is-active` is the single source of truth and # the screen restores to true colours when stopped), letting you force the # filter off for colour-sensitive work and back on without touching the config. { config, lib, pkgs, ... }: let cfg = config.nomarchy.nightlight; # Toggle/status helper, on PATH so the menu and both the generated and # whole-swap Waybars can drive it by name. Self-gates: when the unit doesn't # exist (night-light not enabled) `status` prints nothing, so the Waybar # module hides itself — same pattern as the power-profile indicator. nomarchy-nightlight = pkgs.writeShellScriptBin "nomarchy-nightlight" '' unit=hyprsunset.service if ! systemctl --user cat "$unit" >/dev/null 2>&1; then [ "''${1:-}" = status ] && exit 0 notify-send "Night light" "Not enabled — set nomarchy.nightlight.enable." exit 0 fi case "''${1:-toggle}" in status) if systemctl --user is-active --quiet "$unit"; then printf '{"text":"󰖔","tooltip":"Night light on — warm on schedule (click to disable)","class":"on"}\n' else printf '{"text":"󰖙","tooltip":"Night light off (click to enable)","class":"off"}\n' fi ;; on) systemctl --user start "$unit" ;; off) systemctl --user stop "$unit" ;; toggle) if systemctl --user is-active --quiet "$unit"; then systemctl --user stop "$unit" notify-send "Night light off" "Screen back to true colours." else systemctl --user start "$unit" notify-send "Night light on" "Warm filter follows your schedule." fi ;; *) echo "usage: nomarchy-nightlight [toggle|status|on|off]" >&2; exit 64 ;; esac ''; in { config = { services.hyprsunset = lib.mkIf cfg.enable { enable = true; settings.profile = [ # Daytime: identity = no colour change. { time = cfg.sunrise; identity = true; } # Night: shift to the warm temperature. { time = cfg.sunset; temperature = cfg.temperature; } ]; }; # Always on PATH (it self-gates at runtime), so a static whole-swap Waybar # can exec it even when night-light is off without the call failing. home.packages = [ nomarchy-nightlight ]; }; }