-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathflake.nix
More file actions
193 lines (178 loc) · 6.28 KB
/
flake.nix
File metadata and controls
193 lines (178 loc) · 6.28 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
# SPDX-FileCopyrightText: Tim Sutton
# SPDX-License-Identifier: MIT
{
description = "NixOS developer environment for QGIS plugins.";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = { self, nixpkgs }:
let
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forAllSystems = nixpkgs.lib.genAttrs systems;
pkgsFor = system: import nixpkgs {
inherit system;
config.allowUnfree = true;
};
in
{
packages = forAllSystems (system:
let
pkgs = pkgsFor system;
postgresWithPostGIS = pkgs.postgresql.withPackages (ps: [ ps.postgis ]);
in
{
default = postgresWithPostGIS;
postgres = postgresWithPostGIS;
});
apps = forAllSystems (system:
let
pkgs = pkgsFor system;
in
{
black-check = {
type = "app";
program = toString (pkgs.writeShellScript "black-check" ''
#!/usr/bin/env bash
set -e
echo "🔍 Checking Python files with black..."
find . -type f -name "*.py" -not -path "./.venv/*" -not -path "./build/*" -not -path "./.git/*" | xargs black --check --diff
echo "✅ All Python files are formatted correctly!"
'');
};
black-fix = {
type = "app";
program = toString (pkgs.writeShellScript "black-fix" ''
#!/usr/bin/env bash
set -e
echo "🔧 Fixing Python files with black..."
find . -type f -name "*.py" -not -path "./.venv/*" -not -path "./build/*" -not -path "./.git/*" | xargs black
echo "✅ All Python files have been formatted!"
'');
};
});
devShells = forAllSystems (system:
let
pkgs = pkgsFor system;
postgresWithPostGIS = pkgs.postgresql.withPackages (ps: [ ps.postgis ]);
in
{
default = pkgs.mkShell {
packages = [
pkgs.actionlint # for checking gh actions
pkgs.bandit
pkgs.bearer
pkgs.chafa
pkgs.nixfmt-rfc-style
pkgs.codeql
pkgs.ffmpeg
pkgs.gdb
pkgs.git
pkgs.minio-client # for grabbing ookla data
pkgs.glogg
pkgs.glow # terminal markdown viewer
pkgs.gource # Software version control visualization
pkgs.gum # UX for TUIs
pkgs.isort
pkgs.jq
pkgs.luaPackages.luacheck
pkgs.markdownlint-cli
pkgs.nixfmt-rfc-style
pkgs.pre-commit
pkgs.nixfmt-rfc-style
pkgs.pyprof2calltree # needed to covert cprofile call trees into a format kcachegrind can read
pkgs.python313
# Python development essentials
pkgs.pyright
pkgs.rpl
pkgs.shellcheck
pkgs.shfmt
pkgs.stylua
pkgs.yamlfmt
pkgs.yamllint
postgresWithPostGIS
pkgs.nodePackages.cspell
(pkgs.python313.withPackages (ps: [
# Add these for SQL linting/formatting:
ps.black
ps.click # needed by black
ps.debugpy
ps.docformatter
ps.flake8
ps.gdal
ps.httpx
ps.jsonschema
ps.mypy
ps.numpy
ps.odfpy
ps.pandas
ps.paver
ps.pip
ps.psutil
ps.pytest
ps.rich
ps.setuptools
ps.snakeviz # For visualising cprofiler outputs
ps.sqlfmt
ps.toml
ps.typer
ps.wheel
# For autocompletion in vscode
# This executes some shell code to initialize a venv in $venvDir before
# dropping into the shell
ps.venvShellHook
ps.virtualenv
]))
];
shellHook = ''
unset SOURCE_DATE_EPOCH
# Create a virtual environment in .venv if it doesn't exist
if [ ! -d ".venv" ]; then
python -m venv .venv
fi
# Activate the virtual environment
source .venv/bin/activate
# Upgrade pip and install packages from requirements.txt if it exists
pip install --upgrade pip > /dev/null
if [ -f requirements.txt ]; then
echo "Installing Python requirements from requirements.txt..."
pip install -r requirements.txt > .pip-install.log 2>&1
if [ $? -ne 0 ]; then
echo "❌ Pip install failed. See .pip-install.log for details."
fi
else
echo "No requirements.txt found, skipping pip install."
fi
if [ -f requirements-dev.txt ]; then
echo "Installing Python requirements from requirements-dev.txt..."
pip install -r requirements-dev.txt > .pip-install.log 2>&1
if [ $? -ne 0 ]; then
echo "❌ Pip install failed. See .pip-install.log for details."
fi
else
echo "No requirements-dev.txt found, skipping pip install."
fi
echo "Setting up and running pre-commit hooks..."
echo "-------------------------------------"
pre-commit clean > /dev/null
pre-commit install --install-hooks > /dev/null
pre-commit run --all-files || true
# Colors and styling
CYAN='\033[38;2;83;161;203m'
GREEN='\033[92m'
RED='\033[91m'
RESET='\033[0m'
ORANGE='\033[38;2;237;177;72m'
GRAY='\033[90m'
# Clear screen and show welcome banner
clear
echo -e "$RESET$ORANGE"
echo -e " 🌈 Your Dev Environment is prepared."
echo -e ""
echo -e "Quick Commands:$RESET"
echo -e " $GRAY▶$RESET $CYAN nix flake show$RESET - Show available configurations"
echo -e " $GRAY▶$RESET $CYAN nix flake check$RESET - Run all checks"
echo -e "$RESET$ORANGE \n__________________________________________________________________\n"
echo ""
'';
};
});
};
}