2024-12-12 14:41:43 +01:00
|
|
|
# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
2024-07-09 10:47:30 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
sources,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2024-07-28 14:29:54 +02:00
|
|
|
inherit (lib) mapAttrsToList optionals;
|
2024-07-09 10:47:30 +02:00
|
|
|
|
2024-10-12 19:30:36 +02:00
|
|
|
host = "vote.dgnum.eu";
|
2024-07-09 10:47:30 +02:00
|
|
|
port = 9888;
|
|
|
|
|
|
|
|
python3 =
|
|
|
|
let
|
|
|
|
nix-pkgs = import sources.nix-pkgs { inherit pkgs; };
|
|
|
|
in
|
|
|
|
pkgs.python3.override {
|
|
|
|
packageOverrides = _: _: {
|
|
|
|
inherit (nix-pkgs)
|
2024-07-28 14:29:54 +02:00
|
|
|
authens
|
2024-07-09 10:47:30 +02:00
|
|
|
django-background-tasks
|
2024-07-28 14:29:54 +02:00
|
|
|
django-browser-reload
|
2024-07-09 10:47:30 +02:00
|
|
|
django-bulma-forms
|
|
|
|
django-translated-fields
|
|
|
|
loadcredential
|
|
|
|
;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-07-28 14:29:54 +02:00
|
|
|
pythonEnv =
|
|
|
|
{
|
|
|
|
debug ? false,
|
|
|
|
}:
|
|
|
|
python3.withPackages (
|
|
|
|
ps:
|
|
|
|
[
|
|
|
|
ps.django
|
|
|
|
|
|
|
|
ps.gunicorn
|
|
|
|
|
|
|
|
ps.markdown
|
|
|
|
ps.numpy
|
|
|
|
ps.networkx
|
|
|
|
ps.psycopg
|
|
|
|
|
|
|
|
ps.authens
|
|
|
|
ps.django-background-tasks
|
|
|
|
ps.django-bulma-forms
|
|
|
|
ps.django-translated-fields
|
|
|
|
ps.loadcredential
|
|
|
|
]
|
|
|
|
++ (optionals debug [
|
|
|
|
ps.django-browser-reload
|
|
|
|
ps.django-debug-toolbar
|
|
|
|
])
|
|
|
|
);
|
2024-07-09 10:47:30 +02:00
|
|
|
|
2024-07-09 14:32:04 +02:00
|
|
|
manage = pkgs.writeShellApplication {
|
|
|
|
name = "kadenios-manage";
|
|
|
|
|
2024-07-28 14:29:54 +02:00
|
|
|
runtimeInputs = path ++ [
|
|
|
|
config.systemd.package
|
|
|
|
pkgs.util-linux
|
|
|
|
];
|
2024-07-09 14:32:04 +02:00
|
|
|
|
|
|
|
text = ''
|
2024-07-28 14:29:54 +02:00
|
|
|
MainPID=$(systemctl show -p MainPID --value django-kadenios.service)
|
2024-07-09 14:32:04 +02:00
|
|
|
|
2024-07-28 14:29:54 +02:00
|
|
|
nsenter -e -a -t "$MainPID" -G follow -S follow python ${sources.kadenios}/manage.py "$@"
|
2024-07-09 14:32:04 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-07-09 10:47:30 +02:00
|
|
|
staticDrv = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "kadenios-static";
|
|
|
|
|
|
|
|
src = sources.kadenios;
|
|
|
|
|
2024-07-28 14:29:54 +02:00
|
|
|
nativeBuildInputs = [ (pythonEnv { debug = true; }) ];
|
2024-07-09 10:47:30 +02:00
|
|
|
|
|
|
|
configurePhase = ''
|
|
|
|
export KADENIOS_STATIC_ROOT=$out/static
|
|
|
|
export KADENIOS_DEBUG=true
|
|
|
|
export CREDENTIALS_DIRECTORY=$(pwd)/.credentials
|
|
|
|
'';
|
|
|
|
|
|
|
|
doBuild = false;
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/static
|
|
|
|
python3 manage.py collectstatic
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
environment = builtins.mapAttrs (_: builtins.toJSON) {
|
|
|
|
KADENIOS_ALLOWED_HOSTS = [ "vote.dgnum.eu" ];
|
|
|
|
KADENIOS_STATIC_ROOT = staticDrv;
|
|
|
|
KADENIOS_DATABASES = {
|
|
|
|
default = {
|
|
|
|
ENGINE = "django.db.backends.postgresql";
|
|
|
|
NAME = "kadenios";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
KADENIOS_EMAIL_HOST_USER = "web-services@infra.dgnum.eu";
|
|
|
|
KADENIOS_EMAIL_USE_SSL = true;
|
|
|
|
KADENIOS_FROM_EMAIL = "Kadenios <vote@infra.dgnum.eu>";
|
|
|
|
KADENIOS_SERVER_EMAIL = "kadenios@infra.dgnum.eu";
|
|
|
|
};
|
2024-07-28 14:29:54 +02:00
|
|
|
|
|
|
|
path = [ (pythonEnv { }) ];
|
2024-07-09 10:47:30 +02:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2024-07-09 14:32:04 +02:00
|
|
|
environment.systemPackages = [ manage ];
|
2024-07-09 10:47:30 +02:00
|
|
|
systemd.services = {
|
|
|
|
django-kadenios = {
|
|
|
|
description = "ENS simple voting server";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [
|
|
|
|
"network.target"
|
|
|
|
"postgresql.service"
|
|
|
|
];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
DynamicUser = true;
|
|
|
|
LoadCredential = mapAttrsToList (name: value: "${name}:${value}") {
|
|
|
|
SECRET_KEY = config.age.secrets."kadenios-secret_key_file".path;
|
|
|
|
EMAIL_HOST_PASSWORD = config.age.secrets."kadenios-email_password_file".path;
|
|
|
|
};
|
|
|
|
StateDirectory = "django-kadenios";
|
|
|
|
User = "kadenios";
|
|
|
|
};
|
|
|
|
|
2024-07-28 14:29:54 +02:00
|
|
|
inherit environment path;
|
2024-07-09 10:47:30 +02:00
|
|
|
|
|
|
|
script = ''
|
2024-07-09 14:32:04 +02:00
|
|
|
python3 ${sources.kadenios}/manage.py migrate
|
2024-07-09 10:47:30 +02:00
|
|
|
gunicorn app.wsgi --pythonpath ${sources.kadenios} -b 127.0.0.1:${builtins.toString port} --workers=2 --threads=4
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
django-kadenios-tasks = {
|
|
|
|
description = "Background tasks worker for Kadenios";
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [
|
|
|
|
"network.target"
|
|
|
|
"postgresql.service"
|
|
|
|
"django-kadenios.service"
|
|
|
|
];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
DynamicUser = true;
|
|
|
|
LoadCredential = mapAttrsToList (name: value: "${name}:${value}") {
|
|
|
|
SECRET_KEY = config.age.secrets."kadenios-secret_key_file".path;
|
|
|
|
EMAIL_HOST_PASSWORD = config.age.secrets."kadenios-email_password_file".path;
|
|
|
|
};
|
|
|
|
StateDirectory = "django-kadenios";
|
|
|
|
User = "kadenios";
|
|
|
|
WorkingDirectory = sources.kadenios;
|
|
|
|
};
|
|
|
|
|
2024-07-28 14:29:54 +02:00
|
|
|
inherit environment path;
|
2024-07-09 10:47:30 +02:00
|
|
|
|
|
|
|
script = ''
|
|
|
|
python3 manage.py process_tasks
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-10-12 19:30:36 +02:00
|
|
|
dgn-web.simpleProxies.kadenios = {
|
|
|
|
inherit host port;
|
|
|
|
vhostConfig.locations."/static/".root = staticDrv;
|
|
|
|
};
|
2024-07-09 10:47:30 +02:00
|
|
|
|
2024-10-12 19:30:36 +02:00
|
|
|
services.postgresql = {
|
|
|
|
ensureDatabases = [ "kadenios" ];
|
|
|
|
ensureUsers = [
|
|
|
|
{
|
|
|
|
name = "kadenios";
|
|
|
|
ensureDBOwnership = true;
|
|
|
|
}
|
|
|
|
];
|
2024-07-09 10:47:30 +02:00
|
|
|
};
|
|
|
|
}
|