(define-module (ryan-services networking) #:use-module (guix gexp) #:use-module (guix records) #:use-module (ryan-packages networking) #:use-module (gnu packages linux) #:use-module (gnu packages dns) #:use-module (gnu packages base) #:use-module (gnu services) #:use-module (gnu services admin) #:use-module (gnu services configuration) #:use-module (gnu services shepherd) #:export (netbird-configuration netbird-service-type)) (define-configuration netbird-configuration (netbird (file-like netbird-bin) "The netbird package to use") (iptables (file-like iptables-nft) "The iptables implementation to use") (dns-manager (file-like openresolv) "Resolv.conf manager") (log-file (string "/var/log/netbird.log") "Path to logs") (socket (string "/var/run/netbird.sock") "Path of UNIX socket") (verbosity (string "warning") "Log verbosity. Default is 'warning'") (extra-options (list-of-strings '()) "List of extra options") (no-serialization)) (define netbird-shepherd-service (match-record-lambda (netbird iptables dns-manager log-file socket verbosity extra-options) (let ((environment #~(list (string-append "PATH=" (string-join '(#$(file-append iptables "/sbin") #$(file-append iproute "/sbin") #$(file-append dns-manager "/sbin") #$(file-append coreutils "/bin")) ":"))))) (list (shepherd-service (documentation "Run netbird") (provision '(netbird)) (requirement '(user-processes)) (start #~(make-forkexec-constructor (list #$(file-append netbird "/bin/netbird") "service" "run" "--log-level" #$verbosity "--daemon-addr" (string-append "unix://" #$socket) "--log-file" "console" #$@extra-options) #:environment-variables #$environment #:log-file #$log-file)) (stop #~(make-kill-destructor))))))) (define netbird-service-type (service-type (name 'netbird) (extensions (list (service-extension shepherd-root-service-type netbird-shepherd-service) (service-extension profile-service-type (compose list netbird-configuration-netbird)) (service-extension log-rotation-service-type (compose list netbird-configuration-log-file)))) (default-value (netbird-configuration)) (description "Run netbird.")))