hackens-org-configurations/machines/hackens-org/orga/module.nix
2024-01-12 16:19:31 +01:00

65 lines
1.7 KiB
Nix

{ pkgs, lib, config, ... }:
let
app = "hackens_orga";
cfg = config.services.django.${app};
assets = cfg.assets;
in
{
options = {
services.django.${app} = {
enable = lib.mkEnableOption (lib.mdDoc "Enable django ${app}");
settings = lib.mkOption {
type = lib.types.submodule {
freeformType = with lib.types; attrsOf anything;
options = {
HACKENS_ORGA_STATIC_ROOT = lib.mkOption {
type = lib.types.path;
default = builtins.toString assets.static-assets;
};
};
};
};
assets = lib.mkOption {
type = lib.types.attrsOf lib.types.anything;
description = lib.mdDoc "Assets for django";
};
port = lib.mkOption {
type = lib.types.port;
default = 51666;
};
processes = lib.mkOption {
type = lib.types.int;
default = 2;
};
threads = lib.mkOption {
type = lib.types.int;
default = 2;
};
};
};
config = lib.mkIf cfg.enable {
systemd.services."django-${app}" = {
description = "${app} django service";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
User = "django-${app}";
};
script = ''
source ${assets.envFile}
${assets.managePy} migrate
${assets.python}/bin/gunicorn ${app}.wsgi \
--pythonpath ${assets.source}/${app} \
-b 127.0.0.1:${toString cfg.port} \
--workers=${toString cfg.processes} \
--threads=${toString cfg.threads}
'';
};
users.users."django-${app}" = {
isSystemUser = true;
group = "django-${app}";
};
users.groups."django-${app}" = {};
};
}