mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-28 08:33:54 +00:00
024a383d64
Somewhen between systemd v239 and v242 upstream decided to no longer run a few system services with `DyanmicUser=1` but failed to provide a migration path for all the state those services left behind. For the case of systemd-timesync the state has to be moved from /var/lib/private/systemd/timesync to /var/lib/systemd/timesync if /var/lib/systemd/timesync is currently a symlink. We only do this if the stateVersion is still below 19.09 to avoid starting to have an ever growing activation script for (then) ancient systemd migrations that are no longer required. See https://github.com/systemd/systemd/issues/12131 for details about the missing migration path and related discussion.
55 lines
1.6 KiB
Nix
55 lines
1.6 KiB
Nix
{ 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.
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
|
|
config = mkIf config.services.timesyncd.enable {
|
|
|
|
systemd.additionalUpstreamSystemUnits = [ "systemd-timesyncd.service" ];
|
|
|
|
systemd.services.systemd-timesyncd = {
|
|
wantedBy = [ "sysinit.target" ];
|
|
restartTriggers = [ config.environment.etc."systemd/timesyncd.conf".source ];
|
|
};
|
|
|
|
environment.etc."systemd/timesyncd.conf".text = ''
|
|
[Time]
|
|
NTP=${concatStringsSep " " config.services.timesyncd.servers}
|
|
'';
|
|
|
|
users.users.systemd-timesync.uid = config.ids.uids.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
|
|
'';
|
|
};
|
|
|
|
}
|