aboutsummaryrefslogtreecommitdiff
path: root/battering/packages/opensnitch.scm
blob: 97744fee4312722fcdd29fe522b8e9bc055825f3 (plain) (blame)
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
(define-module (battering packages opensnitch)
  #:use-module (guix packages)
  #:use-module (guix git-download)
  #:use-module (guix gexp)
  #:use-module (guix utils)
  #:use-module (guix build-system go)
  #:use-module (guix build-system python)
  #:use-module (guix build-system gnu)
  #:use-module (gnu packages algebra)
  #:use-module (gnu packages base)
  #:use-module (gnu packages bison)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages elf)
  #:use-module (gnu packages flex)
  #:use-module (gnu packages golang)
  #:use-module (gnu packages golang-build)
  #:use-module (gnu packages golang-web)
  #:use-module (gnu packages golang-xyz)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages llvm)
  #:use-module (gnu packages qt)
  #:use-module (gnu packages rpc)
  #:use-module (gnu packages tls)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages protobuf)
  #:use-module (gnu packages python-build)
  #:use-module (gnu packages python-web)
  #:use-module (gnu packages python-xyz)
  #:use-module (battering packages golang-xyz)
  #:use-module (battering packages python-xyz)
  #:use-module ((guix licenses)
                #:prefix license:))

(define-public opensnitch
  (package
    (name "opensnitch")
    (version "1.6.7")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/evilsocket/opensnitch/")
                    (commit (string-append "v" version))))
              (file-name (git-file-name name version))
              (sha256
               (base32 "0990hdc3vn50axyz21v11gwkc2svlwf9wlnf03lwxgnm2q4ha76q"))))
    (build-system python-build-system)
    (arguments
     (list
      #:phases #~(modify-phases %standard-phases
                   (add-after 'unpack 'make-proto-definitions
                     (lambda _
                       (with-directory-excursion "proto/"
                         (invoke "make" "../ui/opensnitch/ui_pb2.py"))))
                   (add-after 'make-proto-definitions 'chdir
                     (lambda _
                       (chdir "ui")))
                   (add-after 'chdir 'patch-setup.py
                     (lambda _
                       (substitute* "setup.py"
                         (("/usr/") ""))))
                   (add-after 'chdir 'generate-resources
                     (lambda _
                       ;; Patch resource script
                       (substitute* "i18n/generate_i18n.sh"
                         (("/bin/sh")
                          (which "sh")))
                       ;; Remove calls to pip in Makefile
                       (substitute* "Makefile"
                         (("@pip3.*$") ""))
                       (invoke "make" "opensnitch/resources_rc.py"))))))
    (inputs (list python-grpcio-tools
                  python-pyinotify
                  python-slugify
                  python-pyqt
                  python-protobuf
                  python-notify2
                  python-qt-material))
    (native-inputs (list python-setuptools qttools-5))
    (home-page "https://github.com/evilsocket/opensnitch/")
    (synopsis "GNU/Linux application firewall.")
    (description "OpenSnitch is an interactive GNU/Linux application firewall inspired by Little Snitch.")
    (license license:gpl3+)))

(define linux-libre-headers-opensnitch
  (package
    (inherit linux-libre-headers)
    (name "linux-libre-headers-opensnitch")
    (native-inputs (modify-inputs (package-native-inputs linux-libre-headers)
                     (append openssl bc elfutils)))
    (arguments
     (substitute-keyword-arguments (package-arguments linux-libre-headers-latest)
       ((#:phases p)
        #~(modify-phases #$p
            (replace 'build
              (lambda _
                (invoke "make" "defconfig")
                (invoke "make" "prepare")))
            (replace 'install
              (lambda _
                (begin
                  (copy-recursively "." #$output))))))
       ((#:allowed-references _) #f)))))

(define-public opensnitch-ebpf-module
  (package
    (name "opensnitch-ebpf-module")
    (version "1.6.7")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/evilsocket/opensnitch/")
                    (commit (string-append "v" version))))
              (file-name (git-file-name name version))
              (sha256
               (base32 "0990hdc3vn50axyz21v11gwkc2svlwf9wlnf03lwxgnm2q4ha76q"))))
    (build-system gnu-build-system)
    (inputs (list linux-libre linux-libre-headers))
    (native-inputs (list clang tar zstd flex bison))
    (arguments
     (list
      ;; TODO: make it buildable against any kernel?
      #:make-flags #~(list (format #f "KERNEL_DIR=~a" #$linux-libre-headers-opensnitch))
      #:tests? #f
      #:phases #~(modify-phases %standard-phases
                   (add-after 'unpack 'chdir
                     (lambda _
                       (chdir "ebpf_prog/")))
                   (delete 'configure)
                   (replace 'install
                     (lambda _
                       (let ((lib (string-append #$output "/lib")))
                         (install-file "opensnitch-dns.o" lib)
                         (install-file "opensnitch-procs.o" lib)
                         (install-file "opensnitch.o" lib)))))))
    (home-page "https://github.com/evilsocket/opensnitch/")
    (synopsis "eBPF module for Opensnitch")
    (description "This package provides an additional module that allows
Opensnitch to monitor traffic via eBPF rules.")
    (license license:gpl3+)))

(define-public go-github-com-evilsocket-opensnitch-daemon
  (package
    (name "go-github-com-evilsocket-opensnitch-daemon")
    (version "1.6.7")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/evilsocket/opensnitch/")
                    (commit (string-append "v" version))))
              (file-name (git-file-name name version))
              (sha256
               (base32 "0990hdc3vn50axyz21v11gwkc2svlwf9wlnf03lwxgnm2q4ha76q"))))
    (build-system go-build-system)
    (arguments
     (list
      #:go go-1.23
      #:import-path "github.com/evilsocket/opensnitch/daemon"
      #:unpack-path "github.com/evilsocket/opensnitch"
      #:tests? #f
      #:phases #~(modify-phases %standard-phases
                   (add-before 'build 'make-proto-definitions
                     (lambda* (#:key unpack-path #:allow-other-keys)
                       (with-directory-excursion (format #f "src/~a/proto/" unpack-path)
                         (invoke "make" "../daemon/ui/protocol/ui.pb.go"))))
                   (add-before 'build 'replace-ebpf-path
                     (lambda* (#:key tests? import-path #:allow-other-keys)
                       (with-directory-excursion (format #f "src/~a/" import-path)
                         (substitute* "core/ebpf.go"
                           (("/usr")
                            #$opensnitch-ebpf-module)
                           (("modulesDir = .*$")
                            "modulesDir = \"\"\n")))))
                   (add-before 'check 'delete-buggy-test-data
                     (lambda* (#:key tests? import-path #:allow-other-keys)
                       (when tests?
                         (delete-file
                          (string-append
                           "src/" import-path "/ui/testdata/default-config.json"))))))))
    (inputs (list go-google-golang-org-grpc
                  go-golang-org-x-sys
                  go-golang-org-x-net
                  go-github-com-vishvananda-netns
                  go-github-com-vishvananda-netlink
                  go-github-com-varlink-go
                  go-github-com-iovisor-gobpf
                  go-github-com-google-uuid
                  go-github-com-google-nftables
                  go-github-com-google-gopacket
                  go-github-com-golang-protobuf
                  go-github-com-fsnotify-fsnotify
                  libnetfilter-queue
                  libnfnetlink
                  opensnitch-ebpf-module))
    (native-inputs (list protobuf protoc-gen-go
                         go-google-golang-org-grpc-cmd-protoc-gen-go-grpc
                         pkg-config))
    (home-page "https://github.com/evilsocket/opensnitch")
    (synopsis "GNU/Linux application firewall.")
    (description "OpenSnitch is an interactive GNU/Linux application firewall inspired by Little Snitch.")
    (license license:gpl3)))