generated from duckdb/extension-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
flake.nix
158 lines (151 loc) · 4.6 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
{
description = "Nix flake for the odbc_scanner duckdb extension";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
odbc-drivers.url = "github:rupurt/odbc-drivers-nix";
};
outputs = {
flake-utils,
nixpkgs,
odbc-drivers,
...
}: let
systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
outputs = flake-utils.lib.eachSystem systems (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [
odbc-drivers.overlay
];
};
stdenv = pkgs.llvmPackages_15.stdenv;
in rec {
# packages exported by the flake
packages = {
db2-odbc-driver = pkgs.db2-odbc-driver {};
postgres-odbc-driver = pkgs.postgres-odbc-driver {};
};
# nix run
apps = {
generate-dot-clangd = {
type = "app";
program = toString (pkgs.writeScript "generate-dot-clangd" ''
UNIX_ODBC_DIR=${pkgs.unixODBC} \
envsubst < ./templates/.clangd.template > .clangd
'');
};
generate-dot-clang-format = {
type = "app";
program = toString (pkgs.writeScript "generate-dot-clang-format" ''
cp ./templates/.clang-format.template .clang-format
'');
};
generate-odbc-ini = {
type = "app";
program = toString (pkgs.writeScript "generate-odbc-ini" ''
cp ./templates/.odbc.ini.template .odbc.ini
'');
};
generate-odbcinst-ini = {
type = "app";
program = toString (pkgs.writeScript "generate-odbcinst-ini" ''
DB2_DRIVER_PATH=${packages.db2-odbc-driver}/lib/${
if stdenv.isDarwin
then "libdb2.dylib"
else "libdb2.so"
} \
POSTGRES_DRIVER_PATH=${packages.postgres-odbc-driver}/lib/psqlodbca.so \
envsubst < ./templates/.odbcinst.ini.template > .odbcinst.ini
'');
};
ls-odbc-driver-paths = {
type = "app";
program = toString (pkgs.writeScript "ls-odbc-driver-paths" ''
echo "db2 ${packages.db2-odbc-driver}/lib/${
if stdenv.isDarwin
then "libdb2.dylib"
else "libdb2.so"
}"
echo "postgres ${packages.postgres-odbc-driver}/lib/psqlodbca.so"
'');
};
load-db2-schema = {
type = "app";
program = toString (pkgs.writeScript "load-db2-schema" ''
echo "TODO: load db2 schema"
'');
};
test = {
type = "app";
program = toString (pkgs.writeScript "test" ''
export PATH="${pkgs.lib.makeBinPath (
with pkgs; [
git
gnumake
cmake
ninja
openssl
packages.db2-odbc-driver
packages.postgres-odbc-driver
]
)}:$PATH"
export CC=${stdenv.cc}/bin/clang
export CXX=${stdenv.cc}/bin/clang++
make \
GEN=ninja \
ODBCSYSINI=$PWD \
ODBCINSTINI=.odbcinst.ini \
ODBCINI=$PWD/.odbc.ini \
test CLIENT_FLAGS="-DODBC_CONFIG=${pkgs.unixODBC}/bin/odbc_config"
'');
};
build = {
type = "app";
program = toString (pkgs.writeScript "build" ''
export PATH="${pkgs.lib.makeBinPath (
with pkgs; [
git
gnumake
cmake
ninja
openssl
packages.db2-odbc-driver
packages.postgres-odbc-driver
]
)}:$PATH"
export CC=${stdenv.cc}/bin/clang
export CXX=${stdenv.cc}/bin/clang++
make \
GEN=ninja \
CLIENT_FLAGS="-DODBC_CONFIG=${pkgs.unixODBC}/bin/odbc_config"
'');
};
default = apps.build;
};
# nix fmt
formatter = pkgs.alejandra;
# nix develop -c $SHELL
devShells.default = pkgs.mkShell {
packages = [
pkgs.git
pkgs.gnumake
pkgs.cmake
# faster cmake builds
pkgs.ninja
# clangd lsp
pkgs.llvmPackages_15.bintools
pkgs.llvmPackages_15.clang
pkgs.envsubst
pkgs.openssl
pkgs.unixODBC
# psql cli
pkgs.postgresql_15
packages.db2-odbc-driver
packages.postgres-odbc-driver
];
};
});
in
outputs;
}