nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchurl,
5 dpkg,
6 unzip,
7 wrapGAppsHook3,
8 makeWrapper,
9 runtimeShell,
10 gtk3,
11 libxtst,
12 libxscrnsaver,
13 libxrender,
14 libxrandr,
15 libxi,
16 libxfixes,
17 libxext,
18 libxdamage,
19 libxcursor,
20 libxcomposite,
21 libx11,
22 libxshmfence,
23 libxkbfile,
24 glib,
25 cairo,
26 pango,
27 dbus,
28 cups,
29 at-spi2-atk,
30 at-spi2-core,
31 atk,
32 libdrm,
33 gdk-pixbuf,
34 nss,
35 nspr,
36 alsa-lib,
37 expat,
38 libxkbcommon,
39 libgbm,
40 vulkan-loader,
41 systemd,
42 libGL,
43 krb5,
44 fontconfig,
45 freetype,
46 libnotify,
47 libsecret,
48 libuuid,
49 libxcb,
50 patchelf,
51}:
52
53let
54 pname = "mongodb-compass";
55 version = "1.49.1";
56
57 selectSystem =
58 attrs:
59 attrs.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
60
61 src = fetchurl {
62 url = "https://downloads.mongodb.com/compass/${
63 selectSystem {
64 x86_64-linux = "mongodb-compass_${version}_amd64.deb";
65 x86_64-darwin = "mongodb-compass-${version}-darwin-x64.zip";
66 aarch64-darwin = "mongodb-compass-${version}-darwin-arm64.zip";
67 }
68 }";
69 hash = selectSystem {
70 x86_64-linux = "sha256-6wjwV6KViRJiJiS+Cc3+sjLjKm/K7dGHUHAx9u5Rngk=";
71 x86_64-darwin = "sha256-v4lxvKMcLabMfshpBD4PqCXcyf/cJz+kn6qKIfLruNc=";
72 aarch64-darwin = "sha256-7FmRgA+5qHUiozGGlzGM/gWffzcpHwiOY52yGKvH5GY=";
73 };
74 };
75
76 appName = "MongoDB Compass.app";
77
78 rpath = lib.makeLibraryPath [
79 alsa-lib
80 at-spi2-atk
81 at-spi2-core
82 atk
83 cairo
84 cups
85 dbus
86 expat
87 fontconfig
88 freetype
89 gdk-pixbuf
90 glib
91 gtk3
92 libdrm
93 libGL
94 libnotify
95 libsecret
96 libuuid
97 libxcb
98 libxkbcommon
99 libgbm
100 nspr
101 nss
102 pango
103 stdenv.cc.cc
104 systemd
105 libx11
106 libxscrnsaver
107 libxcomposite
108 libxcursor
109 libxdamage
110 libxext
111 libxfixes
112 libxi
113 libxrandr
114 libxrender
115 libxtst
116 libxkbfile
117 libxshmfence
118 (lib.getLib stdenv.cc.cc)
119 ];
120in
121stdenv.mkDerivation (finalAttrs: {
122 inherit pname version src;
123
124 buildInputs = lib.optionals stdenv.hostPlatform.isLinux [
125 dpkg
126 wrapGAppsHook3
127 patchelf
128 ];
129
130 nativeBuildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ unzip ];
131
132 dontUnpack = stdenv.hostPlatform.isLinux;
133 dontFixup = stdenv.hostPlatform.isDarwin;
134 sourceRoot = lib.optionalString stdenv.hostPlatform.isDarwin appName;
135
136 buildCommand = lib.optionalString stdenv.hostPlatform.isLinux ''
137 IFS=$'\n'
138
139 # The deb file contains a setuid binary, so 'dpkg -x' doesn't work here
140 dpkg --fsys-tarfile $src | tar --extract
141
142 mkdir -p $out
143 mv usr/* $out
144
145 rm -rf $out/share/lintian
146
147 # The node_modules are bringing in non-linux files/dependencies
148 find $out -name "*.app" -exec rm -rf {} \; || true
149 find $out -name "*.dll" -delete
150 find $out -name "*.exe" -delete
151
152 # Otherwise it looks "suspicious"
153 chmod -R g-w $out
154
155 for file in `find $out -type f -perm /0111 -o -name \*.so\*`; do
156 echo "Manipulating file: $file"
157 patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" "$file" || true
158 patchelf --set-rpath ${rpath}:$out/lib/mongodb-compass "$file" || true
159 done
160
161 wrapGAppsHook $out/bin/mongodb-compass
162 '';
163
164 installPhase = ''
165 runHook preInstall
166
167 ${lib.optionalString stdenv.hostPlatform.isDarwin ''
168 # Create directories for the application bundle and the launcher script.
169 mkdir -p "$out/Applications/${appName}" "$out/bin"
170
171 # Copy the unzipped app bundle into the Applications folder.
172 cp -R . "$out/Applications/${appName}"
173
174 # Create a launcher script that opens the app.
175 cat > "$out/bin/${pname}" << EOF
176 #!${runtimeShell}
177 open -na "$out/Applications/${appName}" --args "\$@"
178 EOF
179 chmod +x "$out/bin/${pname}"
180 ''}
181
182 runHook postInstall
183 '';
184
185 passthru.updateScript = ./update.sh;
186
187 meta = {
188 description = "GUI for MongoDB";
189 homepage = "https://github.com/mongodb-js/compass";
190 license = lib.licenses.sspl;
191 sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
192 mainProgram = "mongodb-compass";
193 maintainers = with lib.maintainers; [
194 friedow
195 iamanaws
196 ];
197 platforms = [
198 "x86_64-linux"
199 "aarch64-darwin"
200 "x86_64-darwin"
201 ];
202 };
203})