nixpkgs/pkgs/development/libraries/nss/generic.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

190 lines
6.4 KiB
Nix
Raw Normal View History

2022-05-31 22:33:23 +00:00
{ version, hash }:
2021-08-10 11:01:51 +00:00
{ lib
, stdenv
, fetchurl
, nspr
, perl
, zlib
, sqlite
, ninja
, darwin
, fixDarwinDylibNames
, buildPackages
, useP11kit ? true
, p11-kit
, # allow FIPS mode. Note that this makes the output non-reproducible.
# https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/NSS_Tech_Notes/nss_tech_note6
enableFIPS ? false
, nixosTests
}:
let
underscoreVersion = lib.replaceStrings [ "." ] [ "_" ] version;
2021-08-10 11:01:51 +00:00
in
stdenv.mkDerivation rec {
pname = "nss";
inherit version;
2012-10-31 13:04:58 +00:00
src = fetchurl {
url = "mirror://mozilla/security/nss/releases/NSS_${underscoreVersion}_RTM/src/${pname}-${version}.tar.gz";
2022-05-31 22:33:23 +00:00
inherit hash;
};
2019-03-20 20:05:45 +00:00
depsBuildBuild = [ buildPackages.stdenv.cc ];
2020-07-20 15:02:44 +00:00
nativeBuildInputs = [ perl ninja (buildPackages.python3.withPackages (ps: with ps; [ gyp ])) ]
++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.cctools fixDarwinDylibNames ];
2019-03-20 20:05:45 +00:00
buildInputs = [ zlib sqlite ];
2017-03-22 18:47:51 +00:00
propagatedBuildInputs = [ nspr ];
2021-08-10 11:01:51 +00:00
patches = [
# Based on http://patch-tracker.debian.org/patch/series/dl/nss/2:3.15.4-1/85_security_load.patch
(if (lib.versionOlder version "3.77") then
./85_security_load.patch
else
./85_security_load_3.77+.patch
)
./fix-cross-compilation.patch
2021-08-10 11:01:51 +00:00
];
2019-10-26 15:39:27 +00:00
patchFlags = [ "-p0" ];
2017-01-24 13:49:14 +00:00
postPatch = ''
patchShebangs nss
for f in nss/coreconf/config.gypi nss/build.sh nss/coreconf/config.gypi; do
substituteInPlace "$f" --replace "/usr/bin/env" "${buildPackages.coreutils}/bin/env"
done
substituteInPlace nss/coreconf/config.gypi --replace "/usr/bin/grep" "${buildPackages.coreutils}/bin/env grep"
'' + lib.optionalString stdenv.hostPlatform.isDarwin ''
2021-08-10 11:01:51 +00:00
substituteInPlace nss/coreconf/Darwin.mk --replace '@executable_path/$(notdir $@)' "$out/lib/\$(notdir \$@)"
substituteInPlace nss/coreconf/config.gypi --replace "'DYLIB_INSTALL_NAME_BASE': '@executable_path'" "'DYLIB_INSTALL_NAME_BASE': '$out/lib'"
'';
2020-08-03 02:02:14 +00:00
outputs = [ "out" "dev" "tools" ];
2013-08-07 14:17:58 +00:00
preConfigure = "cd nss";
2021-08-10 11:01:51 +00:00
buildPhase =
let
getArch = platform:
if platform.isx86_64 then "x64"
else if platform.isx86_32 then "ia32"
else if platform.isAarch32 then "arm"
else if platform.isAarch64 then "arm64"
else if platform.isPower && platform.is64bit then
(
if platform.isLittleEndian then "ppc64le" else "ppc64"
)
2021-08-10 11:01:51 +00:00
else platform.parsed.cpu.name;
# yes, this is correct. nixpkgs uses "host" for the platform the binary will run on whereas nss uses "host" for the platform that the build is running on
target = getArch stdenv.hostPlatform;
host = getArch stdenv.buildPlatform;
in
''
runHook preBuild
sed -i 's|nss_dist_dir="$dist_dir"|nss_dist_dir="'$out'"|;s|nss_dist_obj_dir="$obj_dir"|nss_dist_obj_dir="'$out'"|' build.sh
./build.sh -v --opt \
--with-nspr=${nspr.dev}/include:${nspr.out}/lib \
--system-sqlite \
--enable-legacy-db \
--target ${target} \
-Dhost_arch=${host} \
-Duse_system_zlib=1 \
--enable-libpkix \
${lib.optionalString enableFIPS "--enable-fips"} \
${lib.optionalString stdenv.isDarwin "--clang"} \
${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "--disable-tests"}
runHook postBuild
'';
2020-06-29 01:09:27 +00:00
NIX_CFLAGS_COMPILE = "-Wno-error -DNIX_NSS_LIBDIR=\"${placeholder "out"}/lib/\" " + lib.optionalString stdenv.hostPlatform.is64bit "-DNSS_USE_64=1";
2020-06-29 01:09:27 +00:00
installPhase = ''
runHook preInstall
rm -rf $out/private
2020-06-29 01:09:27 +00:00
find $out -name "*.TOC" -delete
mv $out/public $out/include
2013-08-07 14:17:58 +00:00
ln -s lib $out/lib64
2017-09-28 23:52:45 +00:00
# Upstream issue: https://bugzilla.mozilla.org/show_bug.cgi?id=530672
# https://gitweb.gentoo.org/repo/gentoo.git/plain/dev-libs/nss/files/nss-3.32-gentoo-fixups.patch?id=af1acce6c6d2c3adb17689261dfe2c2b6771ab8a
NSS_MAJOR_VERSION=`grep "NSS_VMAJOR" lib/nss/nss.h | awk '{print $3}'`
NSS_MINOR_VERSION=`grep "NSS_VMINOR" lib/nss/nss.h | awk '{print $3}'`
NSS_PATCH_VERSION=`grep "NSS_VPATCH" lib/nss/nss.h | awk '{print $3}'`
PREFIX="$out"
mkdir -p $out/lib/pkgconfig
sed -e "s,%prefix%,$PREFIX," \
-e "s,%exec_prefix%,$PREFIX," \
-e "s,%libdir%,$PREFIX/lib64," \
2017-10-09 18:49:11 +00:00
-e "s,%includedir%,$dev/include/nss," \
2017-09-28 23:52:45 +00:00
-e "s,%NSS_VERSION%,$NSS_MAJOR_VERSION.$NSS_MINOR_VERSION.$NSS_PATCH_VERSION,g" \
-e "s,%NSPR_VERSION%,4.16,g" \
pkg/pkg-config/nss.pc.in > $out/lib/pkgconfig/nss.pc
chmod 0644 $out/lib/pkgconfig/nss.pc
sed -e "s,@prefix@,$PREFIX," \
-e "s,@MOD_MAJOR_VERSION@,$NSS_MAJOR_VERSION," \
-e "s,@MOD_MINOR_VERSION@,$NSS_MINOR_VERSION," \
-e "s,@MOD_PATCH_VERSION@,$NSS_PATCH_VERSION," \
pkg/pkg-config/nss-config.in > $out/bin/nss-config
chmod 0755 $out/bin/nss-config
'';
2021-01-31 15:07:26 +00:00
postInstall = lib.optionalString useP11kit ''
# Replace built-in trust with p11-kit connection
ln -sf ${p11-kit}/lib/pkcs11/p11-kit-trust.so $out/lib/libnssckbi.so
'';
2021-08-10 11:01:51 +00:00
postFixup =
let
isCross = stdenv.hostPlatform != stdenv.buildPlatform;
nss = if isCross then buildPackages.nss.tools else "$out";
in
(lib.optionalString enableFIPS (''
for libname in freebl3 nssdbm3 softokn3
do libfile="$out/lib/lib$libname${stdenv.hostPlatform.extensions.sharedLibrary}"'' +
(if stdenv.isDarwin
2021-08-10 11:01:51 +00:00
then ''
DYLD_LIBRARY_PATH=$out/lib:${nspr.out}/lib \
'' else ''
LD_LIBRARY_PATH=$out/lib:${nspr.out}/lib \
'') + ''
${nss}/bin/shlibsign -v -i "$libfile"
done
'')) +
''
moveToOutput bin "$tools"
moveToOutput bin/nss-config "$dev"
moveToOutput lib/libcrmf.a "$dev" # needed by firefox, for example
rm -f "$out"/lib/*.a
runHook postInstall
'';
2013-08-07 14:17:58 +00:00
2021-09-07 20:48:33 +00:00
passthru.updateScript = ./update.sh;
passthru.tests = lib.optionalAttrs (lib.versionOlder version "3.69") {
inherit (nixosTests) firefox-esr-91;
} // lib.optionalAttrs (lib.versionAtLeast version "3.69") {
inherit (nixosTests) firefox firefox-esr-102;
};
meta = with lib; {
2021-08-10 11:01:51 +00:00
homepage = "https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS";
2013-08-07 14:17:58 +00:00
description = "A set of libraries for development of security-enabled client and server applications";
changelog = "https://github.com/nss-dev/nss/blob/master/doc/rst/releases/nss_${underscoreVersion}.rst";
2022-03-16 23:20:27 +00:00
maintainers = with maintainers; [ hexa ajs124 ];
2018-08-17 21:55:36 +00:00
license = licenses.mpl20;
platforms = platforms.all;
2013-08-07 14:17:58 +00:00
};
}