summary refs log tree commit diff
path: root/pkgs/tools/networking/openvpn/default.nix
blob: 9200bc3f30e8d84bffdb58dffbe42132a9627324 (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
{ lib, stdenv
, fetchurl
, pkg-config
, makeWrapper
, runtimeShell
, iproute2
, lzo
, openssl
, pam
, useSystemd ? stdenv.isLinux
, systemd
, util-linux
, pkcs11Support ? false
, pkcs11helper
}:

with lib;
let
  # Check if the script needs to have other binaries wrapped when changing this.
  update-resolved = fetchurl {
    url = "https://raw.githubusercontent.com/jonathanio/update-systemd-resolved/v1.3.0/update-systemd-resolved";
    sha256 = "021qzv1k0zxgv1rmyfpqj3zlzqr28xa7zff1n7vrbjk36ijylpsc";
  };

  generic = { version, sha256 }:
    let
      withIpRoute = stdenv.isLinux && (versionOlder version "2.5.4");
    in
    stdenv.mkDerivation
      rec {
        pname = "openvpn";
        inherit version;

        src = fetchurl {
          url = "https://swupdate.openvpn.net/community/releases/${pname}-${version}.tar.gz";
          inherit sha256;
        };

        nativeBuildInputs = [ makeWrapper pkg-config ];

        buildInputs = [ lzo openssl ]
          ++ optional stdenv.isLinux pam
          ++ optional withIpRoute iproute2
          ++ optional useSystemd systemd
          ++ optional pkcs11Support pkcs11helper;

        configureFlags = optionals withIpRoute [
          "--enable-iproute2"
          "IPROUTE=${iproute2}/sbin/ip"
        ]
        ++ optional useSystemd "--enable-systemd"
        ++ optional pkcs11Support "--enable-pkcs11"
        ++ optional stdenv.isDarwin "--disable-plugin-auth-pam";

        postInstall = ''
          mkdir -p $out/share/doc/openvpn/examples
          cp -r sample/sample-config-files/ $out/share/doc/openvpn/examples
          cp -r sample/sample-keys/ $out/share/doc/openvpn/examples
          cp -r sample/sample-scripts/ $out/share/doc/openvpn/examples
        '' + optionalString useSystemd ''
          install -Dm555 ${update-resolved} $out/libexec/update-systemd-resolved
          wrapProgram $out/libexec/update-systemd-resolved \
            --prefix PATH : ${makeBinPath [ runtimeShell iproute2 systemd util-linux ]}
        '';

        enableParallelBuilding = true;

        meta = with lib; {
          description = "A robust and highly flexible tunneling application";
          downloadPage = "https://openvpn.net/community-downloads/";
          homepage = "https://openvpn.net/";
          license = licenses.gpl2;
          maintainers = with maintainers; [ viric peterhoeg ];
          platforms = platforms.unix;
        };
      };

in
{
  openvpn_24 = generic {
    version = "2.4.12";
    sha256 = "1vjx82nlkxrgzfiwvmmlnz8ids5m2fiqz7scy1smh3j9jnf2v5b6";
  };

  openvpn = generic {
    version = "2.5.6";
    sha256 = "0gdd88rcan9vfiwkzsqn6fxxdim7kb1bsxrcra59c5xksprpwfik";
  };
}