summary refs log tree commit diff
path: root/pkgs/applications/networking/expressvpn/default.nix
blob: 0bc0fd34fe5adbdba5b0a505d38f07234659a356 (plain) (blame)
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
{ autoPatchelfHook
, buildFHSUserEnv
, dpkg
, fetchurl
, inotify-tools
, lib
, stdenvNoCC
, sysctl
, writeScript
}:

let
  pname = "expressvpn";
  clientVersion = "3.25.0";
  clientBuild = "13";
  version = lib.strings.concatStringsSep "." [ clientVersion clientBuild ];

  expressvpnBase = stdenvNoCC.mkDerivation {
    inherit pname version;

    src = fetchurl {
      url = "https://www.expressvpn.works/clients/linux/expressvpn_${version}-1_amd64.deb";
      hash = "sha256-lyDjG346FrgT7SZbsWET+Hexl9Un6mzMukfO2PwlInA=";
    };

    nativeBuildInputs = [ dpkg autoPatchelfHook ];

    dontConfigure = true;
    dontBuild = true;

    unpackPhase = ''
      runHook preUnpack
      dpkg --fsys-tarfile $src | tar --extract
      runHook postUnpack
    '';

    installPhase = ''
      runHook preInstall
      mv usr/ $out/
      runHook postInstall
    '';
  };

  expressvpndFHS = buildFHSUserEnv {
    name = "expressvpnd";

    # When connected, it directly creates/deletes resolv.conf to change the DNS entries.
    # Since it's running in an FHS environment, it has no effect on actual resolv.conf.
    # Hence, place a watcher that updates host resolv.conf when FHS resolv.conf changes.
    runScript = writeScript "${pname}-wrapper" ''
      cp /host/etc/resolv.conf /etc/resolv.conf;
      while inotifywait /etc 2>/dev/null;
      do
        cp /etc/resolv.conf /host/etc/resolv.conf;
      done &
      expressvpnd --client-version ${clientVersion} --client-build ${clientBuild}
    '';

    # expressvpnd binary has hard-coded the path /sbin/sysctl hence below workaround.
    extraBuildCommands = ''
      chmod +w sbin
      ln -s ${sysctl}/bin/sysctl sbin/sysctl
    '';

    # The expressvpnd binary also uses hard-coded paths to the other binaries and files
    # it ships with, hence the FHS environment.

    targetPkgs = pkgs: with pkgs; [
      expressvpnBase
      inotify-tools
      iproute2
    ];
  };
in
stdenvNoCC.mkDerivation {
  inherit pname version;

  dontUnpack = true;
  dontConfigure = true;
  dontBuild = true;

  installPhase = ''
    runHook preInstall
    mkdir -p $out/bin $out/share
    ln -s ${expressvpnBase}/bin/expressvpn $out/bin
    ln -s ${expressvpndFHS}/bin/expressvpnd $out/bin
    ln -s ${expressvpnBase}/share/{bash-completion,doc,man} $out/share/
    runHook postInstall
  '';

  meta = with lib; {
    description = "CLI client for ExpressVPN";
    homepage = "https://www.expressvpn.com";
    license = licenses.unfree;
    platforms = [ "x86_64-linux" ];
    maintainers = with maintainers; [ yureien ];
  };
}