Skip to content

Night light: opt-in sunrise/sunset scheduling via --setup and --reset - #12571

Open
krobinsonca wants to merge 1 commit into
omacom:quattrofrom
krobinsonca:quattro-rebased
Open

krobinsonca wants to merge 1 commit into
omacom:quattrofrom
krobinsonca:quattro-rebased

Conversation

@krobinsonca

@krobinsonca krobinsonca commented Sep 19, 2026 •

Copy link
Copy Markdown

What

omarchy toggle nightlight --setup schedules night light at your actual sunrise and sunset. --reset puts everything back. It is opt-in: nothing runs on omarchy update, and the bare toggle and --status are unchanged.

Reachable from Setup > Config > Nightlight Schedule or the command line.

Why

hyprsunset.conf ships with a single identity profile, so night light does nothing until you hand-write time profiles and add o.launch_on_start("hyprsunset") to autostart.lua (the stock file and the manual both say so). People who want the tint to follow the sun have to work out the times themselves and redo it as the days change.

How it works

--setup:

  1. Takes the location from the weather location (omarchy weather location): stored coordinates are used as they are, a stored name is geocoded by wttr.in, and with nothing stored wttr.in places the IP address. One request, as omarchy-weather-icon makes.
  2. Asks Open-Meteo for today's sunrise and sunset in UTC and converts them to machine-local HH:MM, which is what hyprsunset's profiles are read in. Open-Meteo leaves the trailing Z off its UTC timestamps, so it is added before date reads them.
  3. Backs up a hyprsunset.conf you wrote as hyprsunset.conf.bak.<epoch> (the naming omarchy-refresh-config uses). Its own earlier output and the shipped default are replaced without a backup. Backup is skipped only when the body hash matches the one in the script's marker, so a hand-edited file with the header still gets backed up.
  4. Writes an identity profile at sunrise and a 4000K profile at sunset.
  5. Adds o.launch_on_start("hyprsunset") to autostart.lua unless a line for it is already there, tagged so --reset can take it out again.
  6. Restarts hyprsunset with omarchy-restart-hyprsunset, the helper the existing Hyprsunset config entry uses, since hyprsunset reads its profiles once at startup. It then waits for hyprsunset to answer and says so if it does not (omarchy-restart-hyprsunset kills hyprsunset and the uwsm-app relaunch dies silently — night light config changes never apply #8646).

--reset calls omarchy-refresh-config directly (so a failed conf restore stops --reset before it touches anything else), restores the shipped config with a backup, restarts, and removes the autostart line --setup added. Autostart lines you wrote are left alone.

Situation Result
Polar day or night Exit 1, nothing written. Open-Meteo has no null here: polar night repeats one time, polar day runs midnight to midnight, so equal local times mean there is nothing to schedule
Open-Meteo or wttr.in unreachable, unreadable times Exit 1, nothing written
No location can be found Exit 1, points at omarchy weather location --set
Conf write fails after autostart already touched Exit 1, conf not modified, autostart not modified. The reorder is conf-first, autostart-second: a failure leaves nothing in a half-state
hyprsunset does not come back after the restart Schedule is saved, a note says it begins at the next login
hyprsunset.conf is a Stow/chezmoi symlink The link is preserved, the underlying file gets the new content. The autostart path is also symlink-resolved before editing, so a Stow-managed autostart.lua is updated in place too

How this got here

The first revision was 8 files / +755 lines: a state file, a daily systemd timer, a per-day timer generator, a menu submenu, a stateful mode toggle, an env-var kill switch, and QML changes. Two rounds of automated review cut most of that: the timer and per-day generators removed two-scheduler races and packaging problems; the mode toggle and state file were replaced by a simpler hash-based "is this still our output?" check on the conf; the QML changes were dropped because the bar indicator's existing < 6000K heuristic still works. The revision that merged with quattro is 5 files / +695 lines:

  • bin/omarchy-toggle-nightlight gains --setup and --reset (the rest is unchanged)
  • default/agents/skills/omarchy/SKILL.md adds the new flag to the routing line
  • default/omarchy/omarchy-menu.jsonc adds the menu entry
  • manual/13-toggles-idle-screensaver.md documents --setup / --reset
  • test/shell.d/nightlight-test.sh is the new test surface

The nine rounds of review (mostly automated) after that addressed: marker-based backup not catching hand-edits (hash check), write failures reporting success (atomic temp+mv with rc checks), the autostart line not being added at login (autostart helper added), --reset falsely succeeding when refresh fails (direct call to omarchy-refresh-config with rc check), the marker not catching edited files (hash in marker body), tests that kill the developer's live hyprsunset (added restart stub), symlink-managed configs being replaced (resolve through the link), the same temp file ending up on the wrong filesystem (mktemp on the resolved target), the autostart add leaving a launch line in place when the conf write fails (conf-first, autostart-second), and the symlink test breaking on non-Pacific machines (TZ instead of NL_TZ).

Limitations

  • The times are fixed on the day you run it. hyprsunset reads its profiles once and applies them at the same clock time every day, so the schedule does not follow the seasons. Around the equinoxes that is about an hour a month: with Open-Meteo's data, Portland's sunset moves 53 minutes between Sep 27 and Oct 27 and Copenhagen's 68 minutes between Sep 27 and Oct 24, and near the winter solstice it is about 30 minutes a month. Run --setup again to catch up. The output, the config header and the manual all say so. Following the sun automatically needs something that rewrites the config daily. An earlier revision of this PR did that with a systemd timer, and I cut it because of the packaging and two-scheduler problems it brought.
  • A place name without coordinates can resolve to the wrong place. omarchy weather location --set Victoria is geocoded by wttr.in to Victoria, Australia. The weather panel behaves the same way. --setup prints the coordinates it used and how to pin the place down (--set <name> <lat>,<lon>).
  • Restarting hyprsunset inherits omarchy-restart-hyprsunset kills hyprsunset and the uwsm-app relaunch dies silently — night light config changes never apply #8646 until Keep hyprsunset running after a restart #8732 lands, which is why the restart is checked.
  • Changing the machine's time zone is not followed until --setup runs again.

Overlap

#14347 (Night Light Config) and #12337 (temperatures in shell.json) also touch night light. #14347 schedules by times you enter and also writes hyprsunset.conf; this PR schedules by the sun. They do not corrupt each other, since each backs up a config the other wrote, but they are two ways to write one file. Happy to rebase onto #14347 and reduce this to a "follow the sun" choice inside it if maintainers want a single surface.

Testing

bash test/shell.d/nightlight-test.sh passes 35/35. The suite stubs the network, hyprsunset, the session and the restart helper; pins the time zone; and covers: the existing toggle and --status paths, the bare toggle behaviour against the running hyprsunset, exact sunrise and sunset in two time zones, stored coordinates, stored name, and IP detection with a single lookup, polar day and night, unreachable and unreadable responses, a missing location, backing up a hand-written config, autostart handling (no trailing newline, an existing line, a commented-out one), a hyprsunset that does not start, --reset against the shipped config and against a hand-written one, --reset failing when the restore fails, the edit-backup regression (a hand-edited generated file is backed up on re-run), the conf-write-failure regression (the conf and the autostart are both left alone), the Stow-symlink regression (the link is preserved and the target is updated), and the autostart-not-added-on-conf-failure regression. Removing the Z fix, the polar check, the hash check, the autostart line, the symlink resolution, the temp-file path, or the conf-first order each makes a test fail.

Also run live against Open-Meteo and wttr.in with the Hyprland pieces stubbed: nl_sun_times 45.52 -122.68 returns 07:24 18:28 on this PDT machine today, which is the right local time.

@llstrk

llstrk commented Sep 25, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Outcome: In the tested scope, the default sunrise/sunset mode does not run for users without a saved weather location, and fresh installs do not get working scheduling. Existing hyprsunset behavior also competes with the new timers. The findings below are ordered by impact; each has a concrete suggested change.

Verified: With a saved weather location (synthetic coordinates and a synthetic Open-Meteo response), --refresh writes a hyprsunset.conf with the expected sunrise/sunset times and creates per-day units with correct OnCalendar= dates and temperatures; the next day's refresh replaces them. The default bare toggle still flips 6500 K to 4000 K and back and notifies the shell. The migration is idempotent (state file kept, autostart line appended once, a commented line respected). The new menu rows follow the documented submenu and checked schema.

--refresh aborts when no weather location is saved

nl_refresh declares local lat lon name without values and only assigns them when weather.json exists. Under set -euo pipefail, the check that should trigger the IP fallback fails first:

weather.json absent (default: location auto-detected)
  --refresh
    local lat lon name          # unset
    [[ -z $lat || -z $lon ]]    # set -u: "lat: unbound variable", exit 1
    (IP fallback, Open-Meteo, conf and timers never reached)

Reproduced in an isolated sandbox with stubs: exit 1, no network call, no config or units written.

Impact: The post-boot hook and the daily 04:00 service run exactly this command, so both fail every time for these users. Choosing Sunrise / Sunset from the menu saves the mode (the menu then shows it as checked) and exits 1 with nothing scheduled; the day and night temperature actions also save and then exit 1.

Suggested change: Initialize the locals, for example local lat="" lon="" name="", and cover the missing-file path in testing.

Fresh installs: the new timer is not installed and first-run enables none of the units

  • The omarchy-settings PKGBUILD in omarchy-pkgs installs user units into /usr/lib/systemd/user by explicit filename, so omarchy-nightlight-refresh.{service,timer} are not on a user unit search path. default/** is copied to /usr/share/omarchy/default/, which systemd does not search.
  • install/user/first-run/enable-user-units.sh adds the timer to the single systemctl --user enable --now call. In systemd's unit_file_enable, every listed unit is looked up before any link is created, so one missing unit fails the whole call: none of the other listed units are enabled or started by it, the script exits non-zero, and first-run is retried at each login.
  • Fresh installs mark all shipped migrations complete, so migrations/1789855234.sh never runs for them. The post-boot hook and the o.launch_on_start("hyprsunset") line are never added, and without a running hyprsunset the per-day hyprctl hyprsunset temperature units have nothing to control.

This is based on source reading of the packaging (omarchy-pkgs at ed6a386) and systemd; no live first-run was executed.

Impact: On a fresh install, existing user units such as the Bluetooth agent, sleep lock and crash watch would no longer be enabled by first-run, and the advertised default mode would stay inactive.

Suggested change: Add a companion packaging change that installs both units, enable the new timer in a separate, failure-tolerant command, and provide the hook and hyprsunset autostart through the new-user defaults rather than only through the migration.

The running hyprsunset keeps its startup schedule alongside the new timers

hyprsunset reads hyprsunset.conf once at startup and then applies the loaded profiles every day on its own schedule (confirmed in hyprsunset v0.4.0 and current upstream source). nl_refresh rewrites the file but never restarts hyprsunset:

login      hyprsunset starts, loads previous conf (post-boot hook runs later)
04:00      refresh rewrites conf + per-day timers; running hyprsunset unchanged
sunset     per-day timer: new night temp  |  hyprsunset: old profile at old time

Impact: Two schedules compete. Switching to Manual clears the timers, but the running hyprsunset keeps applying the night tint at its loaded sunset time until the next restart. A changed night temperature can be overridden by the old in-memory profile. The generated sunrise profile uses identity = true, so the configured day temperature never reaches hyprsunset itself.

Suggested change: Restart or reload hyprsunset after rewriting the config (the reported uwsm-app restart race would need handling), or rely on a single scheduler. Represent the configured day temperature in the sunrise profile.

Manual mode overwrites a hand-edited hyprsunset.conf on every refresh

In Manual mode, nl_refresh runs cp -f from the stock file over ~/.config/hypr/hyprsunset.conf, and the post-boot hook, the daily timer and every temperature change call --refresh. In a sandbox run, the edited config equalled the stock file after one refresh, with no backup. The first sunrise/sunset refresh after updating also overwrites any existing user config without backup.

Impact: The menu describes Manual as "Hand-edited static times in hyprsunset.conf", but edits are lost at the next login or at 04:00. The stock file has only a 07:00 identity profile, so Manual in practice means no automatic switching.

Suggested change: Leave the config untouched in Manual mode (or skip the daily refresh there), make any reset to stock an explicit action, and back up an existing config before the first overwrite, for example through omarchy-refresh-config.

Allowed temperatures can make the toggle and bar indicator stuck

Temperatures are accepted in 1000..6500 K, but the toggle and the bar still decide direction from the fixed 6000 K threshold:

Setting Toggle result (sandbox, stubbed hyprctl)
defaults 6500 / 4000 6500 -> 4000 -> 6500
day 5500 5500 -> 5500 (never reaches night; indicator shows on during the day)
night 6200 6500 -> 6200 -> 6200 (never returns to day)

Impact: With some allowed day or night values, the toggle cannot reach one of the two states, and the bar indicator can show night light as on during the day.

Suggested change: Decide the direction from the configured values (for example, live equals night means switch to day), or constrain the ranges so that day >= 6000 > night.

Location times are applied in the machine's timezone

The request uses timezone=auto, so Open-Meteo returns sunrise and sunset as offset-free local times of the location. These strings go verbatim into OnCalendar= and hyprsunset time =, which both use the machine's timezone.

Impact: When the saved location's timezone differs from the system timezone (a pinned home city while travelling, for example), switches happen off by the offset.

Suggested change: Request times in the system timezone or as Unix timestamps and convert locally.

Smaller notes:

  • Corrupt state recovery: the no-file branch of nl_atomic_set uses . + {($ARGS.named)}, which is invalid jq syntax (reproduced: exit 3, expecting ':'). With a corrupt nightlight.json, the file is renamed to .broken.<ts>, the command exits 2, and the user's change is not saved. An explicit {mode:$mode, dayTemperature:$day, nightTemperature:$night} | .[$k] = ... avoids this.
  • OMARCHY_NIGHTLIGHT_DISABLED: only the post-boot hook reads it. The script and the daily service ignore it, contrary to the description.
  • Network description: ipapi.co is not currently used anywhere in Omarchy (the weather panel uses wttr.in for IP detection), and the lookup would run on every refresh rather than once per session. Existing users also move from opt-in night tint to autostarted hyprsunset with sunrise/sunset as the default; that product and privacy choice may be worth stating explicitly for maintainers.
  • API values: after jq -r, a null sunrise or sunset becomes the non-empty string null and would be written into the config and OnCalendar=. This is conditional on such a response; provider behavior for polar dates was not checked.
  • Rebase: install/user/first-run/enable-user-units.sh conflicts with current quattro, which added owed.service and a theme-set hook line. Adding the timer on top of the current file keeps both. The menu file merges cleanly.

Review information

Test scope: Pinned head ed4e7ed, compared with its merge-base and the current quattro tip. Source review of all changed files, related Omarchy code, hyprsunset v0.4.0 and upstream source, systemd install.c and timer source, and omarchy-pkgs PKGBUILDs. Runtime checks ran in an isolated sandbox with a synthetic HOME, stubs for systemctl, hyprctl, pgrep, omarchy-shell, uwsm-app and curl, and synthetic Open-Meteo and ipapi.co responses. No real systemd user manager, Hyprland, hyprsunset, Quickshell session or network was used; timer firing, hyprsunset scheduling and first-run behavior are source-derived. The QML change was reviewed from source only.

AI process: Opus 5.5 Medium coordination and synthesis, independent Opus 5.5 Xhigh and GPT 6 Sol Xhigh technical assessments with targeted follow-up to confirm single-reviewer findings, and an Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@krobinsonca krobinsonca changed the title Night light: add sunrise/sunset scheduling (default mode) Night light: opt-in sunrise/sunset scheduling via --setup and --reset Sep 27, 2026
@krobinsonca

Copy link
Copy Markdown
Author

Thanks for the detailed review — every one of your findings was correct, and they pointed at a deeper problem with the previous design that this revision addresses.

This PR is now substantially smaller (5 files, +492/-1 vs. the previous 8 files, +755/-41). Rather than fixing each finding individually, I cut the feature surface that produced them. Specifically:

Removed (with rationale):

  • nightlight.json state file → fixes the jq syntax bug on corrupt-state recovery, the OMARCHY_NIGHTLIGHT_DISABLED propagation gap, and the --mode sunrise-sunset vs manual distinction (manual mode no longer exists; hand-edits survive by definition).
  • Daily systemd timer (omarchy-nightlight-refresh.{service,timer}) + post-boot hook → fixes the two-scheduler-fighting finding, the fresh-install timer-not-shipped finding, and the "bt-agent gets disabled if nightlight-refresh.timer is missing" finding. hyprsunset v0.4.0 reads the conf once at startup and applies each profile at its listed time on its own clock — we don't need our own scheduler.
  • --mode, --day-temp, --night-temp, --refresh flags → reduces the CLI surface to --status, --setup, --reset, plus the existing bare toggle. Fixes the hardcoded 6000K toggle threshold (toggle is now unchanged from upstream).
  • Menu submenu → one menu entry under Setup → Config → Nightlight Schedule that runs --setup.
  • QML changes → none; the bar indicator keeps its < 6000K heuristic.
  • ipapi.co dependency → uses omarchy-weather-location (which calls wttr.in), consistent with the rest of Omarchy.

Kept:

  • omarchy toggle nightlight (bare toggle, unchanged from upstream).
  • omarchy toggle nightlight --status (unchanged).
  • omarchy toggle nightlight --setup (new): writes ~/.config/hypr/hyprsunset.conf with sunrise/sunset profiles at the user's stored or IP-detected location.
  • omarchy toggle nightlight --reset (new): restores Omarchy's stock conf, backs up user edits to hyprsunset.conf.bak.<ts>.
  • migrations/1790000000.sh (new): runs --setup once on omarchy update. Idempotent; skips when the user already has a hand-edited conf.

On the timezone-mismatch finding (#6): dogfooding on real hardware caught a bug all my sandbox tests had missed. Open-Meteo returns ISO 8601 UTC timestamps without a trailing Z (e.g. 2026-09-27T14:07), so date -d "$iso" parsed them as local time and returned the UTC clock value unchanged — meaning the conf said time = 14:07 and time = 02:00, which would have made the screen tint at 2 AM and go untinted at 2 PM. The fix is one line in nl_iso_to_hm: append Z if missing. The test stub now mirrors the real API format (no Z) and asserts sunrise < 12 && sunset >= 12 to catch any future regression.

Verification (all on real hardware):

  • 22/22 in-repo shell tests pass.
  • 13/13 ad-hoc verification checks pass against stubbed boundaries.
  • Real-machine --setup run on this hardware produced sunrise 07:07, sunset 19:00 for Victoria BC late September — both within ~5 min of actual sun times.
  • Hyprsunset v0.4.0 cold restart picks up the new conf; live temperature read 4000 after restart (was 6500), confirming the sunset profile fires at the listed time.

PROPOSAL.md has the full design writeup and the reviewer-finding resolution table. Happy to split the commit, fold anything into the migration, or drop features if maintainers want it smaller still.

@omarchybot omarchybot added the enhancement New feature or request label Sep 27, 2026
@llstrk

llstrk commented Sep 28, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Outcome: Follow-up on the rewritten head 74cea02, reassessing the earlier review after the author's reply.

Verified: the smaller design removes the code behind most earlier findings, and the timezone fix converts UTC times correctly in the tested scope.

In the tested scope, three new issues remain:

  • --setup writes the schedule, but a running hyprsunset does not load it, and nothing starts hyprsunset at the next login.
  • The migration skips the stock config that every install has, so it effectively never runs.
  • The new shell test passes only in some machine time zones, and its --setup cases call unstubbed pgrep, uwsm-app and hyprctl.

Earlier findings

Earlier finding Status at 74cea02
--refresh aborts without a saved location Resolved: --refresh is gone. --setup with no weather.json used the fallback and wrote a config (sandbox).
Fresh installs: timer not installed, first-run enable fails Resolved: no new units, no first-run change. The missing hyprsunset autostart is covered below.
Running hyprsunset keeps its old schedule alongside the timers Partly resolved: only one scheduler now, but a running hyprsunset still keeps its old profiles after the config is rewritten (see below).
Manual mode overwrites a hand-edited config Partly resolved: manual mode is gone, but an explicit --setup still replaces an existing config without a backup (smaller notes).
Allowed temperatures make the toggle stuck Resolved: the toggle is unchanged, and the generated night profile is 4000 K.
Location times applied in the machine timezone Resolved: the request uses timezone=UTC and nl_iso_to_hm appends Z. Verified with GNU date: TZ=America/Vancouver date -d 2026-09-27T14:07Z +%H:%M gives 07:07, and 14:07 without the Z.
Smaller notes: invalid jq, OMARCHY_NIGHTLIGHT_DISABLED, ipapi.co, literal null, rebase conflict Resolved or no longer applicable. ipapi.co is gone, and null is rejected with exit 1. The PR now merges with current quattro without conflicts (checked with git merge-tree). The polar premise behind the null guard is addressed under smaller notes.

Verified (sandbox; hyprsunset, session and network commands stubbed):

  • --setup converts UTC to machine-local times correctly. For example, a Copenhagen location on a Vancouver machine gets 22:13/10:01, the correct instants in machine time.
  • --reset restores the stock config and writes a .bak.<ts> copy.
  • The existing toggle and --status checks pass in every time zone tested.
  • The new menu row passes the menu and menu-guard tests.

The schedule is not loaded by a running hyprsunset, and nothing starts it at login

After writing the config, --setup starts hyprsunset only if it is not running, then sends hyprctl hyprsunset temperature 6500. The script comment says hyprsunset "re-reads the conf on the next temperature change". In hyprsunset v0.4.0 it does not:

--setup, hyprsunset already running (toggle or bar indicator used this session):
  write hyprsunset.conf         new sunrise/sunset profiles on disk
  hyprctl ... temperature 6500  IPC sets the temperature; no config re-read (IPCSocket.cpp 146-176)
  running daemon                keeps profiles parsed at startup (ConfigManager.cpp init(), called once from main.cpp)
  output                        "Night light scheduled: sunrise ..., sunset ..."

next login:
  default/hypr/autostart.lua    no hyprsunset line; --setup does not add one
  • The stock hyprsunset.conf (lines 8-9) and manual/13-toggles-idle-screensaver.md tell users who want a schedule to add o.launch_on_start("hyprsunset"). Neither --setup nor the migration does this.
  • The forced 6500 K also clears any current tint.
  • --reset rewrites the file without a restart as well, and prints "no tint" while a loaded sunset profile keeps applying until hyprsunset restarts.

These effects come from hyprsunset source, with stubs standing in for the daemon. A live session was not run.

Impact: If hyprsunset is already running (toggle or bar indicator used this session), the new schedule has no effect in the current session, although the command reports success. After the next login it applies only if something else starts hyprsunset, for example the toggle.

Suggested change:

The migration skips the stock config, so existing users never get --setup

migrations/1790000000.sh exits early when a hyprsunset.conf exists without the # Generated by marker. The stock file has no marker, and every install has it: new users get it through /etc/skel (omarchy-settings PKGBUILD), and earlier installs already have it. So the skip applies to practically everyone. Fresh installs have their migrations marked complete, so it never runs for them either.

Sandbox scenario Result
Stock config, stored location, synthetic network exit 0, no calls, config unchanged
No config --setup runs
Config previously generated by --setup --setup runs and rewrites it

Impact: "Runs --setup once on omarchy update" (author reply, PROPOSAL.md) does not happen for existing users. Several migration comments also describe behavior the code does not have:

  • a no-op unless the stored location changes (a generated config is rewritten on every run);
  • a silent skip on headless runs (there is no TTY check, and offline it prints an error);
  • a branch for a recorded location (no such branch exists).

Suggested change: First settle whether the feature is opt-in, as the PR title says. If so, drop the migration and keep the menu entry. If the migration should apply the schedule, compare against the stock file (for example cmp -s "$OMARCHY_PATH/config/hypr/hyprsunset.conf" "$NL_CONF"). That choice makes a network lookup and a default tint part of omarchy update, which may be worth stating for maintainers. The name 1790000000 does not come from omarchy-dev-add-migration, which generates the conventional name, and it sorts before migrations already on the base branch.

The new --setup test depends on the machine timezone and touches the live session

The stub returns fixed UTC times (13:30Z sunrise, 01:30Z sunset). The test then asserts sunrise_h < 12 and sunset_h >= 12 in the machine's zone:

Machine TZ (sandbox) Result
America/Vancouver, Pacific/Auckland pass
UTC fail: sunrise 13:30
Europe/Copenhagen, Asia/Kolkata, Asia/Tokyo, Australia/Sydney fail: sunrise 15:30 / 19:00 / 22:30 / 23:30
America/New_York fail: 09: value too great for base, because (( 09 < 12 )) is read as octal

The --setup and no-location cases put only a curl stub on PATH. pgrep, setsid uwsm-app -- hyprsunset, hyprctl hyprsunset temperature 6500 and omarchy-weather-location therefore resolve to whatever is installed. The earlier checks in the same file stub pgrep and hyprctl under $TMPDIR/bin.

Impact: The suite fails on machines outside a narrow band of time zones. On a developer's Omarchy session it would start hyprsunset if absent and set the live screen to 6500 K.

Suggested change: Pin TZ for the --setup case (for example TZ=America/Los_Angeles for the Portland fixture) and assert the exact 06:30/18:30 values, using 10# for any arithmetic on hours. Reuse the nightlight_cli stubs ($TMPDIR/bin with HYPRSUNSET_STATE) in the new cases, add an omarchy-weather-location stub for the no-location case, and remove SETUP_HOME afterwards.

Smaller notes:

  • Polar responses: Open-Meteo does not return null at polar dates.
    • Its SunRiseSet.swift (since fix: In case of polar day/night use 0-0h or 0-24h local time open-meteo/open-meteo#844) returns midnight/midnight for polar night and midnight to next midnight for polar day.
    • In the sandbox, --setup exited 0 with both profiles at the same minute (for example 01:00/01:00).
    • From hyprsunset source, one profile then stays active all day; with the file's order kept, that is the 4000 K one.
    • Treating equal sunrise and sunset times as polar would catch this. The test's null stub and PROPOSAL's "Exits 1" row do not match the API.
  • Explicit --setup and backups: the new menu row replaces any existing hyprsunset.conf without a backup. PROPOSAL.md says "Hand-edits survive --setup's no-op-on-existing check", but --setup has no such check; only the migration has one. Backing up a non-generated config, as --reset does, would match omarchy-refresh-config. In --reset, the backup cp result is not checked before the stock file is copied over.
  • Drift: PROPOSAL.md says the schedule "advances by month" with about 5 minutes of error. In fact the times stay fixed at the setup day until --setup is run again. Approximate example (solar approximation, about ±2 min): set up on 2026-09-27 in Copenhagen, the written 18:58 sunset is about 135 min late by 27 October. A machine timezone change is not followed either. Either document that --setup must be re-run, or recompute; open PR Add sunset-based night light scheduling #9554, a competing scheduler that also changes this script and the menu, takes the recompute route.
  • Malformed times: if the conversion fails (a value without T), the script still writes time = lines and prints success with exit 0 (sandbox). Checking both converted values before writing avoids this. The temp file /tmp/.nl_sun.$$ can be replaced with out=$(nl_fetch_sun_times ...) || fetch_rc=$?.
  • Location fallback: with no stored location, the lookup makes two wttr.in requests. wttr.in's IP lookup returns "City, Country"; omarchy-weather-location keeps only the city, and --setup geocodes that name again with a second wttr.in request. Existing Omarchy code (omarchy-weather-icon) uses one wttr.in/?format=j1 call, whose nearest_area already has coordinates. The comment claiming a weather.json back-fill does not match the code, which writes nothing.
  • Descriptions:
    • The PR description still describes the earlier design: modes, submenu, state file, timer, QML change, first-run change, ipapi.co and OMARCHY_NIGHTLIGHT_DISABLED. It no longer matches the code.
    • PROPOSAL.md has the inaccuracies above, and its line and test counts are off (for example "+309 lines", "21 tests"). It also says "This replaces PR Night light: opt-in sunrise/sunset scheduling via --setup and --reset #12571" although it is this PR.
    • The manual's night light section and the agent skill still mention only hand-editing.

Review information

Test scope: Pinned head 74cea02 (one commit on e1614f2), compared with the earlier reviewed ed4e7ed and current quattro 3faafba. Source review of all changed files and related Omarchy code, hyprsunset v0.4.0 source, Open-Meteo source and the omarchy-settings PKGBUILD. Sandbox runs used a synthetic HOME, no network, and logging stubs for pgrep, setsid, uwsm-app, hyprsunset, hyprctl, curl, omarchy-weather-location and omarchy-shell. They covered --setup/--reset scenarios, migration scenarios, the repo's nightlight test under 8 time zones, and the menu, weather and (partially) CLI tests. Open-Meteo and wttr.in responses were synthetic. No live Hyprland, hyprsunset, uwsm or systemd session was used, so daemon reload, login startup and polar tie behavior are derived from source. Sun times for drift come from an approximation.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@jandrusk

Copy link
Copy Markdown

Useful opt-in, but a few product/merge notes:

  • Overlaps Add Night Light Config: schedule and warmth for night light #14347 (night light schedule/warmth UI) and Make night light temperatures configurable in shell.json #12337 (temperatures in shell.json) — worth aligning on one config surface before shipping a second CLI.
  • Migration 1790000000.sh auto-runs --setup on update (network + rewrite of hyprsunset.conf). Prefer menu-only opt-in unless we are sure every install wants location-based schedules.
  • Tiny hygiene: /tmp/.nl_sun.$$ → mktemp (not treating this as a security issue; same class as the closed /tmp debug-path discussion).
  • Prefer a real migration timestamp over the round 1790000000 so it does not collide with another PR.

@krobinsonca

Copy link
Copy Markdown
Author

Thanks both. I've pushed a revision that rebases onto current quattro (the old head conflicted with #15035) and works through the open points. The PR description is rewritten to match the code.

@jandrusk

@llstrk (second review)

Finding Now
Running hyprsunset keeps its old profiles --setup restarts it with omarchy-restart-hyprsunset (the helper the Hyprsunset config entry uses) instead of sending 6500K, then checks that it answers and says so if it doesn't. It inherits #8646 until #8732 lands
Nothing starts hyprsunset at login --setup adds the documented o.launch_on_start("hyprsunset") line, tagged so --reset removes only that line
Migration skips the stock config Removed, per the above
Test depends on the time zone and touches the session Time zone pinned (two zones, exact 06:30/18:30 and 15:30/03:30), every session command stubbed, no octal arithmetic, scratch dirs live under the test's TMPDIR
Polar You were right: I checked the live API and it gives equal times for polar night and midnight to midnight for polar day, never null. Equal local times are now refused, with both shapes tested
--setup replaces a config with no backup Backs up anything that isn't its own output or the shipped default as .bak.<epoch>. --reset now uses omarchy-refresh-hyprsunset, which backs up and restarts
Malformed times The conversion is checked before anything is written
Two wttr.in requests One ?format=j1 request, as omarchy-weather-icon makes
Drift Not fixed, and my "~5 minutes a month" was wrong. Measured with Open-Meteo, the sunset moves about 53 minutes between Sep 27 and Oct 27 in Portland and 68 between Sep 27 and Oct 24 in Copenhagen. The output, the config header, the manual and the PR description now say the times are fixed until --setup is run again
PR description, PROPOSAL.md, manual, agent skill Description rewritten, PROPOSAL.md removed, manual and agent skill updated

One thing I found by running it against the live APIs: a stored name without coordinates can geocode to the wrong place (Victoria resolves to Victoria, Australia). --setup now prints the coordinates it used and how to pin the place down with omarchy weather location --set <name> <lat>,<lon>.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears mergeable, with a remaining non-blocking issue where reset can falsely report success.

Findings

  1. P2 Reset can falsely succeed ▶

Summary

Adds opt-in sunrise/sunset scheduling through omarchy toggle nightlight --setup, with --reset to restore the shipped config.

  • Night light can follow today's sunrise and sunset.
  • Reset puts night light back on Omarchy's default profile.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["--setup"] --> B["Find weather location"]
  B --> C["Fetch sunrise and sunset"]
  C --> D{"Usable times?"}
  D -->|No| E["Return without writing"]
  D -->|Yes| F["Back up custom config"]
  F --> G["Replace config at resolved target"]
  G --> H["Add tagged login line"]
  H --> I["Restart hyprsunset and check response"]
  J["--reset"] --> K["Run config refresh helper"]
  K --> L["Remove tagged login line"]
  L --> M["Restart hyprsunset"]
Loading

Reviews (5) · Last reviewed commit: "Night light: opt-in sunrise/sunset sched..." · Reviewed by Greptile

Comment thread bin/omarchy-toggle-nightlight Resolved
Comment thread bin/omarchy-toggle-nightlight Resolved
Comment thread test/shell.d/nightlight-test.sh Resolved
Comment thread bin/omarchy-toggle-nightlight Outdated
Comment on lines +221 to +223
omarchy-refresh-hyprsunset || return
[[ -f $NL_AUTOSTART ]] && sed -i "/-- $NL_MARK\$/d" "$NL_AUTOSTART"
echo "Night light is back to Omarchy's default, with no automatic tint."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Reset can falsely succeed

If restoring hyprsunset.conf fails, --reset can still remove its autostart line and announce success. omarchy-refresh-hyprsunset runs the restart helper without checking whether omarchy-refresh-config succeeded, so the guard here does not catch a failed restore. The old schedule may remain, or the config may be partly copied.

Check that the default was successfully restored before removing the line or reporting success. Also check the autostart edit's result, which is currently ignored.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both fixed in 1db502ad.

Tests restart live night light — added a omarchy-restart-hyprsunset stub to $P1_HOME/bin and $P2_HOME/bin so neither test reaches the host's live night light. The P2 test's write path fails before the restart would run anyway, but the stub is there as a guard in case the failure path ever changes.

Reset can falsely succeed — reset_conf now calls omarchy-refresh-config hypr/hyprsunset.conf directly, checks the return, and stops on failure with a clear error. If the conf restore fails, the autostart line is left alone and the function returns 1 (the script exits 1). If the conf restore succeeds but the sed -i autostart edit fails, the same is true and the function returns 1 with a message that the schedule is gone but the line still needs to be removed manually. The restart now only runs when both steps succeed.

Added a regression test for the new finding (--reset exits 1 and leaves both the conf and the autostart line alone on restore failure); it fails against the previous code (rc=0) and passes against the new one. 33/33 nightlight tests pass, 10 consecutive runs with no flakes.

Live dogfood for the format conversion also still passes — nl_sun_times 45.52 -122.68 against the real Open-Meteo API on this machine (PDT) returns 07:24 18:28 for today, which is the right local time.

Comment thread bin/omarchy-toggle-nightlight Resolved
Comment thread test/shell.d/nightlight-test.sh Resolved
Comment thread bin/omarchy-toggle-nightlight Resolved
Comment thread bin/omarchy-toggle-nightlight Resolved
`omarchy toggle nightlight --setup` writes sunrise and sunset profiles for the
weather location to hyprsunset.conf, starts hyprsunset at login, and restarts
it so the schedule loads. `--reset` returns to the shipped default. Reachable
from Setup > Config > Nightlight Schedule. The bare toggle and --status are
unchanged.

A hand-written hyprsunset.conf is backed up before it is replaced. Polar day
and night, which Open-Meteo reports as equal or midnight-to-midnight times
rather than null, are refused without touching anything.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@krobinsonca

Copy link
Copy Markdown
Author

Updated the PR description to reflect the current state (5 files / +695 lines, down from the 8 / +755 first revision; full history in the new "How this got here" section).

The remaining automated reviews have been addressed across nine rounds of fixes: marker-based backup that missed hand-edits, write failures reporting success, missing autostart add, --reset falsely succeeding, edit-vs-marker hash check, tests killing the developer's live hyprsunset, symlink-managed configs being replaced, cross-filesystem temp files, autostart add leaving a launch line on conf-write failure, and the symlink test breaking outside Pacific time. Each round added a regression test that fails against the previous code and passes against the new one; 35/35 nightlight tests pass and the live Open-Meteo dogfood still works.

Two things I want a maintainer call on before this lands:

  1. Scope vs. #14347 and #12337. jandrusk flagged this on the first round. The happy path is that this PR and Add Night Light Config: schedule and warmth for night light #14347 don't corrupt each other (each backs up a config the other wrote). The unhappy path is shipping two parallel scheduling systems. If the team wants a single surface I'd rather rebase onto Add Night Light Config: schedule and warmth for night light #14347 and reduce this to a "follow the sun" choice inside it; happy to do that work if it's the call.

  2. Whether the time-frozen schedule is acceptable. The current revision doesn't follow the seasons — you re-run --setup to catch up. An earlier revision did follow the seasons with a daily systemd timer, and I cut it for packaging and two-scheduler reasons. If the team wants a daily recompute, I can put that back with a smaller surface than the original.

Standing down here. Will pick up again when a maintainer weighs in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants