-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
64 lines (54 loc) · 2.14 KB
/
flake.nix
File metadata and controls
64 lines (54 loc) · 2.14 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
# credit goes to https://www.zknotes.com/page/python%20development%20flake
{
description = "python dev environment";
# to activate, type `nix develop` while in the repo dir or a subdir.
# or use direnv to automatically do so (see .envrc)
# for best results, don't have a global python installed. mixing python
# versions can make for venv problems.
inputs = {
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (
system: let
pname = "python dev environment";
pkgs = nixpkgs.legacyPackages."${system}";
venvDir = "venv";
dbPort = "5432";
in {
inherit pname;
# `nix develop`
devShell = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
postgresql
python312Packages.python
python312Packages.python-lsp-server
python312Packages.flask
python312Packages.alembic
python312Packages.autopep8
];
LOCAL = "yes";
DB_PORT = dbPort;
DATABASE_URL = "postgresql://postgres@localhost:${dbPort}/test";
shellHook = ''
# create a virtualenv if there isn't one.
# DOESN'T install deps for the python app. Do that once `nix develop` runs with
# $ cd src
# $ pip install -r ./requirements.txt
if [ -d "${venvDir}" ]; then
echo "Skipping venv creation, '${venvDir}' already exists"
else
echo "Creating new venv environment in path: '${venvDir}'"
# Note that the module venv was only introduced in python 3, so for 2.7
# this needs to be replaced with a call to virtualenv
python -m venv "${venvDir}"
# unescape to attempt use
# \$\{pythonPackages.python.interpreter\} -m venv "${venvDir}"
fi
# activate our virtual env.
source "${venvDir}/bin/activate"
'';
};
}
);
}