|
28 | 28 | shortRev = if self ? shortRev then self.shortRev else "dirty"; |
29 | 29 | version = if tag != "" then tag else "0.0.0+${shortRev}"; |
30 | 30 |
|
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 | + }; |
35 | 47 |
|
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); |
37 | 55 |
|
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; |
43 | 63 |
|
44 | | - nativeBuildInputs = [ |
45 | | - pyPkgs.pythonRelaxDepsHook |
46 | | - ]; |
| 64 | + src = self; |
47 | 65 |
|
48 | | - pythonRelaxDeps = [ |
49 | | - "textual-fastdatatable" |
50 | | - ]; |
| 66 | + build-system = [ |
| 67 | + pyPkgs.hatchling |
| 68 | + pyPkgs."hatch-vcs" |
| 69 | + pyPkgs."setuptools-scm" |
| 70 | + ]; |
51 | 71 |
|
52 | | - SETUPTOOLS_SCM_PRETEND_VERSION = version; |
| 72 | + nativeBuildInputs = [ |
| 73 | + pyPkgs.pythonRelaxDepsHook |
| 74 | + ]; |
53 | 75 |
|
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 | + ]; |
62 | 79 |
|
63 | | - pythonImportsCheck = [ "sqlit" ]; |
| 80 | + SETUPTOOLS_SCM_PRETEND_VERSION = version; |
64 | 81 |
|
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 | + }; |
70 | 99 | }; |
71 | | - }; |
| 100 | + |
| 101 | + sqlit = makeSqlit { extras = builtins.attrNames nixpkgsExtras; }; |
72 | 102 | in { |
73 | 103 | packages = { |
74 | 104 | inherit sqlit; |
75 | 105 | default = sqlit; |
76 | 106 | }; |
77 | 107 |
|
| 108 | + lib = { inherit makeSqlit; }; |
| 109 | + |
78 | 110 | apps.default = { |
79 | 111 | type = "app"; |
80 | 112 | program = "${sqlit}/bin/sqlit"; |
|
0 commit comments