aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/pkgs/applications/networking/protonvpn-cli/default.nix
blob: c48f6c820269102a609a12d2757cdd097592f5f1 (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
{ stdenv, lib, fetchFromGitHub, makeWrapper, coreutils
, openvpn, python, dialog, wget, update-resolv-conf }:

let
  expectedUpdateResolvPath = "/etc/openvpn/update-resolv-conf";
  actualUpdateResolvePath = "${update-resolv-conf}/libexec/openvpn/update-resolv-conf";

in stdenv.mkDerivation rec {
  name = "protonvpn-cli";
  version = "1.1.2";

  src = fetchFromGitHub {
    owner = "ProtonVPN";
    repo = "protonvpn-cli";
    rev = "v${version}";
    sha256 = "0xvflr8zf267n3dv63nkk4wjxhbckw56sqmyca3krf410vrd7zlv";
  };

  nativeBuildInputs = [ makeWrapper ];

  installPhase = ''
    mkdir -p "$out/bin"
    substituteInPlace protonvpn-cli.sh \
      --replace ${expectedUpdateResolvPath} ${actualUpdateResolvePath} \
      --replace \$UID 0 \
      --replace /etc/resolv.conf /dev/null \
      --replace \
        "  echo \"Connecting...\"" \
        "  sed -ri 's@${expectedUpdateResolvPath}@${actualUpdateResolvePath}@g' \"\$openvpn_config\"; echo \"Connecting...\""
    cp protonvpn-cli.sh "$out/bin/protonvpn-cli"
    wrapProgram $out/bin/protonvpn-cli \
      --prefix PATH : ${lib.makeBinPath [ coreutils openvpn python dialog wget update-resolv-conf ]}
    ln -s "$out/bin/protonvpn-cli" "$out/bin/pvpn"
  '';

  meta = with stdenv.lib; {
    description = "ProtonVPN Command-Line Tool";
    homepage = "https://github.com/ProtonVPN/protonvpn-cli";
    maintainers = with maintainers; [ caugner ];
    license = licenses.mit;
    platforms = platforms.unix;
  };
}