forgejo-lts: 7.0.10 -> 7.0.11
[NixPkgs.git] / pkgs / development / libraries / unixODBCDrivers / default.nix
blobb5b7e78e32a6b98a2b5cd30ee5637d2e940761b4
1 { fetchurl, stdenv, unixODBC, cmake, mariadb, sqlite, zlib, libxml2, dpkg, lib, openssl, libkrb5, libuuid, patchelf, libiconv, fixDarwinDylibNames, fetchFromGitHub, psqlodbc }:
3 # Each of these ODBC drivers can be configured in your odbcinst.ini file using
4 # the various passthru and meta values. Of note are:
6 #   * `passthru.fancyName`, the typical name used to reference the driver
7 #   * `passthru.driver`, the path to the driver within the built package
8 #   * `meta.description`, a short description of the ODBC driver
10 # For example, you might generate it as follows:
12 # ''
13 # [${package.fancyName}]
14 # Description = ${package.meta.description}
15 # Driver = ${package}/${package.driver}
16 # ''
19   psql = psqlodbc.override { withUnixODBC = true; withLibiodbc = false; };
21   mariadb = stdenv.mkDerivation rec {
22     pname = "mariadb-connector-odbc";
23     version = "3.1.20";
25     src = fetchFromGitHub {
26       owner = "mariadb-corporation";
27       repo = "mariadb-connector-odbc";
28       rev = version;
29       hash = "sha256-l+HlS7/A0shwsEXYKDhi+QCmwHaMTeKrtcvo9yYpYws=";
30       # this driver only seems to build correctly when built against the mariadb-connect-c subrepo
31       # (see https://github.com/NixOS/nixpkgs/issues/73258)
32       fetchSubmodules = true;
33     };
35     patches = [
36       # Fix `call to undeclared function 'sleep'` with clang 16
37       ./mariadb-connector-odbc-unistd.patch
38     ];
40     nativeBuildInputs = [ cmake ];
41     buildInputs = [ unixODBC openssl libiconv zlib ]
42       ++ lib.optionals stdenv.hostPlatform.isDarwin [ libkrb5 ];
44     cmakeFlags = [
45       "-DWITH_EXTERNAL_ZLIB=ON"
46       "-DODBC_LIB_DIR=${lib.getLib unixODBC}/lib"
47       "-DODBC_INCLUDE_DIR=${lib.getDev unixODBC}/include"
48       "-DWITH_OPENSSL=ON"
49       # on darwin this defaults to ON but we want to build against unixODBC
50       "-DWITH_IODBC=OFF"
51     ];
53     buildFlags = if stdenv.hostPlatform.isDarwin then [ "maodbc" ] else null;
55     env = lib.optionalAttrs stdenv.cc.isGNU {
56       NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-pointer-types";
57     };
59     installTargets = if stdenv.hostPlatform.isDarwin then [ "install/fast" ] else null;
61     # see the top of the file for an explanation
62     passthru = {
63       fancyName = "MariaDB";
64       driver = "lib/libmaodbc${stdenv.hostPlatform.extensions.sharedLibrary}";
65     };
67     meta = with lib; {
68       description = "MariaDB ODBC database driver";
69       homepage = "https://downloads.mariadb.org/connector-odbc/";
70       license = licenses.gpl2;
71       platforms = platforms.linux ++ platforms.darwin;
72     };
73   };
75   mysql = stdenv.mkDerivation rec {
76     pname = "mysql-connector-odbc";
77     majorVersion = "5.3";
78     version = "${majorVersion}.6";
80     src = fetchurl {
81       url = "https://dev.mysql.com/get/Downloads/Connector-ODBC/${majorVersion}/${pname}-${version}-src.tar.gz";
82       sha256 = "1smi4z49i4zm7cmykjkwlxxzqvn7myngsw5bc35z6gqxmi8c55xr";
83     };
85     nativeBuildInputs = [ cmake ];
86     buildInputs = [ unixODBC mariadb ];
88     cmakeFlags = [ "-DWITH_UNIXODBC=1" ];
90     # see the top of the file for an explanation
91     passthru = {
92       fancyName = "MySQL";
93       driver = "lib/libmyodbc3-3.51.12.so";
94     };
96     meta = with lib; {
97       description = "MySQL ODBC database driver";
98       homepage = "https://dev.mysql.com/downloads/connector/odbc/";
99       license = licenses.gpl2;
100       platforms = platforms.linux;
101       broken = true;
102     };
103   };
105   sqlite = stdenv.mkDerivation rec {
106     pname = "sqlite-connector-odbc";
107     version = "0.9993";
109     src = fetchurl {
110       url = "http://www.ch-werner.de/sqliteodbc/sqliteodbc-${version}.tar.gz";
111       sha256 = "0dgsj28sc7f7aprmdd0n5a1rmcx6pv7170c8dfjl0x1qsjxim6hs";
112     };
114     buildInputs = [ unixODBC sqlite zlib libxml2 ];
116     configureFlags = [ "--with-odbc=${unixODBC}" "--with-sqlite3=${sqlite.dev}" ];
118     installTargets = [ "install-3" ];
120     # move libraries to $out/lib where they're expected to be
121     postInstall = ''
122       mkdir -p "$out/lib"
123       mv "$out"/*.* "$out/lib"
124     '';
126     # see the top of the file for an explanation
127     passthru = {
128       fancyName = "SQLite";
129       driver = "lib/libsqlite3odbc.so";
130     };
132     meta = with lib; {
133       description = "ODBC driver for SQLite";
134       homepage = "http://www.ch-werner.de/sqliteodbc";
135       license = licenses.bsd2;
136       platforms = platforms.unix;
137       maintainers = with maintainers; [ vlstill ];
138     };
139   };
141   msodbcsql17 = stdenv.mkDerivation rec {
142     pname = "msodbcsql17";
143     version = "${versionMajor}.${versionMinor}.${versionAdditional}-1";
145     versionMajor = "17";
146     versionMinor = "7";
147     versionAdditional = "1.1";
149     src = fetchurl {
150       url = "https://packages.microsoft.com/debian/10/prod/pool/main/m/msodbcsql17/msodbcsql${versionMajor}_${version}_amd64.deb";
151       sha256 = "0vwirnp56jibm3qf0kmi4jnz1w7xfhnsfr8imr0c9hg6av4sk3a6";
152     };
154     nativeBuildInputs = [ dpkg patchelf ];
156     unpackPhase = "dpkg -x $src ./";
157     buildPhase = "";
159     installPhase = ''
160       mkdir -p $out
161       mkdir -p $out/lib
162       cp -r opt/microsoft/msodbcsql${versionMajor}/lib64 opt/microsoft/msodbcsql${versionMajor}/share $out/
163     '';
165     postFixup = ''
166       patchelf --set-rpath ${lib.makeLibraryPath [ unixODBC openssl libkrb5 libuuid stdenv.cc.cc ]} \
167         $out/lib/libmsodbcsql-${versionMajor}.${versionMinor}.so.${versionAdditional}
168     '';
170     # see the top of the file for an explanation
171     passthru = {
172       fancyName = "ODBC Driver ${versionMajor} for SQL Server";
173       driver = "lib/libmsodbcsql-${versionMajor}.${versionMinor}.so.${versionAdditional}";
174     };
176     meta = with lib; {
177       broken = stdenv.hostPlatform.isDarwin;
178       description = "ODBC Driver ${versionMajor} for SQL Server";
179       homepage = "https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017";
180       sourceProvenance = with sourceTypes; [ binaryNativeCode ];
181       license = licenses.unfree;
182       platforms = platforms.linux;
183       maintainers = with maintainers; [ spencerjanssen ];
184     };
185   };
187   msodbcsql18 = stdenv.mkDerivation(finalAttrs: {
188     pname = "msodbcsql${finalAttrs.versionMajor}";
189     version = "${finalAttrs.versionMajor}.${finalAttrs.versionMinor}.${finalAttrs.versionAdditional}${finalAttrs.versionSuffix}";
191     versionMajor = "18";
192     versionMinor = "1";
193     versionAdditional = "1.1";
194     versionSuffix = lib.optionalString stdenv.hostPlatform.isLinux "-1";
196     src = fetchurl {
197       url = {
198         x86_64-linux = "https://packages.microsoft.com/debian/11/prod/pool/main/m/msodbcsql${finalAttrs.versionMajor}/msodbcsql${finalAttrs.versionMajor}_${finalAttrs.version}_amd64.deb";
199         aarch64-linux = "https://packages.microsoft.com/debian/11/prod/pool/main/m/msodbcsql${finalAttrs.versionMajor}/msodbcsql${finalAttrs.versionMajor}_${finalAttrs.version}_arm64.deb";
200         x86_64-darwin = "https://download.microsoft.com/download/6/4/0/64006503-51e3-44f0-a6cd-a9b757d0d61b/msodbcsql${finalAttrs.versionMajor}-${finalAttrs.version}-amd64.tar.gz";
201         aarch64-darwin = "https://download.microsoft.com/download/6/4/0/64006503-51e3-44f0-a6cd-a9b757d0d61b/msodbcsql${finalAttrs.versionMajor}-${finalAttrs.version}-arm64.tar.gz";
202       }.${stdenv.system} or (throw "Unsupported system: ${stdenv.system}");
203       hash = {
204         x86_64-linux = "sha256:1f0rmh1aynf1sqmjclbsyh2wz5jby0fixrwz71zp6impxpwvil52";
205         aarch64-linux = "sha256:0zphnbvkqdbkcv6lvv63p7pyl68h5bs2dy6vv44wm6bi89svms4a";
206         x86_64-darwin = "sha256:1fn80byn1yihflznxcm9cpj42mpllnz54apnk9n46vzm2ng2lj6d";
207         aarch64-darwin = "sha256:116xl8r2apr5b48jnq6myj9fwqs88yccw5176yfyzh4534fznj5x";
208       }.${stdenv.system} or (throw "Unsupported system: ${stdenv.system}");
209     };
211     nativeBuildInputs =
212       if stdenv.hostPlatform.isDarwin
213       then
214         [
215           # Fix up the names encoded into the dylib, and make them absolute.
216           fixDarwinDylibNames
217         ]
218       else
219         [
220           dpkg
221           patchelf
222         ];
224     unpackPhase = lib.optionalString stdenv.hostPlatform.isLinux ''
225       dpkg -x $src ./
226     '';
228     installPhase =
229       if stdenv.hostPlatform.isDarwin
230       then
231         ''
232           mkdir -p $out
233           tar xf $src --strip-components=1 -C $out
234         ''
235       else
236         ''
237           mkdir -p $out
238           mkdir -p $out/lib
239           cp -r opt/microsoft/msodbcsql${finalAttrs.versionMajor}/lib64 opt/microsoft/msodbcsql${finalAttrs.versionMajor}/share $out/
240         '';
242     # Replace the hard-coded paths in the dylib with nixpkgs equivalents.
243     fixupPhase = lib.optionalString stdenv.hostPlatform.isDarwin ''
244       ${stdenv.cc.bintools.targetPrefix}install_name_tool \
245         -change /usr/lib/libiconv.2.dylib ${libiconv}/lib/libiconv.2.dylib \
246         -change /opt/homebrew/lib/libodbcinst.2.dylib ${unixODBC}/lib/libodbcinst.2.dylib \
247         $out/${finalAttrs.passthru.driver}
248     '';
250     postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
251       patchelf --set-rpath ${lib.makeLibraryPath [ unixODBC openssl libkrb5 libuuid stdenv.cc.cc ]} \
252         $out/${finalAttrs.passthru.driver}
253     '';
255     # see the top of the file for an explanation
256     passthru = {
257       fancyName = "ODBC Driver ${finalAttrs.versionMajor} for SQL Server";
258       driver = "lib/libmsodbcsql${if stdenv.hostPlatform.isDarwin then ".${finalAttrs.versionMajor}.dylib" else "-${finalAttrs.versionMajor}.${finalAttrs.versionMinor}.so.${finalAttrs.versionAdditional}"}";
259     };
261     meta = with lib; {
262       description = finalAttrs.passthru.fancyName;
263       homepage = "https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver16";
264       sourceProvenance = with sourceTypes; [ binaryNativeCode ];
265       platforms = platforms.unix;
266       license = licenses.unfree;
267       maintainers = with maintainers; [ SamirTalwar ];
268     };
269   });
271   redshift = stdenv.mkDerivation rec {
272     pname = "redshift-odbc";
273     version = "1.4.49.1000";
275     src = fetchurl {
276       url = "https://s3.amazonaws.com/redshift-downloads/drivers/odbc/${version}/AmazonRedshiftODBC-64-bit-${version}-1.x86_64.deb";
277       sha256 = "sha256-r5HvsZjB7+x+ClxtWoONkE1/NAbz90NbHfzxC6tf7jA=";
278     };
280     nativeBuildInputs = [ dpkg ];
282     unpackPhase = ''
283       dpkg -x $src src
284       cd src
285     '';
287     # `unixODBC` is loaded with `dlopen`, so `autoPatchElfHook` cannot see it, and `patchELF` phase would strip the manual patchelf. Thus:
288     # - Manually patchelf with `unixODCB` libraries
289     # - Disable automatic `patchELF` phase
290     installPhase = ''
291       mkdir -p $out/lib
292       cp opt/amazon/redshiftodbc/lib/64/* $out/lib
293       patchelf --set-rpath ${unixODBC}/lib/ $out/lib/libamazonredshiftodbc64.so
294     '';
296     dontPatchELF = true;
298     buildInputs = [ unixODBC ];
300     # see the top of the file for an explanation
301     passthru = {
302       fancyName = "Amazon Redshift (x64)";
303       driver = "lib/libamazonredshiftodbc64.so";
304     };
306     meta = with lib; {
307       broken = stdenv.hostPlatform.isDarwin;
308       description = "Amazon Redshift ODBC driver";
309       homepage = "https://docs.aws.amazon.com/redshift/latest/mgmt/configure-odbc-connection.html";
310       sourceProvenance = with sourceTypes; [ binaryNativeCode ];
311       license = licenses.unfree;
312       platforms = platforms.linux;
313       maintainers = with maintainers; [ sir4ur0n ];
314     };
315   };