From 1a74f19cd68e3b7264621e7231475c6b25505e6d Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 25 Jul 2021 21:53:11 +0200 Subject: flake: add python project dependencies --- .gitignore | 1 + flake.nix | 35 +++++++++++++++++++++++++++++------ 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 @@ +__pycache__ development_database *~ *.swp diff --git a/flake.nix b/flake.nix index 578bb9b..b49951e 100644 --- a/flake.nix +++ b/flake.nix @@ -17,11 +17,18 @@ python = python39; - develPackagesAndScripts = with python.pkgs; [ - postgresql_13 # PostgreSQL server with the standard admin tools. - ipython # Interactive Python REPL for experimenting. - psycopg2 # PostgreSQL driver for Python - embrace # bridges raw SQL queries to Python functions + pythonWithDependencies = python.withPackages (ps: with ps; [ + uvicorn # server for the web app + fastapi # simple Python framework to build web apps + python-multipart # to let fastapi handle form submissions + passlib # for account password hashing + psycopg2 # PostgreSQL driver for Python + embrace # bridges raw SQL queries to Python functions + ]); + + develPackagesAndScripts = [ + postgresql_13 # PostgreSQL server with the standard admin tools. + python.pkgs.ipython # Interactive Python REPL for experimenting. # More pleasant alternative to psql, with colours and auto-completion. # Custom configuration to suppress irrelevant warnings and messages. @@ -54,6 +61,20 @@ -d 2 \ "$@" '') + + # Script for starting the Uvicorn local development server. + # `--reload-dir` arguments necessary to prevent the database directory + # from triggering automatic application reload. + # See: https://github.com/encode/uvicorn/issues/984 + (writeShellScriptBin "dev-serve" '' + uvicorn \ + --reload-dir app \ + --reload-dir templates \ + --reload \ + --app-dir app \ + app:main \ + "$@" + '') ]; exportEnvVar = k: v: ''export ${k}="${v}"; echo ${k}=\"${v}\"''; @@ -63,12 +84,14 @@ PGHOST = "$PWD/development_database"; PGPORT = "5432"; PGDATABASE = "app"; + DATABASE_URL = "postgresql:///${PGDATABASE}?host=${PGHOST}"; + COOKIE_SECRET_KEY = "insecure for development"; }; in { devShell = mkShell rec { - buildInputs = develPackagesAndScripts; + buildInputs = [ pythonWithDependencies ] ++ develPackagesAndScripts; shellHook = '' echo -e "\nDEVSHELL ENVIRONMENT VARIABLES:" -- cgit v1.2.3