1
0
vcp-bula-nixfiles/hosts/nerd/nerd.nix

93 lines
2.1 KiB
Nix
Raw Normal View History

2022-07-12 11:04:14 +02:00
{ config, pkgs, lib, ... }:
{
sops.secrets.nerd_secret = {
sopsFile = ./secrets.yaml;
owner = "nerd";
restartUnits = [ "nerd.service" ];
};
systemd.services.nerd = let
nerdCfg = pkgs.writeText "nerd.cfg" ''
[django]
secret = !!DJANGO_SECRET!!
allowed_hosts = nerd.bula22.de
debug = False
language_code = de-de
time_zone = Europe/Berlin
csrf_trusted_origins = https://nerd.bula22.de
[database]
engine = postgresql_psycopg2
name = nerd
user =
password =
host = /run/postgresql
port =
'';
in {
2022-07-12 11:04:14 +02:00
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
environment = {
NERD_CONFIG_FILE = "/etc/nerd/nerd.cfg";
2022-07-12 11:04:14 +02:00
PYTHONPATH = "${pkgs.python3.pkgs.nerd.pythonPath}:${pkgs.python3.pkgs.nerd}/${pkgs.python3.sitePackages}:${pkgs.python3Packages.psycopg2}/${pkgs.python3.sitePackages}";
};
preStart = ''
export DJANGO_SECRET=$(cat ${config.sops.secrets.nerd_secret.path})
${pkgs.gnused}/bin/sed -e "s/!!DJANGO_SECRET!!/$DJANGO_SECRET/g" ${nerdCfg} > /etc/nerd/nerd.cfg
${pkgs.python3.pkgs.nerd}/bin/nerd migrate
'';
2022-07-12 11:04:14 +02:00
serviceConfig = {
User = "nerd";
Group = "nerd";
ConfigurationDirectory = "nerd";
2022-07-12 11:04:14 +02:00
ExecStart = ''
${pkgs.python3Packages.gunicorn}/bin/gunicorn \
--bind 0.0.0.0:10510 \
--access-logfile - \
nerd.wsgi
'';
};
};
services.postgresql = {
enable = true;
ensureDatabases = [ "nerd" ];
ensureUsers = [
{
name = "nerd";
ensurePermissions = {
"DATABASE nerd" = "ALL PRIVILEGES";
};
}
];
};
users.users.nerd = {
isSystemUser = true;
group = "nerd";
};
users.groups.nerd = {};
networking.firewall.allowedTCPPorts = [ 80 443 ];
services.nginx.enable = lib.mkForce false;
2022-07-12 11:04:14 +02:00
services.caddy = {
enable = true;
virtualHosts."nerd.bula22.de" = {
extraConfig = ''
route {
file_server /static/*
reverse_proxy * http://127.0.0.1:10510
}
root * ${pkgs.python3.pkgs.nerd}/var/lib/nerd/
'';
};
};
}