aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--flake.nix35
2 files changed, 30 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index 177ecee..aa78700 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
1__pycache__
1development_database 2development_database
2*~ 3*~
3*.swp 4*.swp
diff --git a/flake.nix b/flake.nix
index 578bb9b..b49951e 100644
--- a/flake.nix
+++ b/flake.nix
@@ -17,11 +17,18 @@
17 17
18 python = python39; 18 python = python39;
19 19
20 develPackagesAndScripts = with python.pkgs; [ 20 pythonWithDependencies = python.withPackages (ps: with ps; [
21 postgresql_13 # PostgreSQL server with the standard admin tools. 21 uvicorn # server for the web app
22 ipython # Interactive Python REPL for experimenting. 22 fastapi # simple Python framework to build web apps
23 psycopg2 # PostgreSQL driver for Python 23 python-multipart # to let fastapi handle form submissions
24 embrace # bridges raw SQL queries to Python functions 24 passlib # for account password hashing
25 psycopg2 # PostgreSQL driver for Python
26 embrace # bridges raw SQL queries to Python functions
27 ]);
28
29 develPackagesAndScripts = [
30 postgresql_13 # PostgreSQL server with the standard admin tools.
31 python.pkgs.ipython # Interactive Python REPL for experimenting.
25 32
26 # More pleasant alternative to psql, with colours and auto-completion. 33 # More pleasant alternative to psql, with colours and auto-completion.
27 # Custom configuration to suppress irrelevant warnings and messages. 34 # Custom configuration to suppress irrelevant warnings and messages.
@@ -54,6 +61,20 @@
54 -d 2 \ 61 -d 2 \
55 "$@" 62 "$@"
56 '') 63 '')
64
65 # Script for starting the Uvicorn local development server.
66 # `--reload-dir` arguments necessary to prevent the database directory
67 # from triggering automatic application reload.
68 # See: https://github.com/encode/uvicorn/issues/984
69 (writeShellScriptBin "dev-serve" ''
70 uvicorn \
71 --reload-dir app \
72 --reload-dir templates \
73 --reload \
74 --app-dir app \
75 app:main \
76 "$@"
77 '')
57 ]; 78 ];
58 79
59 exportEnvVar = k: v: ''export ${k}="${v}"; echo ${k}=\"${v}\"''; 80 exportEnvVar = k: v: ''export ${k}="${v}"; echo ${k}=\"${v}\"'';
@@ -63,12 +84,14 @@
63 PGHOST = "$PWD/development_database"; 84 PGHOST = "$PWD/development_database";
64 PGPORT = "5432"; 85 PGPORT = "5432";
65 PGDATABASE = "app"; 86 PGDATABASE = "app";
87 DATABASE_URL = "postgresql:///${PGDATABASE}?host=${PGHOST}";
88 COOKIE_SECRET_KEY = "insecure for development";
66 }; 89 };
67 90
68 in { 91 in {
69 92
70 devShell = mkShell rec { 93 devShell = mkShell rec {
71 buildInputs = develPackagesAndScripts; 94 buildInputs = [ pythonWithDependencies ] ++ develPackagesAndScripts;
72 95
73 shellHook = '' 96 shellHook = ''
74 echo -e "\nDEVSHELL ENVIRONMENT VARIABLES:" 97 echo -e "\nDEVSHELL ENVIRONMENT VARIABLES:"