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:
13 # [${package.fancyName}]
14 # Description = ${package.meta.description}
15 # Driver = ${package}/${package.driver}
19 psql = psqlodbc.override { withUnixODBC = true; withLibiodbc = false; };
21 mariadb = stdenv.mkDerivation rec {
22 pname = "mariadb-connector-odbc";
25 src = fetchFromGitHub {
26 owner = "mariadb-corporation";
27 repo = "mariadb-connector-odbc";
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;
36 # Fix `call to undeclared function 'sleep'` with clang 16
37 ./mariadb-connector-odbc-unistd.patch
40 nativeBuildInputs = [ cmake ];
41 buildInputs = [ unixODBC openssl libiconv zlib ]
42 ++ lib.optionals stdenv.hostPlatform.isDarwin [ libkrb5 ];
45 "-DWITH_EXTERNAL_ZLIB=ON"
46 "-DODBC_LIB_DIR=${lib.getLib unixODBC}/lib"
47 "-DODBC_INCLUDE_DIR=${lib.getDev unixODBC}/include"
49 # on darwin this defaults to ON but we want to build against unixODBC
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";
59 installTargets = if stdenv.hostPlatform.isDarwin then [ "install/fast" ] else null;
61 # see the top of the file for an explanation
63 fancyName = "MariaDB";
64 driver = "lib/libmaodbc${stdenv.hostPlatform.extensions.sharedLibrary}";
68 description = "MariaDB ODBC database driver";
69 homepage = "https://downloads.mariadb.org/connector-odbc/";
70 license = licenses.gpl2;
71 platforms = platforms.linux ++ platforms.darwin;
75 mysql = stdenv.mkDerivation rec {
76 pname = "mysql-connector-odbc";
78 version = "${majorVersion}.6";
81 url = "https://dev.mysql.com/get/Downloads/Connector-ODBC/${majorVersion}/${pname}-${version}-src.tar.gz";
82 sha256 = "1smi4z49i4zm7cmykjkwlxxzqvn7myngsw5bc35z6gqxmi8c55xr";
85 nativeBuildInputs = [ cmake ];
86 buildInputs = [ unixODBC mariadb ];
88 cmakeFlags = [ "-DWITH_UNIXODBC=1" ];
90 # see the top of the file for an explanation
93 driver = "lib/libmyodbc3-3.51.12.so";
97 description = "MySQL ODBC database driver";
98 homepage = "https://dev.mysql.com/downloads/connector/odbc/";
99 license = licenses.gpl2;
100 platforms = platforms.linux;
105 sqlite = stdenv.mkDerivation rec {
106 pname = "sqlite-connector-odbc";
110 url = "http://www.ch-werner.de/sqliteodbc/sqliteodbc-${version}.tar.gz";
111 sha256 = "0dgsj28sc7f7aprmdd0n5a1rmcx6pv7170c8dfjl0x1qsjxim6hs";
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
123 mv "$out"/*.* "$out/lib"
126 # see the top of the file for an explanation
128 fancyName = "SQLite";
129 driver = "lib/libsqlite3odbc.so";
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 ];
141 msodbcsql17 = stdenv.mkDerivation rec {
142 pname = "msodbcsql17";
143 version = "${versionMajor}.${versionMinor}.${versionAdditional}-1";
147 versionAdditional = "1.1";
150 url = "https://packages.microsoft.com/debian/10/prod/pool/main/m/msodbcsql17/msodbcsql${versionMajor}_${version}_amd64.deb";
151 sha256 = "0vwirnp56jibm3qf0kmi4jnz1w7xfhnsfr8imr0c9hg6av4sk3a6";
154 nativeBuildInputs = [ dpkg patchelf ];
156 unpackPhase = "dpkg -x $src ./";
162 cp -r opt/microsoft/msodbcsql${versionMajor}/lib64 opt/microsoft/msodbcsql${versionMajor}/share $out/
166 patchelf --set-rpath ${lib.makeLibraryPath [ unixODBC openssl libkrb5 libuuid stdenv.cc.cc ]} \
167 $out/lib/libmsodbcsql-${versionMajor}.${versionMinor}.so.${versionAdditional}
170 # see the top of the file for an explanation
172 fancyName = "ODBC Driver ${versionMajor} for SQL Server";
173 driver = "lib/libmsodbcsql-${versionMajor}.${versionMinor}.so.${versionAdditional}";
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 ];
187 msodbcsql18 = stdenv.mkDerivation(finalAttrs: {
188 pname = "msodbcsql${finalAttrs.versionMajor}";
189 version = "${finalAttrs.versionMajor}.${finalAttrs.versionMinor}.${finalAttrs.versionAdditional}${finalAttrs.versionSuffix}";
193 versionAdditional = "1.1";
194 versionSuffix = lib.optionalString stdenv.hostPlatform.isLinux "-1";
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}");
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}");
212 if stdenv.hostPlatform.isDarwin
215 # Fix up the names encoded into the dylib, and make them absolute.
224 unpackPhase = lib.optionalString stdenv.hostPlatform.isLinux ''
229 if stdenv.hostPlatform.isDarwin
233 tar xf $src --strip-components=1 -C $out
239 cp -r opt/microsoft/msodbcsql${finalAttrs.versionMajor}/lib64 opt/microsoft/msodbcsql${finalAttrs.versionMajor}/share $out/
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}
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}
255 # see the top of the file for an explanation
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}"}";
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 ];
271 redshift = stdenv.mkDerivation rec {
272 pname = "redshift-odbc";
273 version = "1.4.49.1000";
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=";
280 nativeBuildInputs = [ dpkg ];
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
292 cp opt/amazon/redshiftodbc/lib/64/* $out/lib
293 patchelf --set-rpath ${unixODBC}/lib/ $out/lib/libamazonredshiftodbc64.so
298 buildInputs = [ unixODBC ];
300 # see the top of the file for an explanation
302 fancyName = "Amazon Redshift (x64)";
303 driver = "lib/libamazonredshiftodbc64.so";
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 ];