summaryrefslogtreecommitdiff
path: root/modules/ryan-services/networking.scm
blob: 9fd15bd3d7e4076fe23a323751c9543666fa9ca7 (plain)
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
(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.")))