aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--flake.nix82
2 files changed, 83 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 171ad92..177ecee 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
1development_database
1*~ 2*~
2*.swp 3*.swp
3*.swo 4*.swo
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..e09265f
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,82 @@
1# UGE / L2 / Intro to relational databases / Python project prototype
2# Author: Pacien TRAN-GIRARD
3# Licence: EUPL-1.2
4
5{
6 inputs = {
7 nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.05";
8 flake-utils.url = "github:numtide/flake-utils";
9 };
10
11 outputs = { self, nixpkgs, flake-utils }:
12 flake-utils.lib.eachDefaultSystem (system:
13 with import nixpkgs { inherit system; };
14 let
15
16 develPackagesAndScripts = [
17 postgresql_13 # PostgreSQL server with the standard admin tools.
18
19 # More pleasant alternative to psql, with colours and auto-completion.
20 # Custom configuration to suppress irrelevant warnings and messages.
21 (writeShellScriptBin "pgcli" ''
22 ${pgcli}/bin/pgcli --pgclirc "${writeText "pgclirc" ''
23 [main]
24 keyring = False
25 less_chatty = True
26 ''}" "$@"
27 '')
28
29 # Script for initialising an independent development database.
30 # This creates a default empty database name "postgres" and owned by the
31 # current user. Data are stored in ./development_database/pgdata.
32 (writeShellScriptBin "dev-initdb" ''
33 initdb \
34 --no-locale \
35 --encoding UTF8 \
36 --auth-host reject \
37 --auth-local peer \
38 "$@"
39 '')
40
41 # Script for starting an independent development posgresql server.
42 # Accepts connections only through a local UNIX-domain socket.
43 (writeShellScriptBin "dev-postgres" ''
44 postgres \
45 -h "" \
46 -k "$PGHOST" \
47 -d 2 \
48 "$@"
49 '')
50 ];
51
52 exportEnvVar = k: v: ''export ${k}="${v}"; echo ${k}=\"${v}\"'';
53 exportDevelEnvVars = lib.mapAttrsToList exportEnvVar develEnvVars;
54 develEnvVars = rec {
55 PGDATA = "$PWD/development_database/pgdata";
56 PGHOST = "$PWD/development_database";
57 PGPORT = "5432";
58 PGDATABASE = "app";
59 };
60
61 in {
62
63 devShell = mkShell rec {
64 buildInputs = develPackagesAndScripts;
65
66 shellHook = ''
67 echo -e "\nDEVSHELL ENVIRONMENT VARIABLES:"
68 ${lib.concatStringsSep "\n" exportDevelEnvVars}
69
70 echo -e "\nDEVSHELL COMMANDS:"
71 ls "${symlinkJoin { name = "env"; paths = buildInputs; }}/bin"
72
73 # Use the default user shell instead of Bash
74 $(${finger_bsd}/bin/finger $USER \
75 | ${gnugrep}/bin/grep -oP 'Shell: \K.*')
76
77 exit $?
78 '';
79 };
80
81 });
82}