nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 stdenv,
3 lib,
4 fetchurl,
5 autoPatchelfHook,
6 curl,
7 openssl,
8 versionCheckHook,
9 writeShellApplication,
10 common-updater-scripts,
11 gitMinimal,
12 jq,
13 nix-update,
14 pup,
15 nixosTests,
16}:
17
18stdenv.mkDerivation (finalAttrs: {
19 pname = "mongodb-ce";
20 version = "8.2.3";
21
22 src =
23 finalAttrs.passthru.sources.${stdenv.hostPlatform.system}
24 or (throw "Unsupported platform for mongodb-ce: ${stdenv.hostPlatform.system}");
25
26 nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ];
27 dontStrip = true;
28
29 buildInputs = [
30 curl.dev
31 openssl.dev
32 (lib.getLib stdenv.cc.cc)
33 ];
34
35 installPhase = ''
36 runHook preInstall
37
38 install -Dm 755 bin/mongod -t $out/bin
39 install -Dm 755 bin/mongos -t $out/bin
40
41 runHook postInstall
42 '';
43
44 # Only enable the version install check on darwin.
45 # On Linux, this would fail as mongod relies on tcmalloc, which
46 # requires access to `/sys/devices/system/cpu/possible`.
47 # See https://github.com/NixOS/nixpkgs/issues/377016
48 doInstallCheck = stdenv.hostPlatform.isDarwin;
49 nativeInstallCheckInputs = [ versionCheckHook ];
50 versionCheckProgram = "${placeholder "out"}/bin/mongod";
51
52 passthru = {
53 sources = {
54 "x86_64-linux" = fetchurl {
55 url = "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2404-${finalAttrs.version}.tgz";
56 hash = "sha256-NjPVLSqm5CPaG9/yOL7wEWW2rwFYcgCqwIZNk/ObYI8=";
57 };
58 "aarch64-linux" = fetchurl {
59 url = "https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-ubuntu2404-${finalAttrs.version}.tgz";
60 hash = "sha256-oVgHrXLjbc7XBrBr8QtChGfyfs+hCot4Dt9I/Qf9X3E=";
61 };
62 "x86_64-darwin" = fetchurl {
63 url = "https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-${finalAttrs.version}.tgz";
64 hash = "sha256-2jjP+vPAct+dcAn6RQLKrDyAsKQxj4kL+3XlDXfT1cQ=";
65 };
66 "aarch64-darwin" = fetchurl {
67 url = "https://fastdl.mongodb.org/osx/mongodb-macos-arm64-${finalAttrs.version}.tgz";
68 hash = "sha256-qUVQIeot2NO0ddrEW5jElu6HVyqiwTbR1S6KM2LJwV8=";
69 };
70 };
71 updateScript =
72 let
73 script = writeShellApplication {
74 name = "${finalAttrs.pname}-updateScript";
75
76 runtimeInputs = [
77 common-updater-scripts
78 curl
79 gitMinimal
80 jq
81 nix-update
82 pup
83 ];
84
85 text = ''
86 # Get latest version string from Github
87 NEW_VERSION=$(curl -s "https://api.github.com/repos/mongodb/mongo/tags?per_page=1000" | jq -r 'first(.[] | .name | select(startswith("r8.2")) | select(contains("rc") | not) | .[1:])')
88
89 # Check if the new version is available for download, if not, exit
90 curl -s https://www.mongodb.com/try/download/community-edition/releases | pup 'h3:not([id]) text{}' | grep "$NEW_VERSION"
91
92 if [[ "${finalAttrs.version}" = "$NEW_VERSION" ]]; then
93 echo "The new version same as the old version."
94 exit 0
95 fi
96
97 for platform in ${lib.escapeShellArgs finalAttrs.meta.platforms}; do
98 update-source-version "mongodb-ce" "$NEW_VERSION" --ignore-same-version --source-key="sources.$platform"
99 done
100 '';
101 };
102 in
103 {
104 command = lib.getExe script;
105 };
106
107 tests = {
108 inherit (nixosTests) mongodb-ce;
109 };
110 };
111
112 meta = {
113 changelog = "https://www.mongodb.com/docs/upcoming/release-notes/8.2/";
114 description = "MongoDB is a general purpose, document-based, distributed database";
115 homepage = "https://www.mongodb.com/";
116 license = with lib.licenses; [ sspl ];
117 longDescription = ''
118 MongoDB CE (Community Edition) is a general purpose, document-based, distributed database.
119 It is designed to be flexible and easy to use, with the ability to store data of any structure.
120 This pre-compiled binary distribution package provides the MongoDB daemon (mongod) and the MongoDB Shard utility
121 (mongos).
122 '';
123 maintainers = [ ];
124 platforms = lib.attrNames finalAttrs.passthru.sources;
125 sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
126 };
127})