Skip to content

Commit

Permalink
ntp: make timesyncd the new default
Browse files Browse the repository at this point in the history
- most nixos user only require time synchronisation,
  while ntpd implements a battery-included ntp server (1,215 LOCs of C-Code vs 64,302)
- timesyncd support ntp server per interface (if configured through dhcp for instance)
- timesyncd is already included in the systemd package, switching to it would
  save a little disk space (1,5M)
  • Loading branch information
Mic92 committed Dec 16, 2016
1 parent 993cbf8 commit 1590461
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 26 deletions.
12 changes: 12 additions & 0 deletions nixos/modules/config/networking.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ in
'';
};

networking.timeServers = mkOption {
default = [
"0.nixos.pool.ntp.org"
"1.nixos.pool.ntp.org"
"2.nixos.pool.ntp.org"
"3.nixos.pool.ntp.org"
];
description = ''
The set of NTP servers from which to synchronise.
'';
};

networking.proxy = {

default = lib.mkOption {
Expand Down
4 changes: 2 additions & 2 deletions nixos/modules/services/networking/chrony.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ in
};

servers = mkOption {
default = config.services.ntp.servers;
default = config.networking.timeServers;
description = ''
The set of NTP servers from which to synchronise.
'';
Expand Down Expand Up @@ -102,7 +102,7 @@ in
home = stateDir;
};

systemd.services.ntpd.enable = mkForce false;
systemd.services.timesyncd.enable = mkForce false;

systemd.services.chronyd =
{ description = "chrony NTP daemon";
Expand Down
10 changes: 3 additions & 7 deletions nixos/modules/services/networking/ntpd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,15 @@ in
services.ntp = {

enable = mkOption {
default = !config.boot.isContainer;
default = false;
description = ''
Whether to synchronise your machine's time using the NTP
protocol.
'';
};

servers = mkOption {
default = [
"0.nixos.pool.ntp.org"
"1.nixos.pool.ntp.org"
"2.nixos.pool.ntp.org"
"3.nixos.pool.ntp.org"
];
default = config.networking.timeServers;
description = ''
The set of NTP servers from which to synchronise.
'';
Expand All @@ -70,6 +65,7 @@ in

# Make tools such as ntpq available in the system path.
environment.systemPackages = [ pkgs.ntp ];
services.timesyncd.enable = mkForce false;

users.extraUsers = singleton
{ name = ntpUser;
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/networking/openntpd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ in
###### implementation

config = mkIf cfg.enable {
services.ntp.enable = mkForce false;
services.timesyncd.enable = mkForce false;

# Add ntpctl to the environment for status checking
environment.systemPackages = [ package ];
Expand Down
3 changes: 0 additions & 3 deletions nixos/modules/system/boot/networkd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,5 @@ in
};

services.resolved.enable = mkDefault true;
services.timesyncd.enable = mkDefault config.services.ntp.enable;

};

}
23 changes: 14 additions & 9 deletions nixos/modules/system/boot/timesyncd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ with lib;

options = {

services.timesyncd.enable = mkOption {
default = false;
type = types.bool;
description = ''
Enables the systemd NTP client daemon.
'';
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 {
Expand All @@ -30,8 +37,6 @@ with lib;
NTP=${concatStringsSep " " config.services.ntp.servers}
'';

systemd.services.ntpd.enable = false;

users.extraUsers.systemd-timesync.uid = config.ids.uids.systemd-timesync;
users.extraGroups.systemd-timesync.gid = config.ids.gids.systemd-timesync;

Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/virtualisation/google-compute-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ in
169.254.169.254 metadata.google.internal metadata
'';

services.ntp.servers = [ "metadata.google.internal" ];
networking.timeServers = [ "metadata.google.internal" ];

networking.usePredictableInterfaceNames = false;

Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/virtualisation/parallels-guest.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ in

boot.kernelModules = [ "prl_tg" "prl_eth" "prl_fs" "prl_fs_freeze" "acpi_memhotplug" ];

services.ntp.enable = false;
services.timesyncd.enable = false;

systemd.services.prltoolsd = {
description = "Parallels Tools' service";
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/virtualisation/qemu-vm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ in
boot.initrd.luks.devices = mkVMOverride {};

# Don't run ntpd in the guest. It should get the correct time from KVM.
services.ntp.enable = false;
services.timesyncd.enable = false;

system.build.vm = pkgs.runCommand "nixos-vm" { preferLocalBuild = true; }
''
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/virtualisation/xen-domU.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
services.syslogd.tty = "hvc0";

# Don't run ntpd, since we should get the correct time from Dom0.
services.ntp.enable = false;
services.timesyncd.enable = false;
}

0 comments on commit 1590461

Please sign in to comment.