Skip to content

Commit f80cb37

Browse files
committed
Expose optional DB drivers in the Nix flake
Currently the flake installs only core deps, so `nix run` gives a working TUI but every DB driver except SQLite (stdlib) is missing — users can't connect to Postgres/MySQL/etc. On a Nix install there's no pipx-style inject, so the driver has to come from the derivation. Add a small `makeSqlit` helper with an `extras` list that mirrors the names in pyproject.toml's `project.optional-dependencies`, limited to drivers packaged in nixpkgs. The default `sqlit` is unchanged; a new `sqlit-full` variant pulls in every extra we can satisfy from nixpkgs. Custom builds go through `lib.makeSqlit { extras = [ ... ]; }`. Addresses the goal of #126 without the 22-flag / 500-line expansion.
1 parent fa8e98c commit f80cb37

2 files changed

Lines changed: 67 additions & 34 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pip install sqlit-tui
113113
# Arch Linux (AUR)
114114
yay -S sqlit
115115

116-
# Nix (flake)
116+
# Nix (flake) — append "#sqlit-full" for common DB drivers
117117
nix run github:Maxteabag/sqlit
118118
```
119119

flake.nix

Lines changed: 66 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,53 +28,86 @@
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+
];
79+
80+
SETUPTOOLS_SCM_PRETEND_VERSION = version;
6281

63-
pythonImportsCheck = [ "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);
6490

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";
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 { };
102+
sqlit-full = makeSqlit { extras = builtins.attrNames nixpkgsExtras; };
72103
in {
73104
packages = {
74-
inherit sqlit;
105+
inherit sqlit sqlit-full;
75106
default = sqlit;
76107
};
77108

109+
lib = { inherit makeSqlit; };
110+
78111
apps.default = {
79112
type = "app";
80113
program = "${sqlit}/bin/sqlit";

0 commit comments

Comments
 (0)