2020-12-03 22:45:35 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
yammat = import ./. { inherit pkgs; };
|
|
|
|
cfg = config.services.yammat;
|
2021-03-07 08:34:19 +01:00
|
|
|
defaultConfig = ''
|
|
|
|
# Values formatted like "_env:ENV_VAR_NAME:default_value" can be overridden by the specified environment variable.
|
|
|
|
# See https://github.com/yesodweb/yesod/wiki/Configuration#overriding-configuration-values-with-environment-variables
|
|
|
|
|
|
|
|
static-dir: "_env:STATIC_DIR:static"
|
|
|
|
host: "_env:HOST:*4" # any IPv4 host
|
|
|
|
port: "_env:PORT:3000"
|
|
|
|
approot: "_env:APPROOT:http://localhost:3000"
|
|
|
|
ip-from-header: "_env:IP_FROM_HEADER:false"
|
|
|
|
|
|
|
|
# Optional values with the following production defaults.
|
|
|
|
# In development, they default to the inverse.
|
|
|
|
#
|
|
|
|
# development: false
|
|
|
|
# detailed-logging: false
|
|
|
|
# should-log-all: false
|
|
|
|
# reload-templates: false
|
|
|
|
# mutable-static: false
|
|
|
|
# skip-combining: false
|
|
|
|
|
|
|
|
database:
|
|
|
|
user: "_env:PGUSER:yammat"
|
|
|
|
password: "_env:PGPASS:yammat"
|
|
|
|
host: "_env:PGHOST:localhost"
|
|
|
|
port: "_env:PGPORT:5432"
|
|
|
|
database: "_env:PGDATABASE:yammat"
|
|
|
|
poolsize: "_env:PGPOOLSIZE:10"
|
|
|
|
|
|
|
|
email:
|
|
|
|
- "nek0@momen"
|
|
|
|
currency: "€"
|
|
|
|
cash_charge: 50
|
|
|
|
|
|
|
|
copyright: "Powered by YAMMAT"
|
|
|
|
copyright_link: "https://github.com/nek0/yammat"
|
|
|
|
|
|
|
|
block_users: false
|
|
|
|
|
|
|
|
sendmail-location: "/usr/sbin/sendmail"
|
|
|
|
from-mail: "matemat@matemat.hq.c3d2.de"
|
|
|
|
|
|
|
|
# optional administrative credentials.
|
|
|
|
# credentials:
|
|
|
|
# login: "admin"
|
|
|
|
# password: "password"
|
|
|
|
'';
|
2020-12-03 22:45:35 +01:00
|
|
|
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 08:34:19 +01:00
|
|
|
|
|
|
|
config = mkOption {
|
|
|
|
type = types.lines
|
|
|
|
example = ''
|
|
|
|
${defaultConfig}
|
|
|
|
'';
|
|
|
|
description = "Configuration for Yammat";
|
|
|
|
};
|
2020-12-03 22:45:35 +01: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 = "";
|
|
|
|
};
|
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
WorkingDirectory = yammat;
|
2021-03-07 19:46:36 +01:00
|
|
|
ExecStart = "${yammat}/bin/yammat /etc/yammata.yml";
|
2020-12-03 22:45:35 +01:00
|
|
|
};
|
|
|
|
};
|
2021-03-07 08:34:19 +01:00
|
|
|
|
|
|
|
environment.etc."yammat.yml" = {
|
|
|
|
enable = true;
|
|
|
|
text = cfg.config;
|
|
|
|
};
|
2020-12-03 22:45:35 +01:00
|
|
|
};
|
|
|
|
}
|