Chrony: Consider always online

sudo in hook thinks NoNewPrivleges flag is stil active.
I don't have it in me to try to fix this,
all my computers are more or less always online,
and it doesn't sync time often enough to be noticeable on battery
(proabably).
This commit is contained in:
Geoffrey Frogeye 2025-05-22 16:42:30 +02:00
parent a4978d6c12
commit 12c176de22
2 changed files with 1 additions and 36 deletions

View file

@ -1,6 +1,5 @@
{
lib,
config,
...
}:
{
@ -9,39 +8,8 @@
services.chrony.enable = true;
networking = {
# Using community provided service
# Using european servers
timeServers = map (n: "${toString n}.europe.pool.ntp.org") (lib.lists.range 0 3);
# Only try to sync time when we have internet connection
dhcpcd.runHook = ''
if $if_up
then
/run/wrappers/bin/sudo ${config.services.chrony.package}/bin/chronyc online
elif $if_down
then
/run/wrappers/bin/sudo ${config.services.chrony.package}/bin/chronyc offline
fi
'';
};
# Allow dhcpcd to control chrony
security.sudo.extraRules = [
{
users = [ "dhcpcd" ];
commands =
builtins.map
(arg: {
command = "${config.services.chrony.package}/bin/chronyc ${arg}";
options = [ "NOPASSWD" ];
})
[
"online"
"offline"
];
}
];
systemd.services.dhcpcd.serviceConfig.NoNewPrivileges = false;
};
}

View file

@ -90,9 +90,6 @@ in
};
};
# Wait until there's a connection to fetch time
services.chrony.serverOption = "offline";
systemd.services.wifi_apply = {
after = [ "wpa_supplicant.service" ];
wantedBy = [ "wpa_supplicant.service" ];