maxwell/custom/modules/asjon.nix

118 lines
3.1 KiB
Nix
Raw Permalink Normal View History

2020-10-20 01:11:28 +02:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.asjon;
in {
options.services.asjon = {
enable = mkEnableOption "Asjon: our chat bot";
dataDir = mkOption {
type = types.path;
default = "/var/lib/asjon";
description = ''
Path where the settings and source tree will exist.
'';
};
user = mkOption {
type = types.str;
default = "asjon";
description = ''
Asjon will be run under this user (user will be created if it doesn't exist.
This can be your user name).
'';
};
2021-12-21 00:31:10 +01:00
group = mkOption {
type = types.str;
default = "asjon";
description = ''
Asjon will be run under this group (user will be created if it doesn't exist.
This can be your user name).
'';
};
2020-10-20 01:11:28 +02:00
};
config = mkIf cfg.enable {
2021-12-21 00:31:10 +01:00
users.users.${cfg.user} = {
group = cfg.group;
2020-10-20 01:11:28 +02:00
home = cfg.dataDir;
2021-06-17 19:06:04 +02:00
isSystemUser = true;
2020-10-20 01:11:28 +02:00
createHome = true;
description = "asjon user";
shell = "${pkgs.bash}/bin/bash";
};
2021-12-21 00:31:10 +01:00
users.groups.${cfg.group} = { };
2020-10-20 01:11:28 +02:00
systemd.services.asjon = {
description = "asjon: our chat bot";
after = [ "nginx.service" "matrix-synapse.service" "asjon-init.service" ];
2021-09-30 08:46:28 +02:00
partOf = [ "nginx.service" "matrix-synapse.service" "asjon-init.service" ];
2020-10-20 01:11:28 +02:00
wantedBy = [ "multi-user.target" ];
path = with pkgs; [
nodejs nodePackages.coffee-script
yarn openssh graphicsmagick git
bash
];
environment = {
# Matrix login
HUBOT_MATRIX_HOST_SERVER = "https://${config.var.hostname}";
# Git integration
HUBOT_GIT_URL = "https://${config.var.hostname}/git";
HUBOT_GIT_API = "https://${config.var.hostname}/git/api/v1";
HUBOT_GIT_REPO = "rnhmjoj/asjon";
# Scripts
AUTO_KILL_ON_UPDATE = "1";
2024-10-22 23:54:45 +02:00
AUTO_INFORM_ON_START = "!XQJXsOXfTevAiEbDTA:eurofusion.eu";
ADMIN_ROOM = "!XQJXsOXfTevAiEbDTA:eurofusion.eu";
2020-10-20 01:11:28 +02:00
REV_REMOTE_HOST = "proxy@rnhmjoj.ydns.eu";
REV_REMOTE_PORT = "22";
REV_KEY = "~/.ssh/proxy";
2022-08-08 16:32:30 +02:00
REDIS_URL = "redis:///run/redis-asjon/redis.sock";
2020-10-20 01:11:28 +02:00
};
serviceConfig = {
User = cfg.user;
ExecStart = "${cfg.dataDir}/tree/bin/hubot -a matrix";
Restart = "always";
WorkingDirectory = "${cfg.dataDir}/tree";
# API keys and passwords definitions
2021-09-29 17:20:23 +02:00
EnvironmentFile = config.secrets.environments.asjon;
2020-10-20 01:11:28 +02:00
};
};
systemd.services.asjon-init = {
description = "Initialize Asjon service (first time only)";
wants = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig.User = cfg.user;
path = with pkgs; [ git yarn acl ];
script = ''
if test -d ${cfg.dataDir}/tree/.git; then
exit 0
fi
# clone repository and install packages
git clone https://github.com/rnhmjoj/asjon.git ${cfg.dataDir}/tree
cd ${cfg.dataDir}/tree
yarn install
'';
};
};
}