|
| 1 | +{ lib |
| 2 | +, stdenv |
| 3 | +, fetchurl |
| 4 | +, sconsPackages |
| 5 | +, boost |
| 6 | +, gperftools |
| 7 | +, pcre-cpp |
| 8 | +, snappy |
| 9 | +, zlib |
| 10 | +, yaml-cpp |
| 11 | +, sasl |
| 12 | +, openssl |
| 13 | +, libpcap |
| 14 | +, python3 |
| 15 | +, curl |
| 16 | +, Security |
| 17 | +, CoreFoundation |
| 18 | +, cctools |
| 19 | +, xz |
| 20 | +}: |
| 21 | + |
| 22 | +# Note: |
| 23 | +# The command line administrative tools are part of other packages: |
| 24 | +# see pkgs.mongodb-tools and pkgs.mongosh. |
| 25 | + |
| 26 | +with lib; |
| 27 | + |
| 28 | +{ version, sha256, patches ? [] |
| 29 | +, license ? lib.licenses.sspl |
| 30 | +}: |
| 31 | + |
| 32 | +let |
| 33 | + variants = |
| 34 | + if versionAtLeast version "6.0" then rec { |
| 35 | + python = scons.python.withPackages (ps: with ps; [ |
| 36 | + pyyaml |
| 37 | + cheetah3 |
| 38 | + psutil |
| 39 | + setuptools |
| 40 | + packaging |
| 41 | + pymongo |
| 42 | + ]); |
| 43 | + |
| 44 | + scons = sconsPackages.scons_3_1_2; |
| 45 | + |
| 46 | + mozjsVersion = "60"; |
| 47 | + mozjsReplace = "defined(HAVE___SINCOS)"; |
| 48 | + |
| 49 | + } else rec { |
| 50 | + python = scons.python.withPackages (ps: with ps; [ |
| 51 | + pyyaml |
| 52 | + cheetah3 |
| 53 | + psutil |
| 54 | + setuptools |
| 55 | + ]); |
| 56 | + |
| 57 | + scons = sconsPackages.scons_3_1_2; |
| 58 | + |
| 59 | + mozjsVersion = "60"; |
| 60 | + mozjsReplace = "defined(HAVE___SINCOS)"; |
| 61 | + |
| 62 | + }; |
| 63 | + |
| 64 | + system-libraries = [ |
| 65 | + "boost" |
| 66 | + "pcre" |
| 67 | + "snappy" |
| 68 | + "yaml" |
| 69 | + "zlib" |
| 70 | + #"asio" -- XXX use package? |
| 71 | + #"stemmer" -- not nice to package yet (no versioning, no makefile, no shared libs). |
| 72 | + #"valgrind" -- mongodb only requires valgrind.h, which is vendored in the source. |
| 73 | + #"wiredtiger" |
| 74 | + ] ++ optionals stdenv.isLinux [ "tcmalloc" ]; |
| 75 | + inherit (lib) systems subtractLists; |
| 76 | + |
| 77 | +in stdenv.mkDerivation rec { |
| 78 | + inherit version; |
| 79 | + pname = "mongodb"; |
| 80 | + |
| 81 | + src = fetchurl { |
| 82 | + url = "https://fastdl.mongodb.org/src/mongodb-src-r${version}.tar.gz"; |
| 83 | + inherit sha256; |
| 84 | + }; |
| 85 | + |
| 86 | + nativeBuildInputs = [ variants.scons ] |
| 87 | + ++ lib.optionals (versionAtLeast version "4.4") [ xz ]; |
| 88 | + |
| 89 | + buildInputs = [ |
| 90 | + boost |
| 91 | + curl |
| 92 | + gperftools |
| 93 | + libpcap |
| 94 | + yaml-cpp |
| 95 | + openssl |
| 96 | + pcre-cpp |
| 97 | + variants.python |
| 98 | + sasl |
| 99 | + snappy |
| 100 | + zlib |
| 101 | + ] ++ lib.optionals stdenv.isDarwin [ Security CoreFoundation cctools ]; |
| 102 | + |
| 103 | + # MongoDB keeps track of its build parameters, which tricks nix into |
| 104 | + # keeping dependencies to build inputs in the final output. |
| 105 | + # We remove the build flags from buildInfo data. |
| 106 | + inherit patches; |
| 107 | + |
| 108 | + postPatch = '' |
| 109 | + # fix environment variable reading |
| 110 | + substituteInPlace SConstruct \ |
| 111 | + --replace "env = Environment(" "env = Environment(ENV = os.environ," |
| 112 | + '' + lib.optionalString (versionAtLeast version "4.4") '' |
| 113 | + # Fix debug gcc 11 and clang 12 builds on Fedora |
| 114 | + # https://github.com/mongodb/mongo/commit/e78b2bf6eaa0c43bd76dbb841add167b443d2bb0.patch |
| 115 | + substituteInPlace src/mongo/db/query/plan_summary_stats.h --replace '#include <string>' '#include <optional> |
| 116 | + #include <string>' |
| 117 | + substituteInPlace src/mongo/db/exec/plan_stats.h --replace '#include <string>' '#include <optional> |
| 118 | + #include <string>' |
| 119 | + '' + lib.optionalString (versionOlder version "5.0") '' |
| 120 | + # remove -march overriding, we know better. |
| 121 | + sed -i 's/env.Append.*-march=.*$/pass/' SConstruct |
| 122 | + '' + lib.optionalString (stdenv.isDarwin && versionOlder version "6.0") '' |
| 123 | + substituteInPlace src/third_party/mozjs-${variants.mozjsVersion}/extract/js/src/jsmath.cpp --replace '${variants.mozjsReplace}' 0 |
| 124 | + '' + lib.optionalString (stdenv.isDarwin && versionOlder version "3.6") '' |
| 125 | + substituteInPlace src/third_party/s2/s1angle.cc --replace drem remainder |
| 126 | + substituteInPlace src/third_party/s2/s1interval.cc --replace drem remainder |
| 127 | + substituteInPlace src/third_party/s2/s2cap.cc --replace drem remainder |
| 128 | + substituteInPlace src/third_party/s2/s2latlng.cc --replace drem remainder |
| 129 | + substituteInPlace src/third_party/s2/s2latlngrect.cc --replace drem remainder |
| 130 | + '' + lib.optionalString stdenv.isi686 '' |
| 131 | +
|
| 132 | + # don't fail by default on i686 |
| 133 | + substituteInPlace src/mongo/db/storage/storage_options.h \ |
| 134 | + --replace 'engine("wiredTiger")' 'engine("mmapv1")' |
| 135 | + ''; |
| 136 | + |
| 137 | + env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang |
| 138 | + "-Wno-unused-command-line-argument"; |
| 139 | + |
| 140 | + sconsFlags = [ |
| 141 | + "--release" |
| 142 | + "--ssl" |
| 143 | + #"--rocksdb" # Don't have this packaged yet |
| 144 | + "--wiredtiger=on" |
| 145 | + "--js-engine=mozjs" |
| 146 | + "--use-sasl-client" |
| 147 | + "--disable-warnings-as-errors" |
| 148 | + "VARIANT_DIR=nixos" # Needed so we don't produce argument lists that are too long for gcc / ld |
| 149 | + ] ++ lib.optionals (versionAtLeast version "4.4") [ "--link-model=static" ] |
| 150 | + ++ map (lib: "--use-system-${lib}") system-libraries; |
| 151 | + |
| 152 | + preBuild = '' |
| 153 | + sconsFlags+=" CC=$CC" |
| 154 | + sconsFlags+=" CXX=$CXX" |
| 155 | + '' + optionalString stdenv.isAarch64 '' |
| 156 | + sconsFlags+=" CCFLAGS='-march=armv8-a+crc'" |
| 157 | + ''; |
| 158 | + |
| 159 | + preInstall = '' |
| 160 | + mkdir -p "$out/lib" |
| 161 | + ''; |
| 162 | + |
| 163 | + postInstall = '' |
| 164 | + rm -f "$out/bin/install_compass" || true |
| 165 | + ''; |
| 166 | + |
| 167 | + doInstallCheck = true; |
| 168 | + installCheckPhase = '' |
| 169 | + runHook preInstallCheck |
| 170 | + "$out/bin/mongo" --version |
| 171 | + runHook postInstallCheck |
| 172 | + ''; |
| 173 | + |
| 174 | + installTargets = |
| 175 | + if (versionAtLeast version "6.0") then "install-devcore" |
| 176 | + else if (versionAtLeast version "4.4") then "install-core" |
| 177 | + else "install"; |
| 178 | + |
| 179 | + prefixKey = if (versionAtLeast version "4.4") then "DESTDIR=" else "--prefix="; |
| 180 | + |
| 181 | + enableParallelBuilding = true; |
| 182 | + |
| 183 | + hardeningEnable = [ "pie" ]; |
| 184 | + |
| 185 | + meta = { |
| 186 | + description = "A scalable, high-performance, open source NoSQL database"; |
| 187 | + homepage = "http://www.mongodb.org"; |
| 188 | + inherit license; |
| 189 | + |
| 190 | + maintainers = with maintainers; [ bluescreen303 offline cstrahan ]; |
| 191 | + platforms = subtractLists systems.doubles.i686 systems.doubles.unix; |
| 192 | + broken = (versionOlder version "6.0" && stdenv.system == "aarch64-darwin"); |
| 193 | + }; |
| 194 | +} |
0 commit comments