2020-12-03 21:45:35 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
yammat = import ./. { inherit pkgs; };
|
|
|
|
cfg = config.services.yammat;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.yammat = with lib; {
|
|
|
|
enable = mkEnableOption "Yammat";
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "yammat";
|
|
|
|
description = "System user to run Yammat";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "yammat";
|
|
|
|
description = "System group to run Yammat";
|
|
|
|
};
|
2021-03-07 07:34:19 +00:00
|
|
|
|
|
|
|
config = mkOption {
|
2021-03-10 00:53:35 +00:00
|
|
|
type = types.lines;
|
2021-03-10 00:49:40 +00:00
|
|
|
default = builtins.readFile ./config/settings.yml;
|
2021-03-07 07:34:19 +00:00
|
|
|
description = "Configuration for Yammat";
|
|
|
|
};
|
2020-12-03 21:45:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
users.users.${cfg.user} = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = cfg.group;
|
|
|
|
};
|
|
|
|
users.groups.${cfg.group} = {};
|
|
|
|
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
|
|
|
ensureDatabases = [ "yammat" ];
|
|
|
|
ensureUsers = [ {
|
|
|
|
name = cfg.user;
|
|
|
|
ensurePermissions = {
|
|
|
|
"DATABASE yammat" = "ALL PRIVILEGES";
|
|
|
|
};
|
|
|
|
} ];
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.yammat = {
|
|
|
|
description = "Yammat Matemat";
|
|
|
|
after = [ "postgresql.service" ];
|
|
|
|
requires = [ "postgresql.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
environment = {
|
|
|
|
APPROOT = yammat;
|
|
|
|
STATIC_DIR = "${yammat}/static";
|
|
|
|
PGHOST = "";
|
|
|
|
};
|
2021-03-07 18:27:21 +00:00
|
|
|
# make sendmail available
|
|
|
|
path = [ "/run/wrappers" ];
|
2020-12-03 21:45:35 +00:00
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
WorkingDirectory = yammat;
|
2021-03-10 00:49:47 +00:00
|
|
|
ExecStart = "${yammat}/bin/yammat /etc/yammat.yml";
|
2020-12-03 21:45:35 +00:00
|
|
|
};
|
|
|
|
};
|
2021-03-07 07:34:19 +00:00
|
|
|
|
|
|
|
environment.etc."yammat.yml" = {
|
|
|
|
enable = true;
|
|
|
|
text = cfg.config;
|
|
|
|
};
|
2020-12-03 21:45:35 +00:00
|
|
|
};
|
|
|
|
}
|