nixpkgs/pkgs/tools/networking/openvpn/default.nix
Adam Joseph 42815b4a0c treewide: systemdSupport: use lib.meta.availableOn
Many packages have some kind of flag indicating whether or not to build with
systemd support.  Most of these default to `stdenv.isLinux`, but systemd does
not build on (and is marked `broken` for) `isStatic`.  Only a few packages have
the needed `&& !isStatic` in the default value for their parameter.

This commit moves the logic for the default value of these flags into
`systemd.meta.{platforms,badPlatforms}` and evaluates those conditions using
`lib.meta.availableOn`.

This provides three benefits:

1. The default values are set correctly (i.e. including `&& isStatic`)

2. The default values are set consistently

3. The way is paved for any future non-Linux systemd platforms (FreeBSD is
   reported to have experimental systemd support)
2023-01-22 00:27:19 -08:00

89 lines
2.6 KiB
Nix

{ lib
, stdenv
, fetchurl
, pkg-config
, iproute2
, lzo
, openssl
, openssl_1_1
, pam
, useSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd
, systemd
, update-systemd-resolved
, util-linux
, pkcs11Support ? false
, pkcs11helper
}:
let
inherit (lib) versionOlder optional optionals optionalString;
generic = { version, sha256, extraBuildInputs ? [] }:
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 = [ pkg-config ];
buildInputs = [ lzo ]
++ optional stdenv.isLinux pam
++ optional withIpRoute iproute2
++ optional useSystemd systemd
++ optional pkcs11Support pkcs11helper
++ extraBuildInputs;
configureFlags = optionals withIpRoute [
"--enable-iproute2"
"IPROUTE=${iproute2}/sbin/ip"
]
++ optional useSystemd "--enable-systemd"
++ optional pkcs11Support "--enable-pkcs11"
++ optional stdenv.isDarwin "--disable-plugin-auth-pam";
# We used to vendor the update-systemd-resolved script inside libexec,
# but a separate package was made, that uses libexec/openvpn. Copy it
# into libexec in case any consumers expect it to be there even though
# they should use the update-systemd-resolved package instead.
postInstall = ''
mkdir -p $out/share/doc/openvpn/examples
cp -r sample/sample-{config-files,keys,scripts}/ $out/share/doc/openvpn/examples
'' + optionalString useSystemd ''
install -Dm555 -t $out/libexec ${update-systemd-resolved}/libexec/openvpn/*
'';
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.gpl2Only;
maintainers = with maintainers; [ viric peterhoeg ];
platforms = platforms.unix;
};
};
in
{
openvpn_24 = generic {
version = "2.4.12";
sha256 = "1vjx82nlkxrgzfiwvmmlnz8ids5m2fiqz7scy1smh3j9jnf2v5b6";
extraBuildInputs = [ openssl_1_1 ];
};
openvpn = generic {
version = "2.5.8";
sha256 = "1cixqm4gn2d1v8qkbww75j30fzvxz13gc7whcmz54i0x4fvibwx6";
extraBuildInputs = [ openssl ];
};
}