1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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))))