2022-03-17 21:51:11 +02:00
|
|
|
{ config, inputs, pkgs, ... }:
|
|
|
|
let
|
|
|
|
dataDir = "/srv/data/SHINOBI/shinobi";
|
|
|
|
|
|
|
|
shinobiConfigJson = builtins.toJSON {
|
|
|
|
ffmpegBinary = "${pkgs.ffmpeg}/bin/ffmpeg";
|
|
|
|
port = 38080;
|
|
|
|
db = {
|
|
|
|
host = "127.0.0.1";
|
|
|
|
port = 3306;
|
|
|
|
user = "majesticflame";
|
|
|
|
database = "ccio";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "shinobi-conf.json" shinobiConfigJson;
|
|
|
|
|
|
|
|
secretFile = config.age.secrets.shinobi-secrets.path;
|
|
|
|
|
|
|
|
inherit (inputs.self.packages.${pkgs.system}) shinobi;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
age.secrets.shinobi-secrets = {
|
|
|
|
file = ../../../secrets/shinobi-secrets.age;
|
|
|
|
owner = "shinobi";
|
|
|
|
group = "shinobi";
|
|
|
|
mode = "0400";
|
|
|
|
};
|
|
|
|
services.mysql = {
|
|
|
|
enable = true;
|
|
|
|
settings.mysqld.bind-address = "127.0.0.1";
|
|
|
|
package = pkgs.mariadb;
|
|
|
|
dataDir = "/srv/data/DB/mariadb";
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.shinobi = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = "shinobi";
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.shinobi = {};
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [ "d '${dataDir}' 0750 shinobi shinobi - -" ];
|
|
|
|
|
|
|
|
systemd.services.shinobi = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = [ pkgs.bash pkgs.nodejs-14_x ];
|
|
|
|
preStart = ''
|
|
|
|
${pkgs.jq}/bin/jq --slurp '.[0] * .[1]' ${configFile} ${secretFile} | install -Dm600 -o shinobi -g shinobi /dev/stdin ${dataDir}/conf.json
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
WorkingDirectory = dataDir;
|
2022-03-17 23:26:42 +02:00
|
|
|
User = "shinobi";
|
2022-03-17 21:51:11 +02:00
|
|
|
ExecStart = "${pkgs.nodejs-14_x}/bin/node ${shinobi}/bin/shinobi";
|
|
|
|
KillSignal = "HUP";
|
2022-03-18 13:53:15 +02:00
|
|
|
OOMPolicy = "continue";
|
|
|
|
Restart = "on-abnormal";
|
|
|
|
RestartSec = "5s";
|
2022-03-17 21:51:11 +02:00
|
|
|
};
|
|
|
|
environment.NODE_PATH = "${shinobi}/lib/node_modules/shinobi/node_modules";
|
|
|
|
};
|
2022-03-17 22:01:36 +02:00
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = [ 38080 ];
|
2022-03-17 21:51:11 +02:00
|
|
|
}
|