about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJulian Stecklina <js@alien8.de>2023-10-17 13:43:37 +0200
committernikstur <nikstur@outlook.com>2023-10-25 00:48:35 +0200
commit3c1c4b65e9eaf68e49113cba5dfe6750596fc86f (patch)
treeded8598c7d6a7752c8cde05779654c604aea358a
parentf827f7ad7b8b301b420d0a94b1db293e1e5be051 (diff)
downloadnixlib-3c1c4b65e9eaf68e49113cba5dfe6750596fc86f.tar
nixlib-3c1c4b65e9eaf68e49113cba5dfe6750596fc86f.tar.gz
nixlib-3c1c4b65e9eaf68e49113cba5dfe6750596fc86f.tar.bz2
nixlib-3c1c4b65e9eaf68e49113cba5dfe6750596fc86f.tar.lz
nixlib-3c1c4b65e9eaf68e49113cba5dfe6750596fc86f.tar.xz
nixlib-3c1c4b65e9eaf68e49113cba5dfe6750596fc86f.tar.zst
nixlib-3c1c4b65e9eaf68e49113cba5dfe6750596fc86f.zip
nixos/timesyncd: replace activationScript via ExecPreStart
-rw-r--r--nixos/modules/system/boot/timesyncd.nix45
1 files changed, 22 insertions, 23 deletions
diff --git a/nixos/modules/system/boot/timesyncd.nix b/nixos/modules/system/boot/timesyncd.nix
index a6604802c38c..7487cf97fe53 100644
--- a/nixos/modules/system/boot/timesyncd.nix
+++ b/nixos/modules/system/boot/timesyncd.nix
@@ -46,6 +46,28 @@ with lib;
       wantedBy = [ "sysinit.target" ];
       aliases = [ "dbus-org.freedesktop.timesync1.service" ];
       restartTriggers = [ config.environment.etc."systemd/timesyncd.conf".source ];
+
+      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
+          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 = ''
@@ -59,28 +81,5 @@ with lib;
       group = "systemd-timesync";
     };
     users.groups.systemd-timesync.gid = config.ids.gids.systemd-timesync;
-
-    system.activationScripts.systemd-timesyncd-migration =
-      # 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
-      mkIf (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
-      '';
-    system.activationScripts.systemd-timesyncd-init-clock =
-      # 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
-      fi
-      '';
   };
-
 }