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-02 20:54:45 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
sources,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
inherit (lib) mapAttrsToList;
|
|
|
|
|
2024-10-12 19:30:36 +02:00
|
|
|
host = "cas.eleves.ens.fr";
|
2024-07-02 20:54:45 +02:00
|
|
|
port = 9889;
|
|
|
|
|
2024-07-08 16:23:12 +02:00
|
|
|
python3 =
|
|
|
|
let
|
|
|
|
nix-pkgs = import sources.nix-pkgs {
|
|
|
|
inherit pkgs;
|
|
|
|
python3 = pkgs.python312;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
pkgs.python312.override {
|
|
|
|
packageOverrides = _: _: {
|
|
|
|
inherit (nix-pkgs) django-browser-reload django-bulma-forms loadcredential;
|
|
|
|
|
|
|
|
django-cas-server = nix-pkgs.django-cas-server.overridePythonAttrs (_: {
|
|
|
|
patches = [ ./01-pytest-cas.patch ];
|
|
|
|
});
|
|
|
|
};
|
2024-07-07 13:56:10 +02:00
|
|
|
};
|
|
|
|
|
2024-07-02 20:54:45 +02:00
|
|
|
pythonEnv = python3.withPackages (ps: [
|
|
|
|
ps.django
|
|
|
|
ps.ldap3
|
|
|
|
ps.gunicorn
|
|
|
|
ps.psycopg
|
|
|
|
|
|
|
|
# Local packages
|
2024-07-07 13:56:10 +02:00
|
|
|
ps.django-browser-reload
|
|
|
|
ps.django-bulma-forms
|
|
|
|
ps.django-cas-server
|
|
|
|
ps.loadcredential
|
2024-07-02 20:54:45 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
staticDrv = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "cas_eleves-static";
|
|
|
|
|
|
|
|
src = sources.cas-eleves;
|
|
|
|
|
|
|
|
nativeBuildInputs = [ pythonEnv ];
|
|
|
|
|
|
|
|
configurePhase = ''
|
|
|
|
export CE_STATIC_ROOT=$out/static
|
|
|
|
export CE_DEBUG=true
|
|
|
|
export CREDENTIALS_DIRECTORY=$(pwd)/.credentials
|
|
|
|
'';
|
|
|
|
|
2024-07-09 10:46:58 +02:00
|
|
|
doBuild = false;
|
2024-07-02 20:54:45 +02:00
|
|
|
|
|
|
|
installPhase = ''
|
2024-07-09 10:46:58 +02:00
|
|
|
mkdir -p $out/static
|
2024-07-02 20:54:45 +02:00
|
|
|
python3 manage.py collectstatic
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
systemd.services = {
|
2024-07-03 14:56:46 +02:00
|
|
|
django-cas-eleves = {
|
2024-07-02 20:54:45 +02:00
|
|
|
description = "ENS CAS server";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2024-07-03 14:56:46 +02:00
|
|
|
after = [
|
|
|
|
"network.target"
|
|
|
|
"postgresql.service"
|
|
|
|
];
|
2024-07-02 20:54:45 +02:00
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
DynamicUser = true;
|
|
|
|
LoadCredential = mapAttrsToList (name: value: "${name}:${value}") {
|
|
|
|
SECRET_KEY = config.age.secrets."cas_eleves-secret_key_file".path;
|
|
|
|
};
|
|
|
|
StateDirectory = "django-cas-eleves";
|
|
|
|
User = "cas_server";
|
|
|
|
WorkingDirectory = sources.cas-eleves;
|
|
|
|
};
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
CE_ALLOWED_HOSTS = builtins.toJSON [
|
|
|
|
"cas-eleves.dgnum.eu"
|
|
|
|
"cas.eleves.ens.fr"
|
|
|
|
];
|
|
|
|
CE_STATIC_ROOT = staticDrv;
|
|
|
|
};
|
|
|
|
|
|
|
|
path = [ pythonEnv ];
|
|
|
|
|
|
|
|
script = ''
|
2024-07-04 21:22:13 +02:00
|
|
|
python3 manage.py loaddata patterns
|
2024-07-02 20:54:45 +02:00
|
|
|
python3 manage.py migrate
|
|
|
|
gunicorn app.wsgi --pythonpath ${sources.cas-eleves} -b 127.0.0.1:${builtins.toString port} --workers=2 --threads=4
|
|
|
|
'';
|
|
|
|
};
|
2024-07-03 14:56:46 +02:00
|
|
|
|
|
|
|
cas-eleves-cleanup = {
|
|
|
|
description = "Periodic cleanup of cas_server database";
|
|
|
|
|
|
|
|
startAt = "daily";
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
|
|
|
|
LoadCredential = mapAttrsToList (name: value: "${name}:${value}") {
|
|
|
|
SECRET_KEY = config.age.secrets."cas_eleves-secret_key_file".path;
|
|
|
|
};
|
|
|
|
StateDirectory = "django-cas-eleves";
|
|
|
|
User = "cas_server";
|
|
|
|
WorkingDirectory = sources.cas-eleves;
|
|
|
|
};
|
|
|
|
|
|
|
|
path = [ pythonEnv ];
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
python3 manage.py clearsessions
|
|
|
|
python3 manage.py cas_clean_sessions
|
|
|
|
python3 manage.py cas_clean_tickets
|
|
|
|
'';
|
|
|
|
};
|
2024-07-02 20:54:45 +02:00
|
|
|
};
|
|
|
|
|
2024-09-30 20:11:56 +02:00
|
|
|
dgn-redirections.permanent."cas-eleves.dgnum.eu" = "cas.eleves.ens.fr";
|
2024-07-28 14:10:42 +02:00
|
|
|
|
2024-10-12 19:30:36 +02:00
|
|
|
dgn-web.simpleProxies.cas-eleves = {
|
|
|
|
inherit host port;
|
|
|
|
vhostConfig = {
|
2024-07-12 19:13:04 +02:00
|
|
|
serverAliases = [ "cas-eleves.dgnum.eu" ];
|
2024-07-02 20:54:45 +02:00
|
|
|
locations = {
|
|
|
|
"/static/".root = staticDrv;
|
|
|
|
"= /robots.txt".root = "${staticDrv}/static";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-10-12 19:30:36 +02:00
|
|
|
|
|
|
|
services.postgresql = {
|
|
|
|
ensureDatabases = [ "cas_server" ];
|
|
|
|
ensureUsers = [
|
|
|
|
{
|
|
|
|
name = "cas_server";
|
|
|
|
ensureDBOwnership = true;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2024-07-02 20:54:45 +02:00
|
|
|
}
|