From 27a74de2721b2a55611dab408dedc3718a50e12e Mon Sep 17 00:00:00 2001 From: Rutherther Date: Sat, 8 Aug 2026 19:24:50 +0200 Subject: [PATCH] feat: add netbird package and service --- modules/ruther/packages/netbird.scm | 142 ++++++++++++++++++++++++++++ modules/ruther/services/netbird.scm | 41 ++++++++ 2 files changed, 183 insertions(+) create mode 100644 modules/ruther/packages/netbird.scm create mode 100644 modules/ruther/services/netbird.scm diff --git a/modules/ruther/packages/netbird.scm b/modules/ruther/packages/netbird.scm new file mode 100644 index 0000000000000000000000000000000000000000..00c5a44aa17f81e64d03468e780d59dc8cccc758 --- /dev/null +++ b/modules/ruther/packages/netbird.scm @@ -0,0 +1,142 @@ +;; Based on the netbird package from the Renaissance Guix channel: +;; https://codeberg.org/joshuablais/renaissance/src/commit/7153b914be1c2f71616e3f13ebdce0245e7395fc/renaissance/packages/netbird.scm +(define-module (ruther packages netbird) + #:use-module (guix packages) + #:use-module (guix git-download) + #:use-module (guix gexp) + #:use-module (guix build-system go) + #:use-module ((guix licenses) #:prefix license:) + #:use-module (gnu packages golang) + #:use-module (gnu packages version-control) + #:use-module (gnu packages nss) + #:use-module (gnu packages vpn) + #:use-module (gnu packages linux)) + +(define %netbird-version "0.76.1") + +(define %netbird-source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/netbirdio/netbird") + (commit (string-append "v" %netbird-version)))) + (file-name (git-file-name "netbird" %netbird-version)) + (sha256 + (base32 "09r1lvx9k2y6919bm4xngjhxr6mwmcyxfbc1q4ychzrn4ka1n5w3")))) + +(define (netbird-go-modules version source) + (computed-file + (string-append "netbird-go-modules-" version) + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils)) + (setenv "PATH" + (string-append #$(file-append go-1.26 "/bin") ":" + #$(file-append git-minimal "/bin") ":" + (getenv "PATH"))) + (setenv "SSL_CERT_FILE" + (string-append #$nss-certs + "/etc/ssl/certs/ca-certificates.crt")) + (setenv "SSL_CERT_DIR" + (string-append #$nss-certs "/etc/ssl/certs")) + (let ((cache (string-append (getcwd) "/gomodcache"))) + (setenv "GOPATH" (string-append (getcwd) "/go")) + (setenv "GOMODCACHE" cache) + (setenv "GOCACHE" (string-append (getcwd) "/gocache")) + (setenv "GOSUMDB" "off") + (setenv "GOFLAGS" "-mod=mod") + (setenv "GOTELEMETRY" "off") + (setenv "GOTOOLCHAIN" "local") + + (copy-recursively #$source "src") + (for-each (lambda (f) (chmod f #o644)) + (find-files "src" #:directories? #f)) + (for-each (lambda (d) (chmod d #o755)) + (find-files "src" #:directories? #t)) + + (with-directory-excursion "src" + (invoke "go" "mod" "download" "all")) + + (for-each (lambda (d) (chmod d #o755)) + (find-files cache #:directories? #t)) + (for-each (lambda (f) (chmod f #o644)) + (find-files cache #:directories? #f)) + + (when (file-exists? (string-append cache "/cache/lock")) + (delete-file (string-append cache "/cache/lock"))) + (when (file-exists? (string-append cache "/cache/download/sumdb")) + (delete-file-recursively + (string-append cache "/cache/download/sumdb"))) + (for-each delete-file (find-files cache "\\.lock$")) + + (copy-recursively cache #$output)))) + #:local-build? #f + #:options + (list #:hash-algo 'sha256 + #:hash (base32 "0g0j80mgvl9jg2iz06g2zcxnl5ycklkddjw4z923s0hzgyb5pv0s") + #:recursive? #t))) + +(define-public netbird + (package + (name "netbird") + (version %netbird-version) + (source %netbird-source) + (build-system go-build-system) + (arguments + (list + #:go go-1.26 + #:import-path "github.com/netbirdio/netbird" + #:install-source? #f + #:tests? #f + #:phases + #~(modify-phases %standard-phases + (add-after 'unpack 'set-module-cache + (lambda _ + (let ((cache "/tmp/gomodcache")) + (mkdir-p cache) + (copy-recursively + #$(netbird-go-modules %netbird-version %netbird-source) + cache) + (for-each (lambda (d) (chmod d #o755)) + (find-files cache #:directories? #t)) + (for-each (lambda (f) (chmod f #o644)) + (find-files cache #:directories? #f)) + (setenv "GO111MODULE" "on") + (setenv "GOMODCACHE" cache) + (setenv "GOFLAGS" "-mod=mod") + (setenv "GOSUMDB" "off") + (setenv "GOPROXY" "off") + (setenv "GOTOOLCHAIN" "local") + (let ((gosum "src/github.com/netbirdio/netbird/go.sum")) + (when (file-exists? gosum) (chmod gosum #o644)))))) + (replace 'build + (lambda _ + (with-directory-excursion + "src/github.com/netbirdio/netbird" + (for-each + (lambda (pair) + (let ((pkg (car pair)) + (bin (cdr pair))) + (format #t "building ~a~%" bin) + (invoke "go" "build" + "-ldflags" + (string-append + "-X github.com/netbirdio/netbird/version.version=v" + #$version " -s -w") + "-o" (string-append #$output "/bin/" bin) + (string-append + "github.com/netbirdio/netbird/" pkg)))) + '(("client" . "netbird") + ("signal" . "netbird-signal") + ("management" . "netbird-management") + ("relay" . "netbird-relay")))))) + (delete 'install) + (delete 'check)))) + (inputs (list wireguard-tools)) + (native-inputs (list git-minimal)) + (home-page "https://netbird.io") + (synopsis "WireGuard-based mesh networking") + (description + "NetBird combines WireGuard with a control plane for zero-config +peer-to-peer mesh networking.") + (license (list license:bsd-3 license:agpl3)))) diff --git a/modules/ruther/services/netbird.scm b/modules/ruther/services/netbird.scm new file mode 100644 index 0000000000000000000000000000000000000000..b51b83f14cf90c91739a9dde18b27ea9d97f24c9 --- /dev/null +++ b/modules/ruther/services/netbird.scm @@ -0,0 +1,41 @@ +(define-module (ruther services netbird) + #:use-module (gnu services) + #:use-module (gnu services shepherd) + #:use-module (gnu services configuration) + #:use-module (guix gexp) + #:use-module (guix records) + #:use-module (ruther packages netbird) + #:export (netbird-configuration + netbird-configuration? + netbird-configuration-netbird + netbird-configuration-log-level + + netbird-service-type)) + +(define-configuration/no-serialization netbird-configuration + (netbird (file-like netbird) "The netbird package to use.") + (log-level (string "info") "Log level.")) + +(define (netbird-shepherd-service config) + (let ((netbird (netbird-configuration-netbird config)) + (log-level (netbird-configuration-log-level config))) + (list + (shepherd-service + (provision '(netbird)) + (requirement '(networking)) + (documentation "Run the NetBird client daemon.") + (start #~(make-forkexec-constructor + (list #$(file-append netbird "/bin/netbird") + "service" "run" + "--log-level" #$log-level) + #:log-file "/var/log/netbird.log")) + (stop #~(make-kill-destructor)))))) + +(define netbird-service-type + (service-type + (name 'netbird) + (extensions + (list (service-extension shepherd-root-service-type + netbird-shepherd-service))) + (default-value (netbird-configuration)) + (description "Run the NetBird VPN client daemon.")))