nixos-module.nix: init

This commit is contained in:
Astro 2020-12-03 22:45:35 +01:00
parent 3bb3e3bb0d
commit 68507c174a

59
nixos-module.nix Normal file
View file

@ -0,0 +1,59 @@
{ 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";
};
};
};
}