1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 fetchpatch,
7 installShellFiles,
8
9 # build-system
10 setuptools,
11 versioneer,
12
13 # dependencies
14 attrs,
15 autobahn,
16 automat,
17 click,
18 cryptography,
19 humanize,
20 iterable-io,
21 pynacl,
22 qrcode,
23 spake2,
24 tqdm,
25 twisted,
26 txtorcon,
27 zipstream-ng,
28
29 # optional-dependencies
30 noiseprotocol,
31
32 # tests
33 net-tools,
34 unixtools,
35 magic-wormhole-transit-relay,
36 magic-wormhole-mailbox-server,
37 pytestCheckHook,
38 pytest-twisted,
39
40 gitUpdater,
41}:
42
43buildPythonPackage rec {
44 pname = "magic-wormhole";
45 version = "0.20.0";
46 pyproject = true;
47
48 src = fetchFromGitHub {
49 owner = "magic-wormhole";
50 repo = "magic-wormhole";
51 tag = version;
52 hash = "sha256-YjzdznZZ/0YTU83f3jlOr6+yOWQ++R1wU9IZDrfAMpo=";
53 };
54
55 patches = [
56 # TODO: drop when updating beyond version 0.20.0
57 (fetchpatch {
58 name = "SubchannelDemultiplex._pending_opens-fix-type.patch";
59 url = "https://github.com/magic-wormhole/magic-wormhole/commit/6d7f48786b5506df5b6a254bc4e37f6bf5d75593.patch";
60 hash = "sha256-28YH3enyQ9rTT56OU7FfFonb9l8beJ9QRgPoItzrgu4=";
61 })
62 ];
63
64 postPatch =
65 # enable tests by fixing the location of the wormhole binary
66 ''
67 substituteInPlace src/wormhole/test/test_cli.py --replace-fail \
68 'locations = procutils.which("wormhole")' \
69 'return "${placeholder "out"}/bin/wormhole"'
70 ''
71 # fix the location of the ifconfig binary
72 + lib.optionalString stdenv.hostPlatform.isLinux ''
73 sed -i -e "s|'ifconfig'|'${net-tools}/bin/ifconfig'|" src/wormhole/ipaddrs.py
74 '';
75
76 build-system = [
77 setuptools
78 versioneer
79 ];
80
81 dependencies = [
82 attrs
83 autobahn
84 automat
85 click
86 cryptography
87 humanize
88 iterable-io
89 pynacl
90 qrcode
91 spake2
92 tqdm
93 twisted
94 txtorcon
95 zipstream-ng
96 ]
97 ++ autobahn.optional-dependencies.twisted
98 ++ twisted.optional-dependencies.tls;
99
100 optional-dependencies = {
101 dilation = [ noiseprotocol ];
102 };
103
104 nativeBuildInputs = [
105 installShellFiles
106 ];
107
108 nativeCheckInputs = [
109 magic-wormhole-mailbox-server
110 magic-wormhole-transit-relay
111 pytestCheckHook
112 pytest-twisted
113 ]
114 ++ optional-dependencies.dilation
115 ++ lib.optionals stdenv.hostPlatform.isDarwin [ unixtools.locale ];
116
117 __darwinAllowLocalNetworking = true;
118
119 postInstall = ''
120 install -Dm644 docs/wormhole.1 $out/share/man/man1/wormhole.1
121
122 # https://github.com/magic-wormhole/magic-wormhole/issues/619
123 installShellCompletion --cmd ${meta.mainProgram} \
124 --bash wormhole_complete.bash \
125 --fish wormhole_complete.fish \
126 --zsh wormhole_complete.zsh
127 rm $out/wormhole_complete.*
128 '';
129
130 passthru.updateScript = gitUpdater { };
131
132 meta = {
133 changelog = "https://github.com/magic-wormhole/magic-wormhole/blob/${version}/NEWS.md";
134 description = "Securely transfer data between computers";
135 homepage = "https://magic-wormhole.readthedocs.io/";
136 license = lib.licenses.mit;
137 maintainers = [ lib.maintainers.mjoerg ];
138 mainProgram = "wormhole";
139 };
140}