Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
251 lines (227 loc) · 7.62 KB
/
Copy pathflake.nix
File metadata and controls
251 lines (227 loc) · 7.62 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
{
description = "Optional development environment for SQLPage";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# Ships the official rustup binaries, so the toolchain in this shell is
# the same build CI and the release use, down to the bundled LLVM.
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
{
self,
nixpkgs,
rust-overlay,
}:
let
inherit (nixpkgs) lib;
systems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-linux"
];
# Oracle governs its own client library by licence, so nixpkgs marks it
# unfree. Naming it here keeps every other package in this flake free.
unfreePackages = [ "oracle-instantclient" ];
forEachSystem =
build:
lib.genAttrs systems (
system:
build (
import nixpkgs {
inherit system;
config.allowUnfreePredicate = package: builtins.elem (lib.getName package) unfreePackages;
overlays = [ rust-overlay.overlays.default ];
}
)
);
cargoEdition = (lib.importTOML ./Cargo.toml).package.edition;
lockedPlaywrightVersion =
(lib.importJSON ./package-lock.json).packages."node_modules/playwright-core".version;
formatterFor =
pkgs:
pkgs.treefmt.withConfig {
runtimeInputs = [
pkgs.biome
pkgs.nixfmt
pkgs.rustfmt
];
settings = {
on-unmatched = "info";
formatter = {
nixfmt = {
command = "nixfmt";
includes = [ "*.nix" ];
};
rustfmt = {
command = "rustfmt";
options = [
"--edition"
cargoEdition
];
includes = [ "*.rs" ];
};
biome = {
command = "biome";
options = [
"format"
"--write"
"--no-errors-on-unmatched"
];
includes = [
"*.css"
"*.js"
"*.json"
"*.jsonc"
"*.mjs"
"*.ts"
];
};
};
};
};
rustToolchainFor = pkgs: pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
# odbc-sys links against a driver manager, and the C sources vendored by
# aws-lc-sys, libsqlite3-sys and zstd-sys need a compiler. Nothing here
# reaches for OpenSSL: SQLPage speaks TLS through rustls.
cargoRuntime = pkgs: [
(rustToolchainFor pkgs)
pkgs.stdenv.cc
pkgs.unixodbc
];
# The database matrix runs prebuilt test binaries that link the unixODBC
# driver manager statically. It still reads ODBCSYSINI at run time and
# dlopens whatever absolute path this file names, so pointing that one
# variable at the store replaces every driver install step.
odbcDriversFor =
pkgs:
pkgs.runCommand "sqlpage-odbc-drivers" { } ''
mkdir -p "$out"
oracleDriver=(${lib.getLib pkgs.oracle-instantclient}/lib/libsqora.so.*)
cat > "$out/odbcinst.ini" <<INI
[PostgreSQL Unicode]
Driver = ${pkgs.unixodbcDrivers.psql}/${pkgs.unixodbcDrivers.psql.driver}
[Oracle 21 ODBC driver]
Driver = ''${oracleDriver[0]}
INI
'';
cargoEnv = pkgs: {
LIBRARY_PATH = "${pkgs.unixodbc}/lib";
};
# Playwright is installed via npm, we we need to set the browser paths.
playwrightEnv = pkgs: {
PLAYWRIGHT_BROWSERS_PATH = "${pkgs.playwright-driver.browsers}";
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = "1";
PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = "true";
};
gatesFor =
pkgs:
lib.mapAttrs
(
name:
{
description,
packages ? [ ],
env ? { },
script,
}:
pkgs.writeShellApplication {
inherit name;
runtimeInputs = [ pkgs.git ] ++ packages;
runtimeEnv = env;
meta = { inherit description; };
text = ''
cd "$(git rev-parse --show-toplevel)"
''
+ script;
}
)
{
lint-rust = {
description = "Check Rust formatting and deny every clippy warning";
packages = cargoRuntime pkgs;
env = cargoEnv pkgs;
script = ''
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
'';
};
test-rust = {
description = "Run the Rust test suites against DATABASE_URL, or SQLite when it is unset";
packages = cargoRuntime pkgs;
env = cargoEnv pkgs;
script = ''
cargo test "$@"
'';
};
test-browser = {
description = "Drive the components in a browser with Playwright";
packages = [ pkgs.nodejs_26 ] ++ cargoRuntime pkgs;
env = cargoEnv pkgs // playwrightEnv pkgs;
script = ''
npm ci --ignore-scripts
npm run build
cd tests/end-to-end
npx playwright test "$@"
'';
};
test-examples = {
description = "Run the Hurl suite of an example against its own containers";
packages = [ pkgs.hurl ];
script = ''
scripts/test-examples-hurl.sh "$@"
'';
};
};
in
{
packages = forEachSystem (pkgs: {
odbc-drivers = odbcDriversFor pkgs;
});
formatter = forEachSystem formatterFor;
checks = forEachSystem (pkgs: {
formatting = (formatterFor pkgs).check self;
});
apps = forEachSystem (
pkgs:
lib.mapAttrs (_: gate: {
type = "app";
program = lib.getExe gate;
inherit (gate) meta;
}) (gatesFor pkgs)
);
devShells = forEachSystem (
pkgs:
assert lib.assertMsg (lockedPlaywrightVersion == pkgs.playwright-driver.version)
"package-lock.json pins Playwright ${lockedPlaywrightVersion}, but nixpkgs ships ${pkgs.playwright-driver.version}. Playwright only drives the browsers its own release shipped with, so run `nix flake update` or realign package-lock.json.";
{
default = pkgs.mkShell {
name = "sqlpage";
packages =
(with pkgs; [
biome
hurl
nodejs_26
pkg-config
sqlite
])
++ cargoRuntime pkgs
++ [ (formatterFor pkgs) ]
++ lib.attrValues (gatesFor pkgs);
buildInputs = with pkgs; [
unixodbc
zstd
];
# DATABASE_URL and LISTEN_ON stay unset on purpose. SQLPage reads
# both from the environment, so exporting them here would override
# every example and test fixture that ships its own configuration.
env = {
RUST_SRC_PATH = "${rustToolchainFor pkgs}/lib/rustlib/src/rust/library";
ZSTD_SYS_USE_PKG_CONFIG = "1";
}
// playwrightEnv pkgs;
};
}
);
};
}