Repository navigation
Night light: opt-in sunrise/sunset scheduling via --setup and --reset - #12571
krobinsonca wants to merge 1 commit into
Conversation
Automated AI 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),
|
| 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_setuses. + {($ARGS.named)}, which is invalid jq syntax (reproduced: exit 3,expecting ':'). With a corruptnightlight.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, anullsunrise or sunset becomes the non-empty stringnulland would be written into the config andOnCalendar=. This is conditional on such a response; provider behavior for polar dates was not checked. - Rebase:
install/user/first-run/enable-user-units.shconflicts with currentquattro, which addedowed.serviceand 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.
ed4e7ed to
74cea02
Compare
|
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):
Kept:
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 Verification (all on real hardware):
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. |
Automated AI review
Outcome: Follow-up on the rewritten head 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:
Earlier findings
Verified (sandbox; hyprsunset, session and network commands stubbed):
The schedule is not loaded by a running hyprsunset, and nothing starts it at loginAfter writing the config,
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
|
| 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
nullat 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,
--setupexited 0 with both profiles at the same minute (for example01: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
nullstub and PROPOSAL's "Exits 1" row do not match the API.
- Its
- Explicit
--setupand backups: the new menu row replaces any existinghyprsunset.confwithout a backup. PROPOSAL.md says "Hand-edits survive--setup's no-op-on-existing check", but--setuphas no such check; only the migration has one. Backing up a non-generated config, as--resetdoes, would matchomarchy-refresh-config. In--reset, the backupcpresult 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
--setupis 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--setupmust 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 writestime =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 without=$(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-locationkeeps only the city, and--setupgeocodes that name again with a second wttr.in request. Existing Omarchy code (omarchy-weather-icon) uses onewttr.in/?format=j1call, whosenearest_areaalready has coordinates. The comment claiming aweather.jsonback-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.
- The PR description still describes the earlier design: modes, submenu, state file, timer, QML change, first-run change, ipapi.co and
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.
|
Useful opt-in, but a few product/merge notes:
|
74cea02 to
9cd1c84
Compare
|
Thanks both. I've pushed a revision that rebases onto current
@llstrk (second review)
One thing I found by running it against the live APIs: a stored name without coordinates can geocode to the wrong place ( |
|
9cd1c84 to
5cae4cb
Compare
| 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." |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
5cae4cb to
1db502a
Compare
1db502a to
48b54b3
Compare
`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>
48b54b3 to
fe7eb7d
Compare
|
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, Two things I want a maintainer call on before this lands:
Standing down here. Will pick up again when a maintainer weighs in. |
What
omarchy toggle nightlight --setupschedules night light at your actual sunrise and sunset.--resetputs everything back. It is opt-in: nothing runs onomarchy update, and the bare toggle and--statusare unchanged.Reachable from Setup > Config > Nightlight Schedule or the command line.
Why
hyprsunset.confships with a single identity profile, so night light does nothing until you hand-write time profiles and addo.launch_on_start("hyprsunset")toautostart.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: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, asomarchy-weather-iconmakes.HH:MM, which is what hyprsunset's profiles are read in. Open-Meteo leaves the trailingZoff its UTC timestamps, so it is added beforedatereads them.hyprsunset.confyou wrote ashyprsunset.conf.bak.<epoch>(the namingomarchy-refresh-configuses). 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.o.launch_on_start("hyprsunset")toautostart.luaunless a line for it is already there, tagged so--resetcan take it out again.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).--resetcallsomarchy-refresh-configdirectly (so a failed conf restore stops--resetbefore it touches anything else), restores the shipped config with a backup, restarts, and removes the autostart line--setupadded. Autostart lines you wrote are left alone.nullhere: polar night repeats one time, polar day runs midnight to midnight, so equal local times mean there is nothing to scheduleomarchy weather location --sethyprsunset.confis a Stow/chezmoi symlinkautostart.luais updated in place tooHow 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
< 6000Kheuristic still works. The revision that merged withquattrois 5 files / +695 lines:bin/omarchy-toggle-nightlightgains--setupand--reset(the rest is unchanged)default/agents/skills/omarchy/SKILL.mdadds the new flag to the routing linedefault/omarchy/omarchy-menu.jsoncadds the menu entrymanual/13-toggles-idle-screensaver.mddocuments--setup/--resettest/shell.d/nightlight-test.shis the new test surfaceThe 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),
--resetfalsely succeeding when refresh fails (direct call toomarchy-refresh-configwith 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 (TZinstead ofNL_TZ).Limitations
--setupagain 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.omarchy weather location --set Victoriais geocoded by wttr.in to Victoria, Australia. The weather panel behaves the same way.--setupprints the coordinates it used and how to pin the place down (--set <name> <lat>,<lon>).--setupruns again.Overlap
#14347 (Night Light Config) and #12337 (temperatures in
shell.json) also touch night light. #14347 schedules by times you enter and also writeshyprsunset.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.shpasses 35/35. The suite stubs the network, hyprsunset, the session and the restart helper; pins the time zone; and covers: the existing toggle and--statuspaths, 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,--resetagainst the shipped config and against a hand-written one,--resetfailing 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 theZfix, 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.68returns07:24 18:28on this PDT machine today, which is the right local time.