# UGE / L2 / Intro to relational databases / Python project prototype # Author: Pacien TRAN-GIRARD # Licence: EUPL-1.2 { inputs = { # for python3Packages.embrace: https://github.com/NixOS/nixpkgs/pull/131425 nixpkgs.url = "github:pacien/nixpkgs/3faf31d"; #nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; }; outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: with import nixpkgs { inherit system; }; let 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 # More pleasant alternative to psql, with colours and auto-completion. # Custom configuration to suppress irrelevant warnings and messages. (writeShellScriptBin "pgcli" '' ${pgcli}/bin/pgcli --pgclirc "${writeText "pgclirc" '' [main] keyring = False less_chatty = True ''}" "$@" '') # Script for initialising an independent development database. # This creates a default empty database name "postgres" and owned by the # current user. Data are stored in ./development_database/pgdata. (writeShellScriptBin "dev-initdb" '' initdb \ --no-locale \ --encoding UTF8 \ --auth-host reject \ --auth-local peer \ "$@" '') # Script for starting an independent development posgresql server. # Accepts connections only through a local UNIX-domain socket. (writeShellScriptBin "dev-postgres" '' postgres \ -h "" \ -k "$PGHOST" \ -d 2 \ "$@" '') ]; exportEnvVar = k: v: ''export ${k}="${v}"; echo ${k}=\"${v}\"''; exportDevelEnvVars = lib.mapAttrsToList exportEnvVar develEnvVars; develEnvVars = rec { PGDATA = "$PWD/development_database/pgdata"; PGHOST = "$PWD/development_database"; PGPORT = "5432"; PGDATABASE = "app"; }; in { devShell = mkShell rec { buildInputs = develPackagesAndScripts; shellHook = '' echo -e "\nDEVSHELL ENVIRONMENT VARIABLES:" ${lib.concatStringsSep "\n" exportDevelEnvVars} echo -e "\nDEVSHELL COMMANDS:" ls "${symlinkJoin { name = "env"; paths = buildInputs; }}/bin" # Use the default user shell instead of Bash $(${finger_bsd}/bin/finger $USER \ | ${gnugrep}/bin/grep -oP 'Shell: \K.*') exit $? ''; }; }); }