1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 gobject-introspection,
6 apt,
7 iproute2,
8 setuptools,
9 networkmanager,
10 proton-core,
11 proton-vpn-api-core,
12 proton-vpn-local-agent,
13 pycairo,
14 pygobject3,
15 pyxdg,
16 pytest-asyncio,
17 pytestCheckHook,
18 pytest-cov-stub,
19}:
20
21buildPythonPackage rec {
22 pname = "proton-vpn-network-manager";
23 version = "0.12.14";
24 pyproject = true;
25
26 src = fetchFromGitHub {
27 owner = "ProtonVPN";
28 repo = "python-proton-vpn-network-manager";
29 tag = "v${version}";
30 hash = "sha256-flZeEdmGXsSFHtlm6HrBtuwOcYJFjWmkMvGgnHL4cPw=";
31 };
32
33 nativeBuildInputs = [
34 # Needed to recognize the NM namespace
35 gobject-introspection
36 ];
37
38 build-system = [
39 setuptools
40 ];
41
42 dependencies = [
43 # Needed here for the NM namespace
44 networkmanager
45 proton-core
46 proton-vpn-api-core
47 proton-vpn-local-agent
48 pycairo
49 pygobject3
50 pyxdg
51 ];
52
53 postPatch = ''
54 substituteInPlace proton/vpn/backend/linux/networkmanager/killswitch/wireguard/killswitch_connection_handler.py \
55 --replace '/usr/sbin/ip' '${iproute2}/bin/ip'
56 substituteInPlace proton/vpn/backend/linux/networkmanager/killswitch/wireguard/wgkillswitch.py \
57 --replace '/usr/bin/apt' '${apt}/bin/apt'
58 '';
59
60 pythonImportsCheck = [
61 "proton.vpn.backend.linux.networkmanager"
62 "proton.vpn.backend.linux.networkmanager.killswitch.default"
63 "proton.vpn.backend.linux.networkmanager.killswitch.wireguard"
64 ];
65
66 nativeCheckInputs = [
67 pytestCheckHook
68 pytest-cov-stub
69 pytest-asyncio
70 ];
71
72 # Needed for `pythonImportsCheck`, `preCheck` happens between `pythonImportsCheckPhase` and `pytestCheckPhase`.
73 preCheck = ''
74 # Needed for Permission denied: '/homeless-shelter'
75 export HOME=$(mktemp -d)
76 export XDG_RUNTIME_DIR=$(mktemp -d)
77 '';
78
79 meta = {
80 description = "Provides the necessary functionality for other ProtonVPN components to interact with NetworkManager";
81 homepage = "https://github.com/ProtonVPN/python-proton-vpn-network-manager";
82 license = lib.licenses.gpl3Only;
83 platforms = lib.platforms.linux;
84 maintainers = with lib.maintainers; [
85 sebtm
86 rapiteanu
87 ];
88 };
89}