modules/ryan-services/networking.scm
49288569e3b246135b034acf2c23cc276c0b7204
· 2.7 KB · 84 lines
raw
| 1 | (define-module (ryan-services networking) |
| 2 | #:use-module (guix gexp) |
| 3 | #:use-module (guix records) |
| 4 | #:use-module (ryan-packages networking) |
| 5 | #:use-module (gnu packages linux) |
| 6 | #:use-module (gnu packages dns) |
| 7 | #:use-module (gnu packages base) |
| 8 | #:use-module (gnu services) |
| 9 | #:use-module (gnu services admin) |
| 10 | #:use-module (gnu services configuration) |
| 11 | #:use-module (gnu services shepherd) |
| 12 | #:export (netbird-configuration |
| 13 | netbird-service-type)) |
| 14 | |
| 15 | (define-configuration netbird-configuration |
| 16 | (netbird |
| 17 | (file-like netbird-bin) |
| 18 | "The netbird package to use") |
| 19 | |
| 20 | (iptables |
| 21 | (file-like iptables-nft) |
| 22 | "The iptables implementation to use") |
| 23 | |
| 24 | (dns-manager |
| 25 | (file-like openresolv) |
| 26 | "Resolv.conf manager") |
| 27 | |
| 28 | (log-file |
| 29 | (string "/var/log/netbird.log") |
| 30 | "Path to logs") |
| 31 | |
| 32 | (socket |
| 33 | (string "/var/run/netbird.sock") |
| 34 | "Path of UNIX socket") |
| 35 | |
| 36 | (verbosity |
| 37 | (string "warning") |
| 38 | "Log verbosity. Default is 'warning'") |
| 39 | |
| 40 | (extra-options |
| 41 | (list-of-strings '()) |
| 42 | "List of extra options") |
| 43 | (no-serialization)) |
| 44 | |
| 45 | (define netbird-shepherd-service |
| 46 | (match-record-lambda <netbird-configuration> |
| 47 | (netbird iptables dns-manager log-file socket verbosity extra-options) |
| 48 | (let ((environment |
| 49 | #~(list (string-append "PATH=" |
| 50 | (string-join |
| 51 | '(#$(file-append iptables "/sbin") |
| 52 | #$(file-append iproute "/sbin") |
| 53 | #$(file-append dns-manager "/sbin") |
| 54 | #$(file-append coreutils "/bin")) |
| 55 | ":"))))) |
| 56 | (list (shepherd-service |
| 57 | (documentation "Run netbird") |
| 58 | (provision '(netbird)) |
| 59 | (requirement '(user-processes)) |
| 60 | (start |
| 61 | #~(make-forkexec-constructor |
| 62 | (list |
| 63 | #$(file-append netbird "/bin/netbird") |
| 64 | "service" "run" |
| 65 | "--log-level" #$verbosity |
| 66 | "--daemon-addr" (string-append "unix://" #$socket) |
| 67 | "--log-file" "console" |
| 68 | #$@extra-options) |
| 69 | #:environment-variables #$environment |
| 70 | #:log-file #$log-file)) |
| 71 | (stop #~(make-kill-destructor))))))) |
| 72 | |
| 73 | (define netbird-service-type |
| 74 | (service-type |
| 75 | (name 'netbird) |
| 76 | (extensions |
| 77 | (list (service-extension shepherd-root-service-type |
| 78 | netbird-shepherd-service) |
| 79 | (service-extension profile-service-type |
| 80 | (compose list netbird-configuration-netbird)) |
| 81 | (service-extension log-rotation-service-type |
| 82 | (compose list netbird-configuration-log-file)))) |
| 83 | (default-value (netbird-configuration)) |
| 84 | (description "Run netbird."))) |