;; 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))))