Skip to content

Commit 726a7ab

Browse files
authored
Merge pull request #178 from Maxteabag/nix-extras
Expose optional DB drivers in the Nix flake
2 parents fa8e98c + 3553a55 commit 726a7ab

1 file changed

Lines changed: 64 additions & 32 deletions

File tree

flake.nix

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,53 +28,85 @@
2828
shortRev = if self ? shortRev then self.shortRev else "dirty";
2929
version = if tag != "" then tag else "0.0.0+${shortRev}";
3030

31-
sqlit = pyPkgs.buildPythonApplication {
32-
pname = "sqlit";
33-
inherit version;
34-
pyproject = true;
31+
# Extras mirror project.optional-dependencies in pyproject.toml,
32+
# limited to drivers packaged in nixpkgs. Others (mssql-python,
33+
# oracledb, mariadb, ibm_db, hdbcli, teradatasql, trino,
34+
# presto-python-client, redshift-connector, clickhouse-connect,
35+
# libsql, firebirdsql, pyathena, adbc-driver-flightsql) aren't
36+
# here; install with `pipx inject` or a custom derivation.
37+
nixpkgsExtras = {
38+
ssh = [ pyPkgs.sshtunnel pyPkgs.paramiko ];
39+
postgres = [ pyPkgs.psycopg2 ];
40+
cockroachdb = [ pyPkgs.psycopg2 ];
41+
mysql = [ pyPkgs.pymysql ];
42+
duckdb = [ pyPkgs.duckdb ];
43+
bigquery = [ pyPkgs.google-cloud-bigquery ];
44+
snowflake = [ pyPkgs.snowflake-connector-python ];
45+
d1 = [ pyPkgs.requests ];
46+
};
3547

36-
src = self;
48+
resolveExtras = names:
49+
lib.concatLists (map (n:
50+
nixpkgsExtras.${n} or (throw
51+
"Unknown sqlit extra '${n}'. Available: ${
52+
lib.concatStringsSep ", " (builtins.attrNames nixpkgsExtras)
53+
}")
54+
) names);
3755

38-
build-system = [
39-
pyPkgs.hatchling
40-
pyPkgs."hatch-vcs"
41-
pyPkgs."setuptools-scm"
42-
];
56+
# Build sqlit, optionally with a set of driver extras from nixpkgs.
57+
# Example: makeSqlit { extras = [ "postgres" "ssh" ]; }
58+
makeSqlit = { extras ? [] }:
59+
pyPkgs.buildPythonApplication {
60+
pname = "sqlit";
61+
inherit version;
62+
pyproject = true;
4363

44-
nativeBuildInputs = [
45-
pyPkgs.pythonRelaxDepsHook
46-
];
64+
src = self;
4765

48-
pythonRelaxDeps = [
49-
"textual-fastdatatable"
50-
];
66+
build-system = [
67+
pyPkgs.hatchling
68+
pyPkgs."hatch-vcs"
69+
pyPkgs."setuptools-scm"
70+
];
5171

52-
SETUPTOOLS_SCM_PRETEND_VERSION = version;
72+
nativeBuildInputs = [
73+
pyPkgs.pythonRelaxDepsHook
74+
];
5375

54-
dependencies = [
55-
pyPkgs.docker
56-
pyPkgs.keyring
57-
pyPkgs.pyperclip
58-
pyPkgs.sqlparse
59-
pyPkgs.textual
60-
pyPkgs."textual-fastdatatable"
61-
];
76+
pythonRelaxDeps = [
77+
"textual-fastdatatable"
78+
];
6279

63-
pythonImportsCheck = [ "sqlit" ];
80+
SETUPTOOLS_SCM_PRETEND_VERSION = version;
6481

65-
meta = with lib; {
66-
description = "A terminal UI for SQL databases";
67-
homepage = "https://github.com/Maxteabag/sqlit";
68-
license = licenses.mit;
69-
mainProgram = "sqlit";
82+
dependencies = [
83+
pyPkgs.docker
84+
pyPkgs.keyring
85+
pyPkgs.pyperclip
86+
pyPkgs.sqlparse
87+
pyPkgs.textual
88+
pyPkgs."textual-fastdatatable"
89+
] ++ (resolveExtras extras);
90+
91+
pythonImportsCheck = [ "sqlit" ];
92+
93+
meta = with lib; {
94+
description = "A terminal UI for SQL databases";
95+
homepage = "https://github.com/Maxteabag/sqlit";
96+
license = licenses.mit;
97+
mainProgram = "sqlit";
98+
};
7099
};
71-
};
100+
101+
sqlit = makeSqlit { extras = builtins.attrNames nixpkgsExtras; };
72102
in {
73103
packages = {
74104
inherit sqlit;
75105
default = sqlit;
76106
};
77107

108+
lib = { inherit makeSqlit; };
109+
78110
apps.default = {
79111
type = "app";
80112
program = "${sqlit}/bin/sqlit";

0 commit comments

Comments
 (0)