Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
161 lines (145 loc) · 4.93 KB
/
Copy pathflake.nix
File metadata and controls
161 lines (145 loc) · 4.93 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
{
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"
'';
};
redis = pkgs.writeShellApplication {
name = "redis";
runtimeInputs = [ pkgs.redis ];
text = ''
socket="$(pwd)/.redis.sock"
redis-server --daemonize yes --unixsocket "$socket" --port "$INTEGREAT_CMS_REDIS_PORT" > /dev/null
echo "$socket" > "$INTEGREAT_CMS_REDIS_SOCKET_LOCATION"
'';
};
in
{
devShells.default = pkgs.mkShell {
packages =
with pkgs;
[
python313
uv
nodejs_22
gettext
netcat-gnu
pcre
file
gnused
glibcLocales
stdenv.cc.cc.lib
]
++ [
pg-start
pg-stop
pg-reset
redis
];
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (
with pkgs;
[
stdenv.cc.cc.lib
file
cairo
pango
harfbuzz
]
);
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_LINKCHECK_DISABLE_LISTENERS 0
# Start redis and make it discoverable to the CMS
set_if_unset INTEGREAT_CMS_REDIS_SOCKET_LOCATION "./.redis_socket_location"
set_if_unset INTEGREAT_CMS_REDIS_PORT 6379
# Setting LD_LIBRARY_PATH can cause issues on non-NixOS systems
if ! command -v nixos-version &> /dev/null; then
unset LD_LIBRARY_PATH
fi
# The CPython builds downloaded by uv are not patched for the Nix dynamic linker,
# so make it use the interpreter provided by this flake instead
export UV_PYTHON_DOWNLOADS=never
export UV_PYTHON=${pkgs.python313}/bin/python3
SOURCE_DATE_EPOCH=$(date +%s)
VENV=.venv
if [ -d $VENV ]; then
source ./$VENV/bin/activate
fi
export PYTHONPATH=`pwd`/$VENV/${pkgs.python313.sitePackages}/:$PYTHONPATH
'';
};
}
);
}