This is an automated email from the git hooks/post-receive script.
guix_mirror_bot pushed a commit to branch master
in repository guix.
The following commit(s) were added to refs/heads/master by this push:
new d19bb5cf43f services: networking: Add chronyd service.
d19bb5cf43f is described below
commit d19bb5cf43f2fb41793813c6a43c7f77856ae0bd
Author: Sören Tempel <[email protected]>
AuthorDate: Sun Nov 8 15:41:18 2026 +0100
services: networking: Add chronyd service.
This allows using chronyd as an NTP daemon.
* gnu/services/networking.scm (chronyd-serialize-field): New procedure.
(chronyd-serialize-list-of-numbers): New procedure.
(chronyd-server): New record type.
(chronyd-serialize-chronyd-server): New procedure.
(chronyd-serialize-list-of-chronyd-server): New procedure.
(chronyd-configuration): New record type.
(chronyd-config-file): New procedure.
(chronyd-shepherd-service): New procedure.
(chronyd-account-service): New variable.
(chronyd-service-activation): New procedure.
(chronyd-service-type): New service.
(generate-chronyd-documentation): New procedure.
* doc/guix.texi (Networking Services): Document it.
* gnu/tests/networking.scm (%chronyd-os, %test-chronyd): New variable.
(run-chronyd-test): New procedure.
---
doc/guix.texi | 80 +++++++++++++++++
gnu/services/networking.scm | 210 ++++++++++++++++++++++++++++++++++++++++++++
gnu/tests/networking.scm | 73 +++++++++++++++
3 files changed, 363 insertions(+)
diff --git a/doc/guix.texi b/doc/guix.texi
index 178c78f073f..a1dc98a2496 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -24452,6 +24452,86 @@ to use with the options @option{iburst} and
@option{prefer}, as well as
@end table
@end deftp
+@cindex chronyd
+@defvar chronyd-service-type
+Run the @command{chronyd}, @acronym{Network Time Protocol, NTP} daemon.
+Contrary to other implementations, it is designed to perform well in a wide
+range of unstable conditions (e.g., intermittent network connections).
+
+The following example enables @command{chronyd}, forcing it to step the system
+clock if the adjustment is larger than @code{0.1} seconds, but only in the
+first three clock updates:
+
+@lisp
+(service chronyd-service-type
+ (chronyd-configuration
+ (makestep '(0.1 3))))
+@end lisp
+@end defvar
+
+@deftp {Data Type} chronyd-configuration
+Available @code{chronyd-configuration} fields are:
+
+@table @asis
+@item @code{chrony} (default: @code{chrony}) (type: file-like)
+Chrony package.
+
+@item @code{command-port} (default: @code{0}) (type: maybe-integer)
+Port that is used for run-time monitoring.
+
+@item @code{drift-file} (default: @code{"/var/lib/chronyd/drift"}) (type:
maybe-)
+File where @command{chronyd} stores rate information.
+
+@item @code{makestep} (type: maybe-list-of-numbers)
+Forces chrony to step the system clock if the adjustment is larger than
+a threshold value.
+
+@item @code{synchronize-rtc?} (type: maybe-boolean)
+System time is periodically copied to the @acronym{RTC,Real Time Clock}.
+
+@item @code{server} (default: @code{()}) (type: list-of-chronyd-server)
+NTP servers which should be used as a time source.
+
+@deftp {Data Type} chronyd-server
+Available @code{chronyd-server} fields are:
+
+@table @asis
+@item @code{host-name} (type: string)
+Hostname of the NTP server.
+
+@item @code{network-time-security?} (type: maybe-boolean)
+Whether to enable authentication using the Network Time Security (NTS)
+mechanism.
+
+@item @code{iburst?} (type: maybe-boolean)
+Whether to start with a burst of 4-8 requests in order to make the first
+update of the clock sooner.
+
+@item @code{burst?} (type: maybe-boolean)
+Whether to send a burst of up to 4 requests when chrony cannot get a
+good measurement from the server.
+
+@item @code{minimum-poll-interval} (type: maybe-integer)
+Minimum interval between requests.
+
+@item @code{maximum-poll-interval} (type: maybe-integer)
+Maximum interval between requests.
+
+@item @code{extra-content} (type: maybe-string)
+Raw content to add to the server directive
+
+@end table
+@end deftp
+
+@item @code{pool} (type: list-of-chronyd-server)
+Pool of NTP servers to connect to.
+
+@item @code{extra-content} (type: maybe-string)
+Raw content to add to the configuration file.
+
+@end table
+@end deftp
+
@cindex OpenNTPD
@defvar openntpd-service-type
Run the @command{ntpd}, the Network Time Protocol (NTP) daemon, as implemented
diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm
index c757174b502..a255c1bbc77 100644
--- a/gnu/services/networking.scm
+++ b/gnu/services/networking.scm
@@ -133,6 +133,13 @@
ntp-service-type
+ chronyd-configuration
+ chronyd-configuration?
+ chronyd-server
+ chronyd-server?
+ chronyd-service-type
+ generate-chronyd-documentation
+
%openntpd-servers
openntpd-configuration
openntpd-configuration?
@@ -650,6 +657,209 @@ will keep the system clock synchronized with that of the
given servers.")
(default-value (ntp-configuration))))
+;;;
+;;; chrony.
+;;;
+
+(define (chronyd-serialize-field-name field-name)
+ (case field-name
+ ((command-port) 'cmdport)
+ ((drift-file) 'driftfile)
+ ((synchronize-rtc?) 'rtcsync)
+ ((network-time-security?) 'nts)
+ ((host-name) 'hostname)
+ ((iburst?) 'iburst)
+ ((burst?) 'burst)
+ ((minimum-poll-interval) 'minpoll)
+ ((maximum-poll-interval) 'maxpoll)
+ (else field-name)))
+
+(define (chronyd-serialize-field field-name value)
+ (let ((field (object->string (chronyd-serialize-field-name field-name))))
+ (if (boolean? value)
+ (if value
+ #~(format #f "~a~%"
+ #$field)
+ #~"")
+ (if (string=? field "extra-content")
+ #~(string-append #$value "\n")
+ #~(format #f "~a ~a~%"
+ #$field
+ #$value)))))
+
+(define chronyd-serialize-string chronyd-serialize-field)
+(define chronyd-serialize-boolean chronyd-serialize-field)
+(define chronyd-serialize-integer chronyd-serialize-field)
+
+(define list-of-numbers? (list-of number?))
+(define-maybe list-of-numbers (prefix chronyd-))
+
+(define (chronyd-serialize-list-of-numbers field-name value)
+ (let ((field (object->string field-name)))
+ #~(string-append
+ #$field
+ " "
+ (string-join (list #$@(map object->string value)))
+ "\n")))
+
+(define-maybe string (prefix chronyd-))
+(define-maybe boolean (prefix chronyd-))
+(define-maybe integer (prefix chronyd-))
+
+(define-configuration chronyd-server
+ (host-name
+ string
+ "Hostname of the NTP server.")
+
+ (network-time-security?
+ maybe-boolean
+ "Whether to enable authentication using the Network Time Security (NTS)
mechanism.")
+
+ (iburst?
+ maybe-boolean
+ "Whether to start with a burst of 4-8 requests in order to make the first
update of the clock sooner.")
+
+ (burst?
+ maybe-boolean
+ "Whether to send a burst of up to 4 requests when chrony cannot get a good
measurement from the server.")
+
+ (minimum-poll-interval
+ maybe-integer
+ "Minimum interval between requests.")
+
+ (maximum-poll-interval
+ maybe-integer
+ "Maximum interval between requests.")
+
+ (extra-content
+ maybe-string
+ "Raw content to add to the server directive")
+
+ (prefix chronyd-))
+
+(define (chronyd-serialize-chronyd-server field-name value)
+ #~(string-append
+ #$(object->string field-name)
+ " "
+ #$(chronyd-server-host-name value)
+ " "
+ (string-map ;TODO: Use string-replace-substring here
+ (lambda (c)
+ (if (char=? c #\newline) #\space c))
+ #$(serialize-configuration value
+ (cdr
+ chronyd-server-fields)))
+ "\n"))
+
+(define (chronyd-serialize-list-of-chronyd-server field-name value)
+ #~(string-append #$@(map (cut chronyd-serialize-chronyd-server field-name <>)
+ value)))
+
+(define list-of-chronyd-server?
+ (list-of chronyd-server?))
+
+(define-configuration chronyd-configuration
+ (chrony
+ (file-like chrony)
+ "Chrony package."
+ empty-serializer)
+
+ (command-port
+ (maybe-integer 0)
+ "Port that is used for run-time monitoring.")
+
+ (drift-file
+ (maybe-string "/var/lib/chronyd/drift")
+ "File where @command{chronyd} stores rate information.")
+
+ (makestep
+ maybe-list-of-numbers
+ "Forces chrony to step the system clock if the adjustment is larger than a
threshold value.")
+
+ (synchronize-rtc?
+ maybe-boolean
+ "System time is periodically copied to the @acronym{RTC, Real Time
Clock}.")
+
+ (server
+ (list-of-chronyd-server '())
+ "NTP servers which should be used as a time source.")
+
+ (pool
+ (list-of-chronyd-server
+ (list
+ (chronyd-server
+ (host-name "2.guix.pool.ntp.org")
+ (iburst? #t))))
+ "Pool of NTP servers to connect to.")
+
+ (extra-content
+ maybe-string
+ "Raw content to add to the configuration file.")
+
+ (prefix chronyd-))
+
+(define (chronyd-config-file config)
+ (mixed-text-file "chrony.conf"
+ (serialize-configuration
+ config
+ chronyd-configuration-fields)))
+
+(define (chronyd-shepherd-service config)
+ (let ((config-file (chronyd-config-file config))
+ (chrony (chronyd-configuration-chrony config)))
+ (list (shepherd-service
+ (documentation "chrony daemon.")
+ (provision '(chronyd))
+ ;; chrony may be bound to a particular IP address, hence
+ ;; only start it after the networking service has started.
+ (requirement '(user-processes networking))
+ (actions (list (shepherd-configuration-action config-file)))
+ (start #~(make-forkexec-constructor
+ (list (string-append #$chrony "/sbin/chronyd")
+ "-F" "1" ;enable a strict system call filter.
+ "-u" "chronyd" "-d" "-f" #$config-file)))
+ (stop #~(make-kill-destructor))))))
+
+(define chronyd-account-service
+ (list (user-group (name "chronyd") (system? #t))
+ (user-account
+ (name "chronyd")
+ (group "chronyd")
+ (system? #t)
+ (comment "chronyd daemon user")
+ (home-directory "/var/empty")
+ (shell (file-append shadow "/sbin/nologin")))))
+
+(define (chronyd-service-activation config)
+ "Return the activation gexp for CONFIG."
+ (with-imported-modules (source-module-closure '((gnu build activation)))
+ #~(begin
+ (use-modules (gnu build activation))
+ (mkdir-p/perms "/var/lib/chronyd"
+ (getpw "chronyd") 488))))
+
+(define chronyd-service-type
+ (service-type (name 'chronyd)
+ (description "Run the Chrony @acronym{NTP, Network Time
Protocol} client.")
+ (extensions
+ (list (service-extension account-service-type
+ (const chronyd-account-service))
+ (service-extension shepherd-root-service-type
+ chronyd-shepherd-service)
+ (service-extension activation-service-type
+ chronyd-service-activation)))
+ (compose concatenate)
+ (default-value (chronyd-configuration))))
+
+(define (generate-chronyd-documentation)
+ (generate-documentation
+ `((chronyd-configuration
+ ,chronyd-configuration-fields
+ (server chronyd-server))
+ (chronyd-server ,chronyd-server-fields))
+ 'chronyd-configuration))
+
+
;;;
;;; OpenNTPD.
;;;
diff --git a/gnu/tests/networking.scm b/gnu/tests/networking.scm
index 8d38c3db925..c83b21f4ac1 100644
--- a/gnu/tests/networking.scm
+++ b/gnu/tests/networking.scm
@@ -41,6 +41,7 @@
#:use-module (gnu packages dns)
#:use-module (gnu packages linux)
#:use-module (gnu packages networking)
+ #:use-module (gnu packages ntp)
#:use-module (gnu packages guile)
#:use-module (gnu services shepherd)
#:use-module (ice-9 match)
@@ -52,6 +53,7 @@
%test-inetd
%test-openvswitch
%test-dhcpd
+ %test-chronyd
%test-dhcpcd
%test-dnsmasq
%test-tor
@@ -835,6 +837,77 @@ port 7, and a dict service on port 2628."
(description "Test a running dnsmasq daemon configuration.")
(value (run-dnsmasq-test))))
+
+;;;
+;;; chronyd.
+;;;
+
+(define %chronyd-os
+ (let ((base-os
+ (simple-operating-system
+ (service dhcpcd-service-type)
+ (service chronyd-service-type
+ (chronyd-configuration
+ (command-port 2342)
+ (pool
+ (list
+ (chronyd-server
+ (host-name "pool.ntp.org")
+ (iburst? #t)))))))))
+ (operating-system
+ (inherit base-os)
+ (packages
+ (append (list chrony)
+ (operating-system-packages base-os))))))
+
+(define (run-chronyd-test)
+ "Run tests in %chronyd-os with a running chronyd daemon."
+ (define os
+ (marionette-operating-system
+ %chronyd-os
+ #:imported-modules '((gnu services herd))))
+
+ (define vm
+ (virtual-machine os))
+
+ (define test
+ (with-imported-modules '((gnu build marionette))
+ #~(begin
+ (use-modules (srfi srfi-64)
+ (gnu build marionette))
+ (define marionette
+ (make-marionette (list #$vm)))
+
+ (test-runner-current (system-test-runner #$output))
+ (test-begin "chronyd")
+
+ (test-assert "service is running"
+ (marionette-eval
+ '(begin
+ (use-modules (gnu services herd))
+
+ ;; Make sure the 'chronyc' command is found.
+ (setenv "PATH" "/run/current-system/profile/bin")
+
+ (start-service 'chronyd))
+ marionette))
+
+ (test-equal "chronyd remote control works"
+ 0
+ (marionette-eval
+ '(status:exit-val
+ (system* "chronyc" "tracking"))
+ marionette))
+
+ (test-end))))
+
+ (gexp->derivation "chronyd-test" test))
+
+(define %test-chronyd
+ (system-test
+ (name "chronyd")
+ (description "Test that the chronyd works.")
+ (value (run-chronyd-test))))
;;;