modules/monitoring/grafana: restart grafana when the dashboards change (nix-config#361) #1383
No reviewers
Labels
No labels
backlog
bug
enhancement
in-progress
library
needs-rebase
review
todo
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ymrtech/nix-config!1383
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "kb/NCFG-361-grafana-dashboard-restart"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Kanban card nix-config#361.
Symptom (measured, not inferred)
While landing nix-config#350 the deploy swapped
/etc/grafana-dashboardsto the new store path and the RUNNING grafana (13.1.4 on mail) kept serving the version it loaded at its last start:/etc/grafana-dashboards/command-tracking.json->/nix/store/4k6wmynfx19m3dzp697jiq2m527f9p3d-grafana-dashboards/command-tracking.json, sha256 equal to origin/main's blob (the file on disk WAS the new one);GET /api/dashboards/uid/command-tracking(Grafana admin on mail) still answeredpanels: 12,time.from: now-1h,meta.updated: 2026-09-22T23:57:24for the whole 7-minute polling window;systemctl restart grafanamade it live (then 18 panels, now-24h).Consequence: every dashboards edit merged since grafana last started (2026-09-23 on mail) was silently invisible to the operator.
Change
modules/monitoring/grafana.nix:letblock (dashboardsDrv) instead of living inline in thesystemd.tmpfiles.rulesstring;"L+ ${cfg.dashboardsDir} - - - - ${dashboardsDrv}/"(both were hardcoded before);systemd.services.grafana.restartTriggers = [ dashboardsDrv ].nixpkgs hashes trigger paths into the unit's
X-Restart-Triggers, so a dashboard edit changes the derivation's store path, the hash changes, andswitch-to-configurationrestarts grafana as part of the deploy. This is the mechanismhosts/already uses for the other generated inputs (uptime-kuma static monitors + status page, adguard policy, unbound), so it is consistent rather than novel.Evidence on this tree (eval, before merge)
The trigger references the very store path the deployed symlink already points at, and the tmpfiles rule is byte-identical to the pre-change one — so this PR adds the restart and does not churn mail's symlink.
Pin
.forgejo/tests/test-grafana-dashboards-restart.sh(new, offline, ~0.1s, wired into nix-build-check.yml's offline-tests step): the real tree must carry all three pieces, and each of four mutations (trigger line deleted / pointed at a literal / emptied / tmpfiles symlink no longer pointing into the derivation) must turn the test red. Deleting the trigger is exactly what a future refactor does by accident, and eval cannot catch it — the host builds green and merely never restarts, which is how this bug shipped.Deliberately out of scope
No dashboard JSON content changes; no change to
cfg.dashboardsDir's default or any other host's grafana wiring.