Skip to content

switch-to-configuration-ng: Fix timers resulting in old unit running - #525813

Draft
nh2 wants to merge 1 commit into
NixOS:masterfrom
nh2:issue-49415-fix-systemd-timers-interrupting-stops-ng
Draft

nh2 wants to merge 1 commit into
NixOS:masterfrom
nh2:issue-49415-fix-systemd-timers-interrupting-stops-ng

Conversation

@nh2

@nh2 nh2 commented May 30, 2026

Copy link
Copy Markdown
Contributor
  • Draft PR because I LLM-translated this fully automatically from my Perl PR switch-to-configuration.pl: Fix timers resulting in old unit running #307562 to gather some quick feedback on the idea before I put more time into it.
    • Especially from @jmbaur and @dasJ via nixos/switch-to-configuration: add new implementation #308801 (comment)
    • I have also written comparatively little Rust so far, and have not read the code of switch-to-configuration-ng yet (haven't had the time to yet, just trying to make servers behave for now), so thorough review / change suggestions would be very appreciated. I have nothing against anybody familiar with switch-to-configuration-ng saying "OK I'll take it from here" and take over, though I'll also be happy to put in more time and implement review feedback if preferred.

Fixes #49415.

This is the backport of the equivalent fix to switch-to-configuration.pl PR'd in #307562.

This is a fully LLM-automated translation of that older PR to the Rust switch-to-configuration-ng.

Assisted-by: Zoo Code + Claude Opus 4.8


I have verified that without this patch, the problem my PR in #307562 fixed in switch-to-configuration.pl is present in switch-to-configuration-ng of NixOS 25.11, and that this PR apparently fixes it.

I could repro the bug after 2 switch-to-configurations without the patch, but with this patch could not repro it within 10 tries. So that's promising. The expected new output

starting (via restart, see #49415) the following units: [email protected]

is printed when I change a config file (I use nebula for testing, and suffering from, this) via:

services.nebula.networks."mynet".settings.lighthouse.interval = 22;

Things done

…ixes NixOS#49415

This is the backport of the equivalent fix to `switch-to-configuration.pl`
PR'd in NixOS#307562.

This is a fully LLM-automated translation of that older PR
to the Rust `switch-to-configuration-ng`.

Assisted-by: Zoo Code + Claude Opus 4.8
@nh2 nh2 self-assigned this May 30, 2026
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS labels May 30, 2026
@nh2

nh2 commented May 30, 2026

Copy link
Copy Markdown
Contributor Author

It would be wise here to re-read the feedback from #307562

in particular the regression test #307562 (comment)

@Sigmanificient Sigmanificient added the llm-assisted Contributions that include code generation with LLMs label Jul 16, 2026
@ElXreno

ElXreno commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

A data point: the same failure through socket activation, with no timer involved (switch-to-configuration-ng from nixos-unstable 2786a2a, systemd 262).

A switch changed only postgresql.service. An unchanged dependent, nixbot.service (Requires=postgresql.target, TriggeredBy=nixbot.socket), was stopped by propagation, but its socket kept listening. It got a start job 0.6 s after postgres had stopped and pulled postgres up from the old unit definition, 8.5 s before daemon-reload:

40.681  Stopped PostgreSQL Server.
41.308  Starting PostgreSQL Server...        old unit definition
41.745  Starting nixbot CI service...
49.851  Reload requested from client PID ... ('.switch-to-conf')
50.97+  start phase, no "Starting PostgreSQL": already active

Postgres then ran the old config with a fresh ActiveEnterTimestamp and NeedDaemonReload=no, and the switch reported success.

Unlike the timer case, the stop job is not cancelled: it completes and the unit is started again afterwards. Reading the diff, this PR covers it, because the unit is in both units_to_stop and units_to_start. I have not run it.

Prepared with an AI assistant (Claude); the logs are from my machine.

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

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. llm-assisted Contributions that include code generation with LLMs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

systemd timers can result in changed services not being restarted reliably

3 participants