-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathflake.nix
More file actions
138 lines (119 loc) · 4.12 KB
/
flake.nix
File metadata and controls
138 lines (119 loc) · 4.12 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
{
description = "A terminal UI for SQL databases";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
lib = pkgs.lib;
pyPkgs = pkgs.python3.pkgs;
ref =
if self ? sourceInfo && self.sourceInfo ? ref
then self.sourceInfo.ref
else "";
tag =
if lib.hasPrefix "refs/tags/v" ref
then lib.removePrefix "refs/tags/v" ref
else if lib.hasPrefix "refs/tags/" ref
then lib.removePrefix "refs/tags/" ref
else if lib.hasPrefix "v" ref
then lib.removePrefix "v" ref
else "";
shortRev = if self ? shortRev then self.shortRev else "dirty";
version = if tag != "" then tag else "0.0.0+${shortRev}";
# Extras mirror project.optional-dependencies in pyproject.toml,
# limited to drivers packaged in nixpkgs. Others (mssql-python,
# oracledb, mariadb, ibm_db, hdbcli, teradatasql, trino,
# presto-python-client, redshift-connector, clickhouse-connect,
# libsql, firebirdsql, pyathena, adbc-driver-flightsql) aren't
# here; install with `pipx inject` or a custom derivation.
nixpkgsExtras = {
ssh = [ pyPkgs.sshtunnel pyPkgs.paramiko ];
postgres = [ pyPkgs.psycopg2 ];
cockroachdb = [ pyPkgs.psycopg2 ];
mysql = [ pyPkgs.pymysql ];
duckdb = [ pyPkgs.duckdb ];
bigquery = [ pyPkgs.google-cloud-bigquery ];
snowflake = [ pyPkgs.snowflake-connector-python ];
d1 = [ pyPkgs.requests ];
};
resolveExtras = names:
lib.concatLists (map (n:
nixpkgsExtras.${n} or (throw
"Unknown sqlit extra '${n}'. Available: ${
lib.concatStringsSep ", " (builtins.attrNames nixpkgsExtras)
}")
) names);
# Build sqlit, optionally with a set of driver extras from nixpkgs.
# Example: makeSqlit { extras = [ "postgres" "ssh" ]; }
makeSqlit = { extras ? [] }:
pyPkgs.buildPythonApplication {
pname = "sqlit";
inherit version;
pyproject = true;
src = self;
build-system = [
pyPkgs.hatchling
pyPkgs."hatch-vcs"
pyPkgs."setuptools-scm"
];
nativeBuildInputs = [
pyPkgs.pythonRelaxDepsHook
];
pythonRelaxDeps = [
"textual-fastdatatable"
];
SETUPTOOLS_SCM_PRETEND_VERSION = version;
dependencies = [
pyPkgs.docker
pyPkgs.keyring
pyPkgs.pyperclip
pyPkgs.sqlparse
pyPkgs.textual
pyPkgs."textual-fastdatatable"
] ++ (resolveExtras extras);
pythonImportsCheck = [ "sqlit" ];
meta = with lib; {
description = "A terminal UI for SQL databases";
homepage = "https://github.com/Maxteabag/sqlit";
license = licenses.mit;
mainProgram = "sqlit";
};
};
sqlit = makeSqlit { extras = builtins.attrNames nixpkgsExtras; };
in {
packages = {
inherit sqlit;
default = sqlit;
};
lib = { inherit makeSqlit; };
apps.default = {
type = "app";
program = "${sqlit}/bin/sqlit";
};
checks = {
inherit sqlit;
};
devShells.default = pkgs.mkShell {
packages = [
pkgs.python3
pkgs.hatch
pyPkgs.pytest
pyPkgs.pytest-timeout
pyPkgs.pytest-asyncio
pyPkgs.pytest-cov
pyPkgs.pytest-benchmark
pkgs.ruff
pyPkgs.mypy
pkgs.pre-commit
pyPkgs.build
pyPkgs.faker
pyPkgs.ipython
];
inputsFrom = [ sqlit ];
};
});
}