Netbird service

69df0e16e7be… · Ryan Schanzenbacher ·

parent 5855a0331c0d… diff

Changed files

diff --git a/modules/ryan-config/base-system.scm b/modules/ryan-config/base-system.scm
index e4e7f90..e1cf87b 100644
--- a/modules/ryan-config/base-system.scm
+++ b/modules/ryan-config/base-system.scm
@@ -29,6 +29,7 @@
#:use-module (gnu services xorg)
#:use-module (gnu services ssh)
#:use-module (ryan-services nix)
+ #:use-module (ryan-services networking)
#:use-module (gnu services sound)
#:use-module (gnu services docker)
#:use-module (gnu services avahi)
@@ -191,6 +192,7 @@
(service tailscale-service-type
(tailscale-configuration
(socket "/var/run/tailscale/tailscaled.sock")))
+ (service netbird-service-type)
(service containerd-service-type)
(service nix-service-type
(nix-configuration
diff --git a/modules/ryan-services/networking.scm b/modules/ryan-services/networking.scm
new file mode 100644
index 0000000..9fd15bd
--- /dev/null
+++ b/modules/ryan-services/networking.scm
@@ -0,0 +1,84 @@
+(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-configuration>
+ (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.")))