aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/nixos/modules/system/boot/timesyncd.nix
diff options
context:
space:
mode:
authorMx Kookie <kookie@spacekookie.de>2020-10-31 19:35:09 +0100
committerMx Kookie <kookie@spacekookie.de>2020-10-31 19:35:09 +0100
commitc4625b175f8200f643fd6e11010932ea44c78433 (patch)
treebce3f89888c8ac3991fa5569a878a9eab6801ccc /infra/libkookie/nixpkgs/nixos/modules/system/boot/timesyncd.nix
parent49f735974dd103039ddc4cb576bb76555164a9e7 (diff)
parentd661aa56a8843e991261510c1bb28fdc2f6975ae (diff)
Add 'infra/libkookie/' from commit 'd661aa56a8843e991261510c1bb28fdc2f6975ae'
git-subtree-dir: infra/libkookie git-subtree-mainline: 49f735974dd103039ddc4cb576bb76555164a9e7 git-subtree-split: d661aa56a8843e991261510c1bb28fdc2f6975ae
Diffstat (limited to 'infra/libkookie/nixpkgs/nixos/modules/system/boot/timesyncd.nix')
-rw-r--r--infra/libkookie/nixpkgs/nixos/modules/system/boot/timesyncd.nix71
1 files changed, 71 insertions, 0 deletions
diff --git a/infra/libkookie/nixpkgs/nixos/modules/system/boot/timesyncd.nix b/infra/libkookie/nixpkgs/nixos/modules/system/boot/timesyncd.nix
new file mode 100644
index 000000000000..35fb5578b070
--- /dev/null
+++ b/infra/libkookie/nixpkgs/nixos/modules/system/boot/timesyncd.nix
@@ -0,0 +1,71 @@
+{ config, lib, ... }:
+
+with lib;
+
+{
+
+ options = {
+
+ services.timesyncd = {
+ enable = mkOption {
+ default = !config.boot.isContainer;
+ type = types.bool;
+ description = ''
+ Enables the systemd NTP client daemon.
+ '';
+ };
+ servers = mkOption {
+ default = config.networking.timeServers;
+ description = ''
+ The set of NTP servers from which to synchronise.
+ '';
+ };
+ extraConfig = mkOption {
+ default = "";
+ type = types.lines;
+ example = ''
+ PollIntervalMaxSec=180
+ '';
+ description = ''
+ Extra config options for systemd-timesyncd. See
+ <link xlink:href="https://www.freedesktop.org/software/systemd/man/timesyncd.conf.html">
+ timesyncd.conf(5)</link> for available options.
+ '';
+ };
+ };
+ };
+
+ config = mkIf config.services.timesyncd.enable {
+
+ systemd.additionalUpstreamSystemUnits = [ "systemd-timesyncd.service" ];
+
+ systemd.services.systemd-timesyncd = {
+ wantedBy = [ "sysinit.target" ];
+ aliases = [ "dbus-org.freedesktop.timesync1.service" ];
+ restartTriggers = [ config.environment.etc."systemd/timesyncd.conf".source ];
+ };
+
+ environment.etc."systemd/timesyncd.conf".text = ''
+ [Time]
+ NTP=${concatStringsSep " " config.services.timesyncd.servers}
+ ${config.services.timesyncd.extraConfig}
+ '';
+
+ users.users.systemd-timesync = {
+ uid = config.ids.uids.systemd-timesync;
+ group = "systemd-timesync";
+ };
+ users.groups.systemd-timesync.gid = config.ids.gids.systemd-timesync;
+
+ system.activationScripts.systemd-timesyncd-migration = mkIf (versionOlder config.system.stateVersion "19.09") ''
+ # 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
+ if [ -L /var/lib/systemd/timesync ]; then
+ rm /var/lib/systemd/timesync
+ mv /var/lib/private/systemd/timesync /var/lib/systemd/timesync
+ fi
+ '';
+ };
+
+}