15 , # allow FIPS mode. Note that this makes the output non-reproducible.
16 # https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/NSS_Tech_Notes/nss_tech_note6
22 underscoreVersion = lib.replaceStrings [ "." ] [ "_" ] version;
24 stdenv.mkDerivation rec {
29 url = "mirror://mozilla/security/nss/releases/NSS_${underscoreVersion}_RTM/src/${pname}-${version}.tar.gz";
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 # Based on http://patch-tracker.debian.org/patch/series/dl/nss/2:3.15.4-1/85_security_load.patch
44 (if (lib.versionOlder version "3.77") then
45 ./85_security_load.patch
47 ./85_security_load_3.77+.patch
49 ./fix-cross-compilation.patch
52 patchFlags = [ "-p0" ];
57 for f in nss/coreconf/config.gypi nss/build.sh nss/coreconf/config.gypi; do
58 substituteInPlace "$f" --replace "/usr/bin/env" "${buildPackages.coreutils}/bin/env"
61 substituteInPlace nss/coreconf/config.gypi --replace "/usr/bin/grep" "${buildPackages.coreutils}/bin/env grep"
62 '' + lib.optionalString stdenv.hostPlatform.isDarwin ''
63 substituteInPlace nss/coreconf/Darwin.mk --replace '@executable_path/$(notdir $@)' "$out/lib/\$(notdir \$@)"
64 substituteInPlace nss/coreconf/config.gypi --replace "'DYLIB_INSTALL_NAME_BASE': '@executable_path'" "'DYLIB_INSTALL_NAME_BASE': '$out/lib'"
67 outputs = [ "out" "dev" "tools" ];
69 preConfigure = "cd nss";
74 if platform.isx86_64 then "x64"
75 else if platform.isx86_32 then "ia32"
76 else if platform.isAarch32 then "arm"
77 else if platform.isAarch64 then "arm64"
78 else if platform.isPower && platform.is64bit then
80 if platform.isLittleEndian then "ppc64le" else "ppc64"
82 else platform.parsed.cpu.name;
83 # 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
84 target = getArch stdenv.hostPlatform;
85 host = getArch stdenv.buildPlatform;
90 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
92 --with-nspr=${nspr.dev}/include:${nspr.out}/lib \
99 ${lib.optionalString enableFIPS "--enable-fips"} \
100 ${lib.optionalString stdenv.isDarwin "--clang"} \
101 ${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "--disable-tests"}
106 NIX_CFLAGS_COMPILE = "-Wno-error -DNIX_NSS_LIBDIR=\"${placeholder "out"}/lib/\" " + lib.optionalString stdenv.hostPlatform.is64bit "-DNSS_USE_64=1";
112 find $out -name "*.TOC" -delete
113 mv $out/public $out/include
117 # Upstream issue: https://bugzilla.mozilla.org/show_bug.cgi?id=530672
118 # https://gitweb.gentoo.org/repo/gentoo.git/plain/dev-libs/nss/files/nss-3.32-gentoo-fixups.patch?id=af1acce6c6d2c3adb17689261dfe2c2b6771ab8a
119 NSS_MAJOR_VERSION=`grep "NSS_VMAJOR" lib/nss/nss.h | awk '{print $3}'`
120 NSS_MINOR_VERSION=`grep "NSS_VMINOR" lib/nss/nss.h | awk '{print $3}'`
121 NSS_PATCH_VERSION=`grep "NSS_VPATCH" lib/nss/nss.h | awk '{print $3}'`
124 mkdir -p $out/lib/pkgconfig
125 sed -e "s,%prefix%,$PREFIX," \
126 -e "s,%exec_prefix%,$PREFIX," \
127 -e "s,%libdir%,$PREFIX/lib64," \
128 -e "s,%includedir%,$dev/include/nss," \
129 -e "s,%NSS_VERSION%,$NSS_MAJOR_VERSION.$NSS_MINOR_VERSION.$NSS_PATCH_VERSION,g" \
130 -e "s,%NSPR_VERSION%,4.16,g" \
131 pkg/pkg-config/nss.pc.in > $out/lib/pkgconfig/nss.pc
132 chmod 0644 $out/lib/pkgconfig/nss.pc
134 sed -e "s,@prefix@,$PREFIX," \
135 -e "s,@MOD_MAJOR_VERSION@,$NSS_MAJOR_VERSION," \
136 -e "s,@MOD_MINOR_VERSION@,$NSS_MINOR_VERSION," \
137 -e "s,@MOD_PATCH_VERSION@,$NSS_PATCH_VERSION," \
138 pkg/pkg-config/nss-config.in > $out/bin/nss-config
139 chmod 0755 $out/bin/nss-config
142 postInstall = lib.optionalString useP11kit ''
143 # Replace built-in trust with p11-kit connection
144 ln -sf ${p11-kit}/lib/pkcs11/p11-kit-trust.so $out/lib/libnssckbi.so
149 isCross = stdenv.hostPlatform != stdenv.buildPlatform;
150 nss = if isCross then buildPackages.nss.tools else "$out";
152 (lib.optionalString enableFIPS (''
153 for libname in freebl3 nssdbm3 softokn3
154 do libfile="$out/lib/lib$libname${stdenv.hostPlatform.extensions.sharedLibrary}"'' +
157 DYLD_LIBRARY_PATH=$out/lib:${nspr.out}/lib \
159 LD_LIBRARY_PATH=$out/lib:${nspr.out}/lib \
161 ${nss}/bin/shlibsign -v -i "$libfile"
165 moveToOutput bin "$tools"
166 moveToOutput bin/nss-config "$dev"
167 moveToOutput lib/libcrmf.a "$dev" # needed by firefox, for example
173 passthru.updateScript = ./update.sh;
175 passthru.tests = lib.optionalAttrs (lib.versionOlder version "3.69") {
176 inherit (nixosTests) firefox-esr-91;
177 } // lib.optionalAttrs (lib.versionAtLeast version "3.69") {
178 inherit (nixosTests) firefox firefox-esr-102;
182 homepage = "https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS";
183 description = "A set of libraries for development of security-enabled client and server applications";
184 changelog = "https://github.com/nss-dev/nss/blob/master/doc/rst/releases/nss_${underscoreVersion}.rst";
185 maintainers = with maintainers; [ hexa ajs124 ];
186 license = licenses.mpl20;
187 platforms = platforms.all;