2021-01-20 00:21:21 +00:00
|
|
|
{ config, options, depot, lib, ... }:
|
2021-01-19 23:41:47 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
inherit (depot.ops) secrets;
|
|
|
|
pkg = depot.web.quotes;
|
|
|
|
|
|
|
|
sock = "/run/quotesdb/gunicorn.sock";
|
|
|
|
in
|
|
|
|
{
|
2021-01-20 00:21:21 +00:00
|
|
|
options = with lib; {
|
|
|
|
my.quotesdb.listen = lib.mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [ "127.0.0.1" "[::1]" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = let
|
|
|
|
nginxListen = (map (addr: {
|
|
|
|
inherit addr;
|
|
|
|
port = 80;
|
|
|
|
ssl = false;
|
|
|
|
}) config.my.quotesdb.listen) ++ (map (addr: {
|
|
|
|
inherit addr;
|
|
|
|
port = 443;
|
|
|
|
ssl = true;
|
|
|
|
}) config.my.quotesdb.listen);
|
|
|
|
in {
|
2022-03-17 23:31:55 +00:00
|
|
|
my.vault.acmeCertificates.bfob = {
|
|
|
|
hostnames = [ "bfob.gg" "*.bfob.gg" ];
|
2022-03-07 00:52:03 +00:00
|
|
|
nginxVirtualHosts = [ "qdb.bfob.gg" "quotes.bfob.gg" "dev-quotes.bfob.gg" ];
|
2021-01-19 23:41:47 +00:00
|
|
|
};
|
|
|
|
services.nginx = {
|
|
|
|
enable = lib.mkDefault true;
|
|
|
|
virtualHosts."qdb.bfob.gg" = {
|
2021-01-20 00:21:21 +00:00
|
|
|
listen = nginxListen;
|
2021-01-19 23:41:47 +00:00
|
|
|
globalRedirect = "quotes.bfob.gg";
|
|
|
|
forceSSL = true;
|
|
|
|
};
|
|
|
|
virtualHosts."quotes.bfob.gg" = {
|
2021-01-20 00:21:21 +00:00
|
|
|
listen = nginxListen;
|
2021-01-19 23:41:47 +00:00
|
|
|
forceSSL = true;
|
|
|
|
locations."/static" = {
|
|
|
|
root = "${pkg}/share";
|
|
|
|
};
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://unix:${sock}";
|
|
|
|
};
|
|
|
|
};
|
2021-01-20 00:22:54 +00:00
|
|
|
virtualHosts."dev-quotes.bfob.gg" = {
|
|
|
|
listen = nginxListen;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://127.0.0.1:8000";
|
|
|
|
};
|
|
|
|
};
|
2021-01-19 23:41:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
services.postgresql = {
|
|
|
|
enable = lib.mkDefault true;
|
|
|
|
ensureDatabases = lib.mkAfter [ "quotesdb" ];
|
|
|
|
ensureUsers = lib.mkAfter [{
|
|
|
|
name = "quotesdb";
|
|
|
|
ensurePermissions = {
|
|
|
|
"DATABASE quotesdb" = "ALL PRIVILEGES";
|
|
|
|
};
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
2022-01-01 21:49:23 +00:00
|
|
|
users.users.quotesdb = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = "nginx";
|
|
|
|
};
|
|
|
|
users.groups.quotesdb = {};
|
|
|
|
|
2021-01-19 23:41:47 +00:00
|
|
|
systemd.services.quotesdb = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
2021-01-19 23:43:43 +00:00
|
|
|
environment.DJANGO_SETTINGS_MODULE = "quotes.quotesapp.prod_settings";
|
|
|
|
preStart = ''
|
|
|
|
${pkg}/bin/quotes-manage migrate --no-input
|
|
|
|
'';
|
2021-01-19 23:41:47 +00:00
|
|
|
serviceConfig = {
|
|
|
|
EnvironmentFile = secrets.quotesdb.environment;
|
|
|
|
RuntimeDirectory = "quotesdb";
|
|
|
|
ExecStart = "${pkg}/bin/quotes --workers 3 --bind unix:${sock}";
|
2022-01-01 21:49:23 +00:00
|
|
|
User = "quotesdb";
|
2021-01-19 23:41:47 +00:00
|
|
|
Group = "nginx";
|
|
|
|
UMask = "0007";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|