summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/proton-vpn-api-core/default.nix
blob: 43584ef7e16f97fa56c171ab8b1d4c5428096f92 (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
{
  lib,
  buildPythonPackage,
  fetchFromGitHub,
  aiohttp,
  cryptography,
  distro,
  fido2,
  gobject-introspection,
  iproute2,
  jinja2,
  networkmanager,
  proton-core,
  proton-vpn-local-agent,
  pycairo,
  pygobject3,
  pynacl,
  pyopenssl,
  pytest-asyncio,
  pytest-cov-stub,
  pytestCheckHook,
  pyxdg,
  requests,
  sentry-sdk,
  setuptools,
}:

buildPythonPackage rec {
  pname = "proton-vpn-api-core";
  version = "4.14.1";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "ProtonVPN";
    repo = "python-proton-vpn-api-core";
    rev = "v${version}";
    hash = "sha256-xyCjzcSasLGm2DMMViI1wpzcLd0mmaBvIyI1HrtW+Gg=";
  };

  postPatch = ''
    substituteInPlace proton/vpn/backend/networkmanager/killswitch/wireguard/killswitch_connection_handler.py \
      --replace-fail '["/usr/sbin/ip", "route"]' '["${iproute2}/bin/ip", "route"]'
  '';

  nativeBuildInputs = [
    # Needed to recognize the NM namespace
    gobject-introspection
  ];

  propagatedBuildInputs = [
    # Needed here for the NM namespace
    networkmanager
  ];

  build-system = [
    setuptools
  ];

  dependencies = [
    cryptography
    distro
    fido2
    jinja2
    proton-core
    proton-vpn-local-agent
    pycairo
    pygobject3
    pynacl
    pyxdg
    sentry-sdk
  ];

  pythonImportsCheck = [
    "proton.vpn.backend.networkmanager.core"
    "proton.vpn.backend.networkmanager.killswitch.default"
    "proton.vpn.backend.networkmanager.killswitch.wireguard"
    "proton.vpn.backend.networkmanager.protocol.openvpn"
    "proton.vpn.backend.networkmanager.protocol.wireguard"
    "proton.vpn.connection"
    "proton.vpn.core"
    "proton.vpn.killswitch.interface"
    "proton.vpn.logging"
    "proton.vpn.session"
    "proton.vpn.split_tunneling"
  ];

  nativeCheckInputs = [
    aiohttp
    pyopenssl
    pytest-asyncio
    requests
    pytestCheckHook
    pytest-cov-stub
  ];

  # Needed for `pythonImportsCheck`, `postInstall` happens between `pythonImportsCheckPhase` and `pytestCheckPhase`.
  postInstall = ''
    # Needed for Permission denied: '/homeless-shelter'
    export HOME=$(mktemp -d)
    export XDG_RUNTIME_DIR=$(mktemp -d)
  '';

  disabledTests = [
    # Permission denied: '/run'
    "test_ensure_configuration_file_is_created"
    "test_ovpnconfig_with_certificate"
    "test_ovpnconfig_with_settings"
    "test_wireguard_config_content_generation"
    "test_wireguard_with_non_certificate"
    "test_ensure_generate_is_returning_expected_content"
    "test_ensure_same_configuration_file_in_case_of_duplicate"
    "test_ensure_configuration_file_is_deleted"
  ];

  meta = {
    description = "Acts as a facade to the other Proton VPN components, exposing a uniform API to the available Proton VPN services";
    homepage = "https://github.com/ProtonVPN/python-proton-vpn-api-core";
    license = lib.licenses.gpl3Only;
    platforms = lib.platforms.linux;
    maintainers = with lib.maintainers; [
      anthonyroussel
      sebtm
      rapiteanu
    ];
  };
}