From 78b4fc0ca55addf60174467d86ac024b64c0ced4 Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Sun, 1 Nov 2026 14:08:59 +0000 Subject: [PATCH 1/2] nixos/home: fold script-installed laptop units into the flake (code#3720) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One home-manager module per system, enabled from nixos/hosts/default.nix next to the existing laptop modules, replicating the installed units' semantics exactly (ExecStart, WorkingDirectory, timer schedules, timeouts, Nice); executed scripts stay at their checkout paths per the fleet-feed-collector precedent — only unit provenance changes. Systems: github-backup (drain/fetch/reconcile), worktree-reaper, cloudflare-quota-export, meta-quota-export, dashboard-backup, oc-password-sync. One intentional difference: worktree-reaper's ExecStart moves from the pre-merge bootstrap worktree (~/git/code-wt-reaper) to the canonical primary path (~/git/code/infra/worktree-reaper), retiring the bootstrap install per the reaper README; this therefore lands after #3698 merges. --- nixos/home/cloudflare-quota-export.nix | 51 ++++++++++++++++ nixos/home/dashboard-backup.nix | 47 +++++++++++++++ nixos/home/github-backup.nix | 81 ++++++++++++++++++++++++++ nixos/home/meta-quota-export.nix | 50 ++++++++++++++++ nixos/home/oc-password-sync.nix | 36 ++++++++++++ nixos/home/worktree-reaper.nix | 61 +++++++++++++++++++ nixos/hosts/default.nix | 51 ++++++++++++++++ 7 files changed, 377 insertions(+) create mode 100644 nixos/home/cloudflare-quota-export.nix create mode 100644 nixos/home/dashboard-backup.nix create mode 100644 nixos/home/github-backup.nix create mode 100644 nixos/home/meta-quota-export.nix create mode 100644 nixos/home/oc-password-sync.nix create mode 100644 nixos/home/worktree-reaper.nix diff --git a/nixos/home/cloudflare-quota-export.nix b/nixos/home/cloudflare-quota-export.nix new file mode 100644 index 0000000000..4487d996ce --- /dev/null +++ b/nixos/home/cloudflare-quota-export.nix @@ -0,0 +1,51 @@ +# cloudflare-quota-export — the Cloudflare quota exporter +# (developing-today/code#1048), run every 15 minutes as a +# quota-gatherer tick (developing-today/code#1151). +# +# Home-manager module: imported by the amd host config +# (nixos/hosts/default.nix) with +# services.cloudflare-quota-export.enable = true. +# +# Folded into the flake 2026-11-01 (developing-today/code#3720): +# until now the units were plain files in ~/.config/systemd/user. +# Semantics are replicated exactly; only provenance changes. The +# script itself stays at ~/atlas/cloudflare-export/, next to the +# data it exports. +{ + config, + lib, + ... +}: +let + cfg = config.services.cloudflare-quota-export; +in +{ + options.services.cloudflare-quota-export = { + enable = lib.mkEnableOption "the Cloudflare quota exporter (code#1048)"; + }; + + config = lib.mkIf cfg.enable { + systemd.user.services.cloudflare-quota-export = { + Unit = { + Description = "Cloudflare quota exporter — code#1048"; + After = [ "network-online.target" ]; + }; + Service = { + Type = "oneshot"; + TimeoutStartSec = 120; + ExecStart = "%h/atlas/cloudflare-export/cloudflare-quota-export.sh --out-dir %h/atlas/cloudflare-export"; + }; + }; + + systemd.user.timers.cloudflare-quota-export = { + Unit.Description = "Run the Cloudflare quota exporter every 15 minutes — code#1048 (gatherer tick, #1151)"; + Timer = { + OnCalendar = "*:0/15"; + RandomizedDelaySec = 20; + Persistent = true; + Unit = "cloudflare-quota-export.service"; + }; + Install.WantedBy = [ "timers.target" ]; + }; + }; +} diff --git a/nixos/home/dashboard-backup.nix b/nixos/home/dashboard-backup.nix new file mode 100644 index 0000000000..9c09030170 --- /dev/null +++ b/nixos/home/dashboard-backup.nix @@ -0,0 +1,47 @@ +# dashboard-backup — the daily dashboard/orchestration data +# backup, laptop leg (developing-today/code#1459). Script: +# ~/tools/dashboard-backup.sh, maintained by its author there. +# +# Home-manager module: imported by the amd host config +# (nixos/hosts/default.nix) with services.dashboard-backup.enable = true. +# +# Folded into the flake 2026-11-01 (developing-today/code#3720): +# until now the units were plain files in ~/.config/systemd/user. +# Semantics are replicated exactly; only provenance changes. +# +# NOT the flake's pm-dashboard-backup (nixos/home/laptop-backups.nix, +# code#1516): that is a separate, newer job. This older job is folded +# in as-is; merging the two backups is a separate decision. +{ + config, + lib, + ... +}: +let + cfg = config.services.dashboard-backup; +in +{ + options.services.dashboard-backup = { + enable = lib.mkEnableOption "the daily dashboard backup, laptop leg (code#1459)"; + }; + + config = lib.mkIf cfg.enable { + systemd.user.services.dashboard-backup = { + Unit.Description = "Daily dashboard/orchestration data backup (laptop leg, code#1459)"; + Service = { + Type = "oneshot"; + ExecStart = "%h/tools/dashboard-backup.sh"; + }; + }; + + systemd.user.timers.dashboard-backup = { + Unit.Description = "Run dashboard backup daily ~04:30 local (code#1459)"; + Timer = { + OnCalendar = "*-*-* 04:30:00"; + Persistent = true; + Unit = "dashboard-backup.service"; + }; + Install.WantedBy = [ "timers.target" ]; + }; + }; +} diff --git a/nixos/home/github-backup.nix b/nixos/home/github-backup.nix new file mode 100644 index 0000000000..240f7d6e94 --- /dev/null +++ b/nixos/home/github-backup.nix @@ -0,0 +1,81 @@ +# github-backup — the GitHub estate mirror system's laptop timers +# (developing-today/code#3215): drain the Worker webhook queue every +# 5 minutes, fetch all mirrors daily, reconcile weekly. +# +# Home-manager module: imported by the amd host config +# (nixos/hosts/default.nix) with services.github-backup.enable = true. +# +# Folded into the flake 2026-11-01 (developing-today/code#3720): +# until now these units were plain files in ~/.config/systemd/user +# installed by infra/github-backup's installer. Semantics are +# replicated exactly; only provenance changes. The scripts stay in +# this repo and run from the primary checkout (~/git/code), per the +# fleet-feed-collector precedent. The drain wrapper +# (infra/github-backup/systemd/drain-wrapper.sh) sources the Worker +# URL + bearer from Bitwarden by name at runtime, so the units need +# no Environment of their own. +{ + config, + lib, + ... +}: +let + cfg = config.services.github-backup; + home = config.home.homeDirectory; + infra = "${home}/git/code/infra/github-backup"; + netService = description: execStart: { + Unit = { + Description = description; + After = [ "network-online.target" ]; + Wants = [ "network-online.target" ]; + }; + Service = { + Type = "oneshot"; + ExecStart = execStart; + WorkingDirectory = "%h/backups/github"; + }; + }; +in +{ + options.services.github-backup = { + enable = lib.mkEnableOption "the github-backup mirror timers (drain, fetch, reconcile)"; + }; + + config = lib.mkIf cfg.enable { + systemd.user.services = { + github-backup-drain = netService "github-backup: drain webhook queue from the Worker and fetch" "${infra}/systemd/drain-wrapper.sh"; + github-backup-fetch = netService "github-backup: daily fetch of all mirrors" "/usr/bin/env python3 ${infra}/bin/fetch_mirrors.py"; + github-backup-reconcile = netService "github-backup: weekly reconciliation sweep" "/usr/bin/env python3 ${infra}/bin/reconcile.py"; + }; + + systemd.user.timers = { + github-backup-drain = { + Unit.Description = "github-backup queue drain (every 5 min)"; + Timer = { + OnBootSec = "3min"; + OnUnitActiveSec = "5min"; + Persistent = true; + }; + Install.WantedBy = [ "timers.target" ]; + }; + github-backup-fetch = { + Unit.Description = "github-backup fetch (daily)"; + Timer = { + OnCalendar = "daily"; + Persistent = true; + RandomizedDelaySec = "30m"; + }; + Install.WantedBy = [ "timers.target" ]; + }; + github-backup-reconcile = { + Unit.Description = "github-backup reconcile (weekly)"; + Timer = { + OnCalendar = "weekly"; + Persistent = true; + RandomizedDelaySec = "2h"; + }; + Install.WantedBy = [ "timers.target" ]; + }; + }; + }; +} diff --git a/nixos/home/meta-quota-export.nix b/nixos/home/meta-quota-export.nix new file mode 100644 index 0000000000..1893018ff9 --- /dev/null +++ b/nixos/home/meta-quota-export.nix @@ -0,0 +1,50 @@ +# meta-quota-export — the Meta (dev.meta.ai) quota exporter +# (developing-today/code#1301 Phase 1), run every 15 minutes. +# +# Home-manager module: imported by the amd host config +# (nixos/hosts/default.nix) with +# services.meta-quota-export.enable = true. +# +# Folded into the flake 2026-11-01 (developing-today/code#3720): +# until now the units were plain files in ~/.config/systemd/user. +# Semantics are replicated exactly; only provenance changes. The +# script itself stays at ~/atlas/meta-quota-export/, next to the +# data it exports, and runs under the system node. +{ + config, + lib, + ... +}: +let + cfg = config.services.meta-quota-export; +in +{ + options.services.meta-quota-export = { + enable = lib.mkEnableOption "the Meta quota exporter (code#1301)"; + }; + + config = lib.mkIf cfg.enable { + systemd.user.services.meta-quota-export = { + Unit = { + Description = "Meta (dev.meta.ai) quota exporter — code#1301 Phase 1"; + After = [ "network-online.target" ]; + }; + Service = { + Type = "oneshot"; + TimeoutStartSec = 120; + ExecStart = "/run/current-system/sw/bin/node %h/atlas/meta-quota-export/meta-quota-export.mjs --cdp-port 19222 --out-dir %h/atlas/meta-quota-export"; + }; + }; + + systemd.user.timers.meta-quota-export = { + Unit.Description = "Run the Meta quota exporter every 15 minutes — code#1301 Phase 1"; + Timer = { + OnCalendar = "*:0/15"; + RandomizedDelaySec = 20; + Persistent = true; + Unit = "meta-quota-export.service"; + }; + Install.WantedBy = [ "timers.target" ]; + }; + }; +} diff --git a/nixos/home/oc-password-sync.nix b/nixos/home/oc-password-sync.nix new file mode 100644 index 0000000000..f656a6bb75 --- /dev/null +++ b/nixos/home/oc-password-sync.nix @@ -0,0 +1,36 @@ +# oc-password-sync — sync the OpenChamber upstream password from +# the prod OpenCode service file (developing-today/openchamber#894). +# Oneshot enabled into default.target, so it runs at user-session +# start. Script: ~/.local/bin/oc-password-sync.sh. +# +# Home-manager module: imported by the amd host config +# (nixos/hosts/default.nix) with services.oc-password-sync.enable = true. +# +# Folded into the flake 2026-11-01 (developing-today/code#3720): +# until now the unit was a plain file in ~/.config/systemd/user. +# Semantics are replicated exactly; only provenance changes. +{ + config, + lib, + ... +}: +let + cfg = config.services.oc-password-sync; + home = config.home.homeDirectory; +in +{ + options.services.oc-password-sync = { + enable = lib.mkEnableOption "the OpenChamber upstream password sync (openchamber#894)"; + }; + + config = lib.mkIf cfg.enable { + systemd.user.services.oc-password-sync = { + Unit.Description = "Sync OpenChamber upstream password from prod OpenCode service file (openchamber#894)"; + Service = { + Type = "oneshot"; + ExecStart = "${home}/.local/bin/oc-password-sync.sh"; + }; + Install.WantedBy = [ "default.target" ]; + }; + }; +} diff --git a/nixos/home/worktree-reaper.nix b/nixos/home/worktree-reaper.nix new file mode 100644 index 0000000000..71104a7997 --- /dev/null +++ b/nixos/home/worktree-reaper.nix @@ -0,0 +1,61 @@ +# worktree-reaper — hourly retirement of dead fleet worktrees on +# the laptop under Drew's 6-hour quiet rule +# (developing-today/code#3698). +# +# Home-manager module: imported by the amd host config +# (nixos/hosts/default.nix) with services.worktree-reaper.enable = true. +# +# Folded into the flake 2026-11-01 (developing-today/code#3720). +# Until now the unit was a plain file in ~/.config/systemd/user, +# installed by infra/worktree-reaper/systemd/install-units.sh from +# the pre-merge bootstrap worktree ~/git/code-wt-reaper, and its +# ExecStart pointed there. The fold's one intentional unit change: +# ExecStart now points at the canonical primary checkout +# (~/git/code/infra/worktree-reaper/...), retiring the bootstrap +# install per the worktree-reaper README. Every other field is +# replicated exactly. All reaper state (config overlay, run logs, +# the DISABLED kill switch) lives in ~/.local/state/worktree-reaper/ +# and is unaffected by where the unit comes from; the script reads +# the config.json shipped beside it in infra/worktree-reaper and +# merges the state-dir overlay on top, as before. +{ + config, + lib, + ... +}: +let + cfg = config.services.worktree-reaper; + home = config.home.homeDirectory; +in +{ + options.services.worktree-reaper = { + enable = lib.mkEnableOption "the worktree reaper (hourly dead-worktree retirement, code#3698)"; + }; + + config = lib.mkIf cfg.enable { + systemd.user.services.worktree-reaper = { + Unit = { + Description = "worktree-reaper: retire dead fleet worktrees (6-hour quiet rule)"; + After = [ "network-online.target" ]; + Wants = [ "network-online.target" ]; + }; + Service = { + Type = "oneshot"; + ExecStart = "/usr/bin/env python3 ${home}/git/code/infra/worktree-reaper/bin/worktree_reaper.py"; + WorkingDirectory = "%h"; + TimeoutStartSec = "6h"; + Nice = 10; + }; + }; + + systemd.user.timers.worktree-reaper = { + Unit.Description = "worktree-reaper (hourly)"; + Timer = { + OnCalendar = "hourly"; + Persistent = true; + RandomizedDelaySec = "10m"; + }; + Install.WantedBy = [ "timers.target" ]; + }; + }; +} diff --git a/nixos/hosts/default.nix b/nixos/hosts/default.nix index 82cde0b7ea..1d34f19551 100644 --- a/nixos/hosts/default.nix +++ b/nixos/hosts/default.nix @@ -120,6 +120,57 @@ in services.laptop-autocommit.enable = true; }; } + { + # GitHub backup mirror timers (code#3215): webhook-queue + # drain every 5 min, daily mirror fetch, weekly reconcile. + # Folded into the flake 2026-11-01 (code#3720); the scripts + # run from the primary checkout (infra/github-backup). + home-manager.users.user = { + imports = [ ../home/github-backup.nix ]; + services.github-backup.enable = true; + }; + } + { + # Worktree reaper (code#3698): hourly retirement of dead + # fleet worktrees under the 6-hour quiet rule. Folded into + # the flake 2026-11-01 (code#3720); ExecStart points at the + # primary checkout, retiring the bootstrap-worktree install. + home-manager.users.user = { + imports = [ ../home/worktree-reaper.nix ]; + services.worktree-reaper.enable = true; + }; + } + { + # Quota exporters (code#1048, code#1301): Cloudflare + Meta + # quota snapshots every 15 min for the quota gatherer. + # Folded into the flake 2026-11-01 (code#3720). + home-manager.users.user = { + imports = [ + ../home/cloudflare-quota-export.nix + ../home/meta-quota-export.nix + ]; + services.cloudflare-quota-export.enable = true; + services.meta-quota-export.enable = true; + }; + } + { + # Dashboard backup, laptop leg (code#1459) — the older + # ~/tools job, distinct from pm-dashboard-backup above. + # Folded into the flake 2026-11-01 (code#3720). + home-manager.users.user = { + imports = [ ../home/dashboard-backup.nix ]; + services.dashboard-backup.enable = true; + }; + } + { + # OpenChamber password sync (openchamber#894): oneshot at + # session start keeping the upstream password current. + # Folded into the flake 2026-11-01 (code#3720). + home-manager.users.user = { + imports = [ ../home/oc-password-sync.nix ]; + services.oc-password-sync.enable = true; + }; + } # KRdp remote desktop for this laptop (user service + package); # see the file for the one-time on-machine credential setup. ./amd-krdp.nix From 82a273f7dc5e9880647bc6babe79c9ffae7859c2 Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Sun, 1 Nov 2026 14:22:43 +0000 Subject: [PATCH 2/2] nixos/home: include oc-password-sync.path in the fold (code#3720) Live census correction: the oc-password-sync system is two units, not one. oc-password-sync.path (also a plain file) watches the prod OpenCode service file and triggers the service; it is the unit actually enabled into default.target. The .service's own [Install] is dormant. Both are now declared in nixos/home/oc-password-sync.nix, replicating the installed files exactly. --- nixos/home/oc-password-sync.nix | 19 ++++++++++++++++--- nixos/hosts/default.nix | 5 +++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/nixos/home/oc-password-sync.nix b/nixos/home/oc-password-sync.nix index f656a6bb75..cdc6a22567 100644 --- a/nixos/home/oc-password-sync.nix +++ b/nixos/home/oc-password-sync.nix @@ -1,13 +1,17 @@ # oc-password-sync — sync the OpenChamber upstream password from # the prod OpenCode service file (developing-today/openchamber#894). -# Oneshot enabled into default.target, so it runs at user-session -# start. Script: ~/.local/bin/oc-password-sync.sh. +# A .path unit watches the prod service file +# (~/.local/state/opencode/service-prod.json) and triggers the +# oneshot service on change; the .path unit is the one enabled into +# default.target. (The service file also carries its own +# [Install] WantedBy=default.target, dormant in practice; it is +# replicated as installed.) Script: ~/.local/bin/oc-password-sync.sh. # # Home-manager module: imported by the amd host config # (nixos/hosts/default.nix) with services.oc-password-sync.enable = true. # # Folded into the flake 2026-11-01 (developing-today/code#3720): -# until now the unit was a plain file in ~/.config/systemd/user. +# until now the units were plain files in ~/.config/systemd/user. # Semantics are replicated exactly; only provenance changes. { config, @@ -32,5 +36,14 @@ in }; Install.WantedBy = [ "default.target" ]; }; + + systemd.user.paths.oc-password-sync = { + Unit.Description = "Watch prod OpenCode service file for password rotation (openchamber#894)"; + Path = { + PathChanged = "${home}/.local/state/opencode/service-prod.json"; + Unit = "oc-password-sync.service"; + }; + Install.WantedBy = [ "default.target" ]; + }; }; } diff --git a/nixos/hosts/default.nix b/nixos/hosts/default.nix index 1d34f19551..f05c2b508e 100644 --- a/nixos/hosts/default.nix +++ b/nixos/hosts/default.nix @@ -163,8 +163,9 @@ in }; } { - # OpenChamber password sync (openchamber#894): oneshot at - # session start keeping the upstream password current. + # OpenChamber password sync (openchamber#894): a .path unit + # watches the prod OpenCode service file and triggers the + # sync oneshot when the password rotates. # Folded into the flake 2026-11-01 (code#3720). home-manager.users.user = { imports = [ ../home/oc-password-sync.nix ];