1{
2 lib,
3 stdenv,
4 fetchurl,
5 pkg-config,
6 libcap_ng,
7 libnl,
8 lz4,
9 lzo,
10 openssl,
11 pam,
12 useSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd,
13 systemd,
14 update-systemd-resolved,
15 pkcs11Support ? false,
16 pkcs11helper,
17 nixosTests,
18 unixtools,
19}:
20
21let
22 inherit (lib) optional optionals optionalString;
23in
24stdenv.mkDerivation (finalAttrs: {
25 pname = "openvpn";
26 version = "2.6.14";
27
28 src = fetchurl {
29 url = "https://swupdate.openvpn.net/community/releases/openvpn-${finalAttrs.version}.tar.gz";
30 hash = "sha256-nramYYNS+ee3canTiuFjG17f7tbUAjPiQ+YC3fIZXno=";
31 };
32
33 nativeBuildInputs = [
34 pkg-config
35 ]
36 ++ lib.optionals stdenv.hostPlatform.isDarwin [
37 unixtools.route
38 unixtools.ifconfig
39 ];
40
41 buildInputs = [
42 lz4
43 lzo
44 openssl
45 ]
46 ++ optionals stdenv.hostPlatform.isLinux [
47 libcap_ng
48 libnl
49 pam
50 ]
51 ++ optional useSystemd systemd
52 ++ optional pkcs11Support pkcs11helper;
53
54 configureFlags =
55 optional useSystemd "--enable-systemd"
56 ++ optional pkcs11Support "--enable-pkcs11"
57 ++ optional stdenv.hostPlatform.isDarwin "--disable-plugin-auth-pam";
58
59 # We used to vendor the update-systemd-resolved script inside libexec,
60 # but a separate package was made, that uses libexec/openvpn. Copy it
61 # into libexec in case any consumers expect it to be there even though
62 # they should use the update-systemd-resolved package instead.
63 postInstall = ''
64 mkdir -p $out/share/doc/openvpn/examples
65 cp -r sample/sample-{config-files,keys,scripts}/ $out/share/doc/openvpn/examples
66 ''
67 + optionalString useSystemd ''
68 install -Dm555 -t $out/libexec ${update-systemd-resolved}/libexec/openvpn/*
69 '';
70
71 enableParallelBuilding = true;
72
73 passthru.tests = {
74 inherit (nixosTests) initrd-network-openvpn systemd-initrd-networkd-openvpn;
75 };
76
77 meta = with lib; {
78 description = "Robust and highly flexible tunneling application";
79 downloadPage = "https://openvpn.net/community-downloads/";
80 homepage = "https://openvpn.net/";
81 license = licenses.gpl2Only;
82 maintainers = with maintainers; [ peterhoeg ];
83 platforms = platforms.unix;
84 mainProgram = "openvpn";
85 };
86})