-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
120 lines (104 loc) · 3.23 KB
/
flake.nix
File metadata and controls
120 lines (104 loc) · 3.23 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
{
description = "A Nix-flake-based Python development environment";
inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1"; # unstable Nixpkgs
outputs =
{ self, ... }@inputs:
let
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forEachSupportedSystem =
f:
inputs.nixpkgs.lib.genAttrs supportedSystems (
system:
f {
pkgs = import inputs.nixpkgs { inherit system; };
}
);
/*
Change this value ({major}.{min}) to
update the Python virtual-environment
version. When you do this, make sure
to delete the `.venv` directory to
have the hook rebuild it for the new
version, since it won't overwrite an
existing one. After this, reload the
development shell to rebuild it.
You'll see a warning asking you to
do this when version mismatches are
present. For safety, removal should
be a manual step, even if trivial.
*/
version = "3.13";
in
{
devShells = forEachSupportedSystem (
{ pkgs }:
let
concatMajorMinor =
v:
pkgs.lib.pipe v [
pkgs.lib.versions.splitVersion
(pkgs.lib.sublist 0 2)
pkgs.lib.concatStrings
];
python = pkgs."python${concatMajorMinor version}";
in
{
default = pkgs.mkShellNoCC {
venvDir = ".venv";
buildInputs = with pkgs; [
(writeShellScriptBin "dev" ''
echo "start"
(nohup bash -c 'sleep 1 && xdg-open http://localhost:8585' > /dev/null 2>&1 ) & \
uvicorn main:app --host 0.0.0.0 --port 8585 --reload --env-file envs/molclass.env
'')
];
postShellHook = ''
venvVersionWarn() {
local venvVersion
venvVersion="$("$venvDir/bin/python" -c 'import platform; print(platform.python_version())')"
[[ "$venvVersion" == "${python.version}" ]] && return
cat <<EOF
Warning: Python version mismatch: [$venvVersion (venv)] != [${python.version}]
Delete '$venvDir' and reload to rebuild for version ${python.version}
EOF
}
venvVersionWarn
echo "======================="
echo "Available commands:"
echo " dev - Start development services"
echo "======================="
'';
packages = with python.pkgs; [
venvShellHook
pip
aiofiles
aiohttp
beautifulsoup4
debugpy
fastapi
httpx
icecream
jinja2
lxml
mypy
pydantic-settings
pyyaml
requests
scrapy
sqlmodel
uvicorn
websockets
pkgs.hurl
pkgs.basedpyright
pkgs.nodePackages.typescript
];
};
}
);
};
}