Skip to content

Commit 31942f2

Browse files
SFrijtersthoughtpolice
authored andcommitted
nixos/ntpd: fix permissions error when creating drift file
This fixes "frequency file /var/lib/ntp/ntp.drift.TEMP: Permission denied". Creating a directory via StateDirectory makes that directory /var/lib/ntp owned by root:root. However, when running ntpd we change to user ntp (see ntpFlags), so the process cannot actually use that directory. Actually creating a home directory for the user at that location solves that problem.
1 parent 6055456 commit 31942f2

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

nixos/modules/services/networking/ntp/ntpd.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ in
142142
group = "ntp";
143143
description = "NTP daemon user";
144144
home = "/var/lib/ntp";
145+
createHome = true;
145146
};
146147
users.groups.ntp = { };
147148

@@ -155,7 +156,6 @@ in
155156
serviceConfig = {
156157
ExecStart = "@${ntp}/bin/ntpd ntpd -g ${builtins.toString ntpFlags}";
157158
Type = "forking";
158-
StateDirectory = "ntp";
159159

160160
# Hardening options
161161
PrivateDevices = true;

nixos/tests/ntpd.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import ./make-test-python.nix (
2020
machine.wait_for_console_text('Listen normally on 10 eth*')
2121
machine.succeed('systemctl is-active ntpd.service')
2222
machine.succeed('ntpq -p')
23+
# ntp user must be able to create drift files
24+
machine.succeed('su -s /bin/sh -c "touch /var/lib/ntp/ntp.drift" ntp')
2325
'';
2426
}
2527
)

0 commit comments

Comments
 (0)