-
Notifications
You must be signed in to change notification settings - Fork 35
/
flake.nix
122 lines (108 loc) · 3.94 KB
/
flake.nix
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
{
inputs = {
utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs, utils }:
utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
pg-start = pkgs.writeShellApplication {
name = "pg-start";
runtimeInputs = [ pkgs.postgresql ];
text = ''
if test ! -d "$PGDATA"; then
pg-reset
fi
if ! pg_ctl status 2>/dev/null | grep -q "server is running"; then
pg_ctl start \
-l "$PGLOG" \
-o "-c unix_socket_directories=$PGDIR -F -p $INTEGREAT_CMS_DB_PORT -k $PGLOCK"
fi
'';
};
pg-stop = pkgs.writeShellApplication {
name = "pg-stop";
runtimeInputs = [ pkgs.postgresql ];
text = ''
if pg_ctl status 2>/dev/null | grep -q "server is running"; then
pg_ctl stop
fi
'';
};
pg-reset = pkgs.writeShellApplication {
name = "pg-reset";
runtimeInputs = [ pkgs.postgresql pg-start pg-stop ];
text = ''
pg-stop
if test ! -d "$PGDIR"; then
mkdir "$PGDIR"
mkdir "$PGLOCK"
fi
rm -rf "$PGDATA"
initdb "$PGDATA" --auth=trust -U "$INTEGREAT_CMS_DB_USER" >/dev/null
pg-start
createdb -h "$INTEGREAT_CMS_DB_HOST" -p "$INTEGREAT_CMS_DB_PORT" -U "$INTEGREAT_CMS_DB_USER" "$INTEGREAT_CMS_DB_NAME"
'';
};
in
{
devShells.default = pkgs.mkShell {
packages = with pkgs; [
python311Full
python311Packages.pip
python311Packages.platformdirs
nodePackages.npm
nodejs_21
gettext
netcat-gnu
pcre16
file
gnused
glibcLocales
stdenv.cc.cc.lib
] ++ [
pg-start
pg-stop
pg-reset
];
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ pkgs.stdenv.cc.cc.lib pkgs.file ];
shellHook = /* bash */ ''
set_if_unset() {
if [ -z "$(eval \$$1)" ]; then
export "$1"="$2"
fi
}
set_if_unset PGDIR "$(pwd)/.postgres"
set_if_unset PGDATA "$PGDIR/data"
set_if_unset PGLOG "$PGDIR/log"
set_if_unset PGLOCK "$PGDIR/lock"
set_if_unset INTEGREAT_CMS_DB_NAME "integreat"
set_if_unset INTEGREAT_CMS_DB_USER "integreat"
set_if_unset INTEGREAT_CMS_DB_PASSWORD "password"
set_if_unset INTEGREAT_CMS_DB_HOST "localhost"
set_if_unset INTEGREAT_CMS_DB_PORT "5432"
# These are set in the devtools at appropriate locations;
# additionally setting them here allows for testing integration in code editors
set_if_unset DJANGO_SETTINGS_MODULE "integreat_cms.core.settings"
set_if_unset INTEGREAT_CMS_DEBUG 1
set_if_unset INTEGREAT_CMS_DEEPL_AUTH_KEY "dummy"
set_if_unset INTEGREAT_CMS_FCM_CREDENTIALS "dummy"
set_if_unset INTEGREAT_CMS_SECRET_KEY "dummy"
set_if_unset INTEGREAT_CMS_BACKGROUND_TASKS_ENABLED 0
set_if_unset INTEGREAT_CMS_SUMM_AI_API_KEY "dummy"
set_if_unset INTEGREAT_CMS_LINKCHECK_DISABLE_LISTENERS 1
# Setting LD_LIBRARY_PATH can cause issues on non-NixOS systems
if ! command -v nixos-version &> /dev/null; then
unset LD_LIBRARY_PATH
fi
SOURCE_DATE_EPOCH=$(date +%s)
VENV=.venv
if [ -d $VENV ]; then
source ./$VENV/bin/activate
fi
export PYTHONPATH=`pwd`/$VENV/${pkgs.python311Full.sitePackages}/:$PYTHONPATH
'';
};
});
}