From 7ccd3bd8f43453c7b60cbc00a29e4fa3d40204da Mon Sep 17 00:00:00 2001 From: nikstur Date: Wed, 8 Oct 2025 14:43:19 +0200 Subject: [PATCH] nixos/timesyncd: remove unnecessary workaround This workardoung is now unnecessary because systemd and systemd-timesyncd will never actually revert to a time lower than the current system time. It will only *advance* the system time to the EPOCH if the system time is lower. This also makes systemd-timesyncd bashless as we remove the preStart script for any NixOS version newer than 19.09. --- nixos/modules/system/boot/timesyncd.nix | 30 ++++++++----------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/nixos/modules/system/boot/timesyncd.nix b/nixos/modules/system/boot/timesyncd.nix index eed83af5715f..71f49a675b12 100644 --- a/nixos/modules/system/boot/timesyncd.nix +++ b/nixos/modules/system/boot/timesyncd.nix @@ -75,28 +75,16 @@ in # NSS module path so that systemd-timesyncd keeps using other NSS modules that are configured in the system. environment.LD_LIBRARY_PATH = config.system.nssModules.path; - preStart = ( - # Ensure that we have some stored time to prevent - # systemd-timesyncd to resort back to the fallback time. If - # the file doesn't exist we assume that our current system - # clock is good enough to provide an initial value. - '' - if ! [ -f /var/lib/systemd/timesync/clock ]; then - test -d /var/lib/systemd/timesync || mkdir -p /var/lib/systemd/timesync - touch /var/lib/systemd/timesync/clock + preStart = + # workaround an issue of systemd-timesyncd not starting due to upstream systemd reverting their dynamic users changes + # - https://github.com/NixOS/nixpkgs/pull/61321#issuecomment-492423742 + # - https://github.com/systemd/systemd/issues/12131 + lib.optionalString (versionOlder config.system.stateVersion "19.09") '' + if [ -L /var/lib/systemd/timesync ]; then + rm /var/lib/systemd/timesync + mv /var/lib/private/systemd/timesync /var/lib/systemd/timesync fi - '' - + - # workaround an issue of systemd-timesyncd not starting due to upstream systemd reverting their dynamic users changes - # - https://github.com/NixOS/nixpkgs/pull/61321#issuecomment-492423742 - # - https://github.com/systemd/systemd/issues/12131 - (lib.optionalString (versionOlder config.system.stateVersion "19.09") '' - if [ -L /var/lib/systemd/timesync ]; then - rm /var/lib/systemd/timesync - mv /var/lib/private/systemd/timesync /var/lib/systemd/timesync - fi - '') - ); + ''; }; environment.etc."systemd/timesyncd.conf".text = ''