1 { lib, stdenv, fetchurl, nspr, perl, zlib
3 , darwin, fixDarwinDylibNames, buildPackages
4 , useP11kit ? true, p11-kit
5 , # allow FIPS mode. Note that this makes the output non-reproducible.
6 # https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/NSS_Tech_Notes/nss_tech_note6
12 url = "http://dev.gentoo.org/~polynomial-c/mozilla/nss-3.15.4-pem-support-20140109.patch.xz";
13 sha256 = "10ibz6y0hknac15zr6dw4gv9nb5r5z9ym6gq18j3xqx7v7n3vpdw";
16 # NOTE: Whenever you updated this version check if the `cacert` package also
17 # needs an update. You can run the regular updater script for cacerts.
18 # It will rebuild itself using the version of this package (NSS) and if
19 # an update is required do the required changes to the expression.
20 # Example: nix-shell ./maintainers/scripts/update.nix --argstr package cacert
22 underscoreVersion = builtins.replaceStrings ["."] ["_"] version;
24 in stdenv.mkDerivation rec {
29 url = "mirror://mozilla/security/nss/releases/NSS_${underscoreVersion}_RTM/src/${pname}-${version}.tar.gz";
30 sha256 = "0892xbjcaw6g4rd2rs4qa37nbda248cjrgxa4faaw0licbpjyb8q";
33 depsBuildBuild = [ buildPackages.stdenv.cc ];
35 nativeBuildInputs = [ perl ninja (buildPackages.python3.withPackages (ps: with ps; [ gyp ])) ]
36 ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.cctools fixDarwinDylibNames ];
38 buildInputs = [ zlib sqlite ];
40 propagatedBuildInputs = [ nspr ];
43 # strip the trailing whitespace from the patch line and the renamed CKO_NETSCAPE_ enum to CKO_NSS_
44 xz -d < ${nssPEM} | sed \
45 -e 's/-DIRS = builtins $/-DIRS = . builtins/g' \
46 -e 's/CKO_NETSCAPE_/CKO_NSS_/g' \
47 -e 's/CKT_NETSCAPE_/CKT_NSS_/g' \
52 for f in nss/coreconf/config.gypi nss/build.sh nss/coreconf/config.gypi; do
53 substituteInPlace "$f" --replace "/usr/bin/env" "${buildPackages.coreutils}/bin/env"
56 substituteInPlace nss/coreconf/config.gypi --replace "/usr/bin/grep" "${buildPackages.coreutils}/bin/env grep"
61 # Based on http://patch-tracker.debian.org/patch/series/dl/nss/2:3.15.4-1/85_security_load.patch
62 ./85_security_load.patch
64 ./fix-cross-compilation.patch
67 patchFlags = [ "-p0" ];
69 postPatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
70 substituteInPlace nss/coreconf/Darwin.mk --replace '@executable_path/$(notdir $@)' "$out/lib/\$(notdir \$@)"
71 substituteInPlace nss/coreconf/config.gypi --replace "'DYLIB_INSTALL_NAME_BASE': '@executable_path'" "'DYLIB_INSTALL_NAME_BASE': '$out/lib'"
74 outputs = [ "out" "dev" "tools" ];
76 preConfigure = "cd nss";
79 getArch = platform: if platform.isx86_64 then "x64"
80 else if platform.isx86_32 then "ia32"
81 else if platform.isAarch32 then "arm"
82 else if platform.isAarch64 then "arm64"
83 else if platform.isPower && platform.is64bit then (
84 if platform.isLittleEndian then "ppc64le" else "ppc64"
86 else platform.parsed.cpu.name;
87 # 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
88 target = getArch stdenv.hostPlatform;
89 host = getArch stdenv.buildPlatform;
93 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
95 --with-nspr=${nspr.dev}/include:${nspr.out}/lib \
100 -Duse_system_zlib=1 \
102 ${lib.optionalString enableFIPS "--enable-fips"} \
103 ${lib.optionalString stdenv.isDarwin "--clang"} \
104 ${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "--disable-tests"}
109 NIX_CFLAGS_COMPILE = "-Wno-error -DNIX_NSS_LIBDIR=\"${placeholder "out"}/lib/\"";
115 find $out -name "*.TOC" -delete
116 mv $out/public $out/include
120 # Upstream issue: https://bugzilla.mozilla.org/show_bug.cgi?id=530672
121 # https://gitweb.gentoo.org/repo/gentoo.git/plain/dev-libs/nss/files/nss-3.32-gentoo-fixups.patch?id=af1acce6c6d2c3adb17689261dfe2c2b6771ab8a
122 NSS_MAJOR_VERSION=`grep "NSS_VMAJOR" lib/nss/nss.h | awk '{print $3}'`
123 NSS_MINOR_VERSION=`grep "NSS_VMINOR" lib/nss/nss.h | awk '{print $3}'`
124 NSS_PATCH_VERSION=`grep "NSS_VPATCH" lib/nss/nss.h | awk '{print $3}'`
127 mkdir -p $out/lib/pkgconfig
128 sed -e "s,%prefix%,$PREFIX," \
129 -e "s,%exec_prefix%,$PREFIX," \
130 -e "s,%libdir%,$PREFIX/lib64," \
131 -e "s,%includedir%,$dev/include/nss," \
132 -e "s,%NSS_VERSION%,$NSS_MAJOR_VERSION.$NSS_MINOR_VERSION.$NSS_PATCH_VERSION,g" \
133 -e "s,%NSPR_VERSION%,4.16,g" \
134 pkg/pkg-config/nss.pc.in > $out/lib/pkgconfig/nss.pc
135 chmod 0644 $out/lib/pkgconfig/nss.pc
137 sed -e "s,@prefix@,$PREFIX," \
138 -e "s,@MOD_MAJOR_VERSION@,$NSS_MAJOR_VERSION," \
139 -e "s,@MOD_MINOR_VERSION@,$NSS_MINOR_VERSION," \
140 -e "s,@MOD_PATCH_VERSION@,$NSS_PATCH_VERSION," \
141 pkg/pkg-config/nss-config.in > $out/bin/nss-config
142 chmod 0755 $out/bin/nss-config
145 postInstall = lib.optionalString useP11kit ''
146 # Replace built-in trust with p11-kit connection
147 ln -sf ${p11-kit}/lib/pkcs11/p11-kit-trust.so $out/lib/libnssckbi.so
151 isCross = stdenv.hostPlatform != stdenv.buildPlatform;
152 nss = if isCross then buildPackages.nss.tools else "$out";
154 (lib.optionalString enableFIPS (''
155 for libname in freebl3 nssdbm3 softokn3
159 libfile="$out/lib/lib$libname.dylib"
160 DYLD_LIBRARY_PATH=$out/lib:${nspr.out}/lib \
162 libfile="$out/lib/lib$libname.so"
163 LD_LIBRARY_PATH=$out/lib:${nspr.out}/lib \
165 ${nss}/bin/shlibsign -v -i "$libfile"
169 moveToOutput bin "$tools"
170 moveToOutput bin/nss-config "$dev"
171 moveToOutput lib/libcrmf.a "$dev" # needed by firefox, for example
178 homepage = "https://developer.mozilla.org/en-US/docs/NSS";
179 description = "A set of libraries for development of security-enabled client and server applications";
180 license = licenses.mpl20;
181 platforms = platforms.all;