60 lines
1.3 KiB
Nix
60 lines
1.3 KiB
Nix
|
{ 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";
|
||
|
};
|
||
|
};
|
||
|
|
||
|
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;
|
||
|
ExecStart = "${yammat}/bin/yammat";
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
}
|