summaryrefslogtreecommitdiff
path: root/guix.scm
blob: 38a673d65d3cfea520f017476505b306b93d6763 (about) (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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
;; SPDX-License-Identifier: CC0-1.0

;; Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org>
;;
;; Available under the terms of Creative Commons Zero v1.0 Universal.

(use-modules
 (guix packages)
 (guix download)
 (guix git-download)
 (guix build-system python)
 (guix gexp)
 ((guix licenses) #:prefix license:)
 (gnu packages python-build)
 (gnu packages python-xyz)
 (gnu packages python-crypto)
 (gnu packages compression)
 (gnu packages python-compression)
 (gnu packages xdisorg)
 (gnu packages serialization)
 (gnu packages protobuf)
 (gnu packages python-web)
 (gnu packages check)
 (gnu packages sphinx)
 (gnu packages python-check)
 (gnu packages license)
 (gnu packages gnupg))

(define %source-dir (dirname (current-filename)))

(define-public python-kaitaistruct
  (package
    (name "python-kaitaistruct")
    (version "0.10")
    (source
     (origin
       (method url-fetch)
       (uri (pypi-uri "kaitaistruct" version))
       (sha256
        (base32 "0ap5ka51gnc2mc4s1kqqsi6nb6zqv8wsrg17ryxazmkkj7idwi50"))))
    (build-system python-build-system)
    (home-page "https://kaitai.io")
    (native-inputs (list python-wheel))
    (synopsis
     "Declarative parser generator for binary data: runtime library for Python")
    (description
     "Kaitai Struct is a declarative language used for describing various binary
data structures, laid out in files or in memory - i.e. binary file formats,
network stream packet formats, etc.")
    (license license:expat)))

(define-public python-parver
  (package
    (name "python-parver")
    (version "0.3.1")
    (source
      (origin
        (method url-fetch)
        (uri (pypi-uri "parver" version))
        (sha256
          (base32 "1lyzqp8bz0n2kzabzl7k7g7cn90rlnrxjzva2p62gsfc7djy00n9"))))
    (build-system python-build-system)
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'relax-requirements
           (lambda _
             (substitute* "setup.py"
                          (("arpeggio[^']*") "arpeggio"))))
         (replace 'check
           (lambda* (#:key tests? #:allow-other-keys)
             (when tests?
               (invoke "pytest")))))))
    (propagated-inputs (list python-arpeggio python-attrs python-six))
    (native-inputs
      (list python-hypothesis
            python-pretend
            python-pytest))
    (home-page "https://github.com/RazerM/parver")
    (synopsis "Parse and manipulate version numbers")
    (description "Parver facilitates parsing and manipulation of
@url{https://www.python.org/dev/peps/pep-0440/,PEP 440} version numbers.")
    (license license:expat)))

(define-public python-pyopenssl-for-mitmproxy
  (let ((base python-pyopenssl))
    (package
      (inherit base)
      (version "22.0.0")
      (source
       (origin
         (inherit (package-source base))
         (uri (pypi-uri "pyOpenSSL" version))
         (sha256
          (base32
           "1gzihw09sqi71lwx97c69hab7w4rbnl6hhfrl6za3i5a4la1n2v6"))))
      (propagated-inputs
       (modify-inputs (package-propagated-inputs base)
         (replace "python-cryptography" python-cryptography-next))))))

(define-public python-urllib3-for-mitmproxy
  (let ((base python-urllib3))
    (package
      (inherit base)
      (propagated-inputs
       (modify-inputs (package-propagated-inputs base)
         (replace "python-cryptography" python-cryptography-next)
         (replace "python-pyopenssl" python-pyopenssl-for-mitmproxy))))))

(define-public python-requests-for-mitmproxy
  (let ((base python-requests))
    (package
      (inherit base)
      (propagated-inputs
       (modify-inputs (package-propagated-inputs base)
         (replace "python-urllib3" python-urllib3-for-mitmproxy))))))

(define-public python-werkzeug-for-mitmproxy
  (let ((base python-werkzeug))
    (package
      (inherit base)
      (propagated-inputs
       (modify-inputs (package-propagated-inputs base)
         (replace "python-requests" python-requests-for-mitmproxy))))))

(define-public python-flask-for-mitmproxy
  (let ((base python-flask))
    (package
      (inherit base)
      (propagated-inputs
       (modify-inputs (package-propagated-inputs base)
         (replace "python-werkzeug" python-werkzeug-for-mitmproxy))))))

(define-public mitmproxy
  (package
    (name "mitmproxy")
    (version "8.1.1")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://github.com/mitmproxy/mitmproxy")
             (commit (string-append "v" version))))
       (sha256
        (base32 "0kpzk8ci02vyjg9nqnpnadmgyaxxrpdydgfnm2xmxf1s4rzdcvwx"))
       (snippet
        '(begin
           ;; The player contains some minified JS. It would be possible to find
           ;; player sources elsewhere on the internet but there's no point in
           ;; doing do since we're not building the docs anyway.
           (delete-file "docs/src/assets/asciinema-player.js")
           #t))))
    (build-system python-build-system)
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'relax-requirements
           (lambda _
             (substitute* "setup.py"
               (("kaitaistruct>=0\\.7[^\"]*") "kaitaistruct")
               ;; The ">=2.8" req was there because older ldap3 lacked a crucial
               ;; ">=0.4.8" req for its dep, pyasn. It's not an issue for Guix
               ;; which ships with pyasn 4.8 anyway.
               (("ldap3>=2\\.8[^\"]*") "ldap3")
               (("protobuf>=3\\.14,<5") "protobuf")
               (("sortedcontainers>=2\\.3[^\"]*") "sortedcontainers")
               (("wsproto>=1\\.0[^\"]*") "wsproto")
               (("pytest-timeout[^\"]*<2[^\"]*") "pytest-timeout")
               (("pytest-asyncio[^\"]*<0.14[^\"]*") "pytest-asyncio"))
             (substitute* "test/mitmproxy/proxy/layers/http/test_http.py"
               (("isinstance\\(x, HTTPFlow\\)")
                "issubclass(type(x), HTTPFlow)"))))
         (replace 'check
           (lambda* (#:key tests? inputs outputs #:allow-other-keys)
             (when tests?
               (setenv "HOME" "/tmp")
               (invoke "pytest" "--timeout" "60")))))))
    (propagated-inputs
     (list python-asgiref
           python-blinker
           python-brotli
           python-cryptography-next
           python-flask-for-mitmproxy
           python-h11
           python-h2
           python-hyperframe
           python-kaitaistruct
           python-ldap3
           python-msgpack
           python-passlib
           python-protobuf
           python-pyopenssl-for-mitmproxy
           python-pyparsing
           python-pyperclip
           python-ruamel.yaml
           python-sortedcontainers
           python-tornado-6
           python-urwid
           python-wsproto
           python-publicsuffix2
           python-zstandard))
    (native-inputs
     (list python-parver
           python-pytest
           python-pytest-asyncio
           python-pytest-timeout))
    (home-page "https://mitmproxy.org/")
    (synopsis "A free interactive HTTPS proxy")
    (description
     "An interactive TLS-capable intercepting HTTP proxy for penetration testers
and software developers.  It can be used to intercept, inspect, modify and
replay web traffic such as HTTP/1, HTTP/2, WebSockets, or any other
SSL/TLS-protected protocols.")
    (license license:expat)))

(define-public python-immutables-for-haketilo
  (let ((base python-immutables))
    (package
      (inherit base)
      (version "0.19")
      (source
       (origin
         ;; Old version tarballs seem to be getting deleted from PyPI each time a
         ;; new version comes out.
         (method git-fetch)
         (uri (git-reference
               (url "https://github.com/MagicStack/immutables")
               (commit (string-append "v" version))))
         (sha256
          (base32
           "1awjylp4pl0jknwgnabg7kkj8f8883fkf99spsdrw1pj1acajvy9"))))
      (arguments
       `(#:phases
         (modify-phases %standard-phases
           (add-after 'unpack 'fix-expected-mypy-types
             (lambda _
               (substitute* "tests/test-data/check-immu.test"
                 (("builtins.str") "builtins.str*"))))
           (replace 'check
             (lambda* (#:key tests? #:allow-other-keys)
               (when tests?
                 (invoke "pytest")))))))
      (native-inputs
       (list python-pytest python-mypy)))))

(define-public python-types-requests
  (package
    (name "python-types-requests")
    (version "2.26.0")
    (source (origin
              (method url-fetch)
              (uri (pypi-uri "types-requests" version))
              (sha256
               (base32
                "10sq8jarr642vhw53k6zbf3hn2b8xfyrckwfngml4fj19g1whpnz"))))
    (build-system python-build-system)
    (home-page "https://github.com/python/typeshed")
    (synopsis "Typing stubs for requests")
    (description
     "This package provides a collection of library stubs for Python, with
static types.")
    (license license:asl2.0)))

;; WARNING! Haketilo package is not ready for building yet. The definition below
;; is only useful for setting up a development environment with
;; `guix shell -D -f guix.scm`. The package will be updated to build properly
;; somewhere in the future.
(define-public haketilo
  (package
    (name "haketilo")
    (version "git")
    (source (local-file %source-dir
                        #:recursive? #t
                        #:select? (git-predicate %source-dir)))
    (build-system python-build-system)
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (replace 'check
           (lambda* (#:key tests? #:allow-other-keys)
             (when tests?
               (invoke "pytest")))))))
    (propagated-inputs
      (list mitmproxy
            reuse
            python-beautifulsoup4
            python-html5lib
            python-immutables-for-haketilo
            python-jsonschema
            python-gnupg))
    (native-inputs
      (list python-setuptools-scm
            python-babel
            python-pytest
            python-pypa-build
            python-mypy
            python-types-requests))
    (home-page "https://hydrillabugs.koszko.org/projects/haketilo/wiki")
    (synopsis "Block JavaScript and add custom logic to web pages")
    (description "Haketilo HTTP proxy facilitates viewing of websites while
having their original JavaScript replaced by user-provided scripts. Haketilo
combines the functionalities of content blocker and user script manager. It can
be used with its script repository, Hydrilla.")
    (license (list license:agpl3+ license:gpl3+ license:cc0))))

haketilo