1 { lib, stdenv, fetchurl, nspr, perl, zlib, sqlite, fixDarwinDylibNames, buildPackages }:
5 url = "http://dev.gentoo.org/~polynomial-c/mozilla/nss-3.15.4-pem-support-20140109.patch.xz";
6 sha256 = "10ibz6y0hknac15zr6dw4gv9nb5r5z9ym6gq18j3xqx7v7n3vpdw";
9 underscoreVersion = builtins.replaceStrings ["."] ["_"] version;
11 in stdenv.mkDerivation rec {
16 url = "mirror://mozilla/security/nss/releases/NSS_${underscoreVersion}_RTM/src/${pname}-${version}.tar.gz";
17 sha256 = "7ec1a52e20fd9a23e1907eeba8f4f2ecd619dac5d20fa023ec5b4faa1843e847";
20 depsBuildBuild = [ buildPackages.stdenv.cc ];
22 nativeBuildInputs = [ perl ]
23 ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;
25 buildInputs = [ zlib sqlite ];
27 propagatedBuildInputs = [ nspr ];
30 xz -d < ${nssPEM} | patch -p1
35 # Based on http://patch-tracker.debian.org/patch/series/dl/nss/2:3.15.4-1/85_security_load.patch
36 ./85_security_load-3.44.patch
40 patchFlags = [ "-p0" ];
42 postPatch = lib.optionalString stdenv.isDarwin ''
43 substituteInPlace nss/coreconf/Darwin.mk --replace '@executable_path/$(notdir $@)' "$out/lib/\$(notdir \$@)"
46 outputs = [ "out" "dev" "tools" ];
48 preConfigure = "cd nss";
51 # NSS's build systems expects aarch32 to be called arm; if we pass in armv6l/armv7l, it
52 # fails with a linker error
53 cpu = if stdenv.hostPlatform.isAarch32 then "arm" else stdenv.hostPlatform.parsed.cpu.name;
55 "NSPR_INCLUDE_DIR=${nspr.dev}/include"
56 "NSPR_LIB_DIR=${nspr.out}/lib"
59 "SOURCE_PREFIX=\$(out)"
62 "NSS_USE_SYSTEM_SQLITE=1"
63 "NATIVE_CC=${buildPackages.stdenv.cc}/bin/cc"
64 ] ++ lib.optionals (!stdenv.isDarwin) [
65 # Pass in CPU even if we're not cross compiling, because otherwise it tries to guess with
66 # uname, which can be wrong if e.g. we're compiling for aarch32 on aarch64
69 ] ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) [
71 "NSS_DISABLE_GTESTS=1" # don't want to build tests when cross-compiling
72 ] ++ lib.optional stdenv.is64bit "USE_64=1"
73 ++ lib.optional stdenv.isDarwin "CCC=clang++";
75 NIX_CFLAGS_COMPILE = "-Wno-error";
77 # TODO(@oxij): investigate this: `make -n check` works but `make
78 # check` fails with "no rule", same for "installcheck".
80 doInstallCheck = false;
84 mv $out/public $out/include
90 # Upstream issue: https://bugzilla.mozilla.org/show_bug.cgi?id=530672
91 # https://gitweb.gentoo.org/repo/gentoo.git/plain/dev-libs/nss/files/nss-3.32-gentoo-fixups.patch?id=af1acce6c6d2c3adb17689261dfe2c2b6771ab8a
92 NSS_MAJOR_VERSION=`grep "NSS_VMAJOR" lib/nss/nss.h | awk '{print $3}'`
93 NSS_MINOR_VERSION=`grep "NSS_VMINOR" lib/nss/nss.h | awk '{print $3}'`
94 NSS_PATCH_VERSION=`grep "NSS_VPATCH" lib/nss/nss.h | awk '{print $3}'`
97 mkdir -p $out/lib/pkgconfig
98 sed -e "s,%prefix%,$PREFIX," \
99 -e "s,%exec_prefix%,$PREFIX," \
100 -e "s,%libdir%,$PREFIX/lib64," \
101 -e "s,%includedir%,$dev/include/nss," \
102 -e "s,%NSS_VERSION%,$NSS_MAJOR_VERSION.$NSS_MINOR_VERSION.$NSS_PATCH_VERSION,g" \
103 -e "s,%NSPR_VERSION%,4.16,g" \
104 pkg/pkg-config/nss.pc.in > $out/lib/pkgconfig/nss.pc
105 chmod 0644 $out/lib/pkgconfig/nss.pc
107 sed -e "s,@prefix@,$PREFIX," \
108 -e "s,@MOD_MAJOR_VERSION@,$NSS_MAJOR_VERSION," \
109 -e "s,@MOD_MINOR_VERSION@,$NSS_MINOR_VERSION," \
110 -e "s,@MOD_PATCH_VERSION@,$NSS_PATCH_VERSION," \
111 pkg/pkg-config/nss-config.in > $out/bin/nss-config
112 chmod 0755 $out/bin/nss-config
116 isCross = stdenv.hostPlatform != stdenv.buildPlatform;
117 nss = if isCross then buildPackages.nss.tools else "$out";
119 for libname in freebl3 nssdbm3 softokn3
123 libfile="$out/lib/lib$libname.dylib"
124 DYLD_LIBRARY_PATH=$out/lib:${nspr.out}/lib \
126 libfile="$out/lib/lib$libname.so"
127 LD_LIBRARY_PATH=$out/lib:${nspr.out}/lib \
129 ${nss}/bin/shlibsign -v -i "$libfile"
132 moveToOutput bin "$tools"
133 moveToOutput bin/nss-config "$dev"
134 moveToOutput lib/libcrmf.a "$dev" # needed by firefox, for example
139 homepage = "https://developer.mozilla.org/en-US/docs/NSS";
140 description = "A set of libraries for development of security-enabled client and server applications";
141 license = licenses.mpl20;
142 platforms = platforms.all;