nixpkgs/pkgs/development/python-modules/nassl/default.nix

133 lines
3.7 KiB
Nix
Raw Normal View History

2020-05-21 10:27:42 +00:00
{ lib
, fetchFromGitHub
, fetchurl
, buildPythonPackage
, pkgsStatic
, openssl
, invoke
, tls-parser
, cacert
2020-12-04 19:25:13 +00:00
, pytestCheckHook
2021-05-08 08:56:15 +00:00
, pythonOlder
2020-05-21 10:27:42 +00:00
}:
let
2021-05-08 08:56:15 +00:00
zlibStatic = (pkgsStatic.zlib.override {
splitStaticOutput = false;
2021-05-08 08:56:15 +00:00
}).overrideAttrs (oldAttrs: {
NIX_CFLAGS_COMPILE = "${oldAttrs.NIX_CFLAGS_COMPILE} -fPIC";
});
2020-05-21 10:27:42 +00:00
nasslOpensslArgs = {
static = true;
enableSSL2 = true;
};
nasslOpensslFlagsCommon = [
"zlib"
"no-zlib-dynamic"
"no-shared"
"--with-zlib-lib=${zlibStatic.out}/lib"
"--with-zlib-include=${zlibStatic.out.dev}/include"
"enable-rc5"
"enable-md2"
"enable-gost"
"enable-cast"
"enable-idea"
"enable-ripemd"
"enable-mdc2"
"-fPIC"
];
opensslStatic = (openssl.override nasslOpensslArgs).overrideAttrs (
oldAttrs: rec {
name = "openssl-${version}";
2020-12-04 19:25:13 +00:00
version = "1.1.1h";
2020-05-21 10:27:42 +00:00
src = fetchurl {
url = "https://www.openssl.org/source/${name}.tar.gz";
2020-12-04 19:25:13 +00:00
sha256 = "1ncmcnh5bmxkwrvm0m1q4kdcjjfpwvlyjspjhibkxc6p9dvsi72w";
2020-05-21 10:27:42 +00:00
};
configureFlags = oldAttrs.configureFlags ++ nasslOpensslFlagsCommon ++ [
"enable-weak-ssl-ciphers"
"enable-tls1_3"
"no-async"
];
buildInputs = oldAttrs.buildInputs ++ [ zlibStatic cacert ];
}
);
opensslLegacyStatic = (openssl.override nasslOpensslArgs).overrideAttrs (
oldAttrs: rec {
name = "openssl-${version}";
version = "1.0.2e";
src = fetchurl {
url = "https://www.openssl.org/source/${name}.tar.gz";
sha256 = "1zqb1rff1wikc62a7vj5qxd1k191m8qif5d05mwdxz2wnzywlg72";
};
configureFlags = oldAttrs.configureFlags ++ nasslOpensslFlagsCommon;
patches = [ ];
buildInputs = oldAttrs.buildInputs ++ [ zlibStatic ];
# openssl_1_0_2 needs `withDocs = false`
outputs = lib.remove "doc" oldAttrs.outputs;
}
);
in
buildPythonPackage rec {
pname = "nassl";
2021-05-08 08:56:15 +00:00
version = "4.0.0";
disabled = pythonOlder "3.7";
2020-05-21 10:27:42 +00:00
src = fetchFromGitHub {
owner = "nabla-c0d3";
repo = pname;
rev = version;
2021-05-08 08:56:15 +00:00
hash = "sha256-6lk2YfI9km10YbJAn38fvo9qa4iXcByL+udCsDe+kvU=";
2020-05-21 10:27:42 +00:00
};
2020-12-04 19:25:13 +00:00
postPatch = let
legacyOpenSSLVersion = lib.replaceStrings ["."] ["_"] opensslLegacyStatic.version;
modernOpenSSLVersion = lib.replaceStrings ["."] ["_"] opensslStatic.version;
zlibVersion = zlibStatic.version;
in ''
mkdir -p deps/openssl-OpenSSL_${legacyOpenSSLVersion}/
2020-05-21 10:27:42 +00:00
cp ${opensslLegacyStatic.out}/lib/libssl.a \
${opensslLegacyStatic.out}/lib/libcrypto.a \
2020-12-04 19:25:13 +00:00
deps/openssl-OpenSSL_${legacyOpenSSLVersion}/
ln -s ${opensslLegacyStatic.out.dev}/include deps/openssl-OpenSSL_${legacyOpenSSLVersion}/include
ln -s ${opensslLegacyStatic.bin}/bin deps/openssl-OpenSSL_${legacyOpenSSLVersion}/apps
2020-05-21 10:27:42 +00:00
2020-12-04 19:25:13 +00:00
mkdir -p deps/openssl-OpenSSL_${modernOpenSSLVersion}/
2020-05-21 10:27:42 +00:00
cp ${opensslStatic.out}/lib/libssl.a \
${opensslStatic.out}/lib/libcrypto.a \
2020-12-04 19:25:13 +00:00
deps/openssl-OpenSSL_${modernOpenSSLVersion}/
ln -s ${opensslStatic.out.dev}/include deps/openssl-OpenSSL_${modernOpenSSLVersion}/include
ln -s ${opensslStatic.bin}/bin deps/openssl-OpenSSL_${modernOpenSSLVersion}/apps
2020-05-21 10:27:42 +00:00
2020-12-04 19:25:13 +00:00
mkdir -p deps/zlib-${zlibVersion}/
cp ${zlibStatic.out}/lib/libz.a deps/zlib-${zlibVersion}/
2020-05-21 10:27:42 +00:00
'';
propagatedBuildInputs = [ tls-parser ];
nativeBuildInputs = [ invoke ];
buildPhase = ''
invoke build.nassl
invoke package.wheel
'';
2021-05-08 08:56:15 +00:00
doCheck = true;
pythonImportsCheck = [ "nassl" ];
2020-12-04 19:25:13 +00:00
checkInputs = [ pytestCheckHook ];
2020-05-21 10:27:42 +00:00
2021-05-08 08:56:15 +00:00
disabledTests = [
"Online"
];
2020-05-21 10:27:42 +00:00
meta = with lib; {
homepage = "https://github.com/nabla-c0d3/nassl";
description = "Low-level OpenSSL wrapper for Python 3.7+";
platforms = with platforms; linux ++ darwin;
2021-05-08 08:56:15 +00:00
license = licenses.agpl3Only;
2020-05-21 10:27:42 +00:00
maintainers = with maintainers; [ veehaitch ];
};
}