Recreated options
This commit is contained in:
parent
0b839e082a
commit
fc8178ed80
22 changed files with 325 additions and 205 deletions
83
system/server/jsw-bot.nix
Normal file
83
system/server/jsw-bot.nix
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
inputs,
|
||||
...
|
||||
}: let
|
||||
name = "jsw-bot";
|
||||
cfg = import ./lib/extractWebOptions.nix {inherit config name;};
|
||||
|
||||
inherit (lib) getExe mkIf optional;
|
||||
inherit (config.niksos.server) nextcloud;
|
||||
|
||||
bash = getExe pkgs.bash;
|
||||
|
||||
mainDir = "/var/lib/dcbot/";
|
||||
programDir = mainDir + "program";
|
||||
dataDir = mainDir + "data";
|
||||
denoDir = mainDir + "deno";
|
||||
|
||||
path = builtins.concatStringsSep ":" (map (x: "${x}/bin/") [pkgs.coreutils pkgs.typst pkgs.deno]);
|
||||
in {
|
||||
options = import ./lib/webOptions.nix {
|
||||
inherit config lib name;
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
systemd.services.${name} = {
|
||||
enable = true;
|
||||
after = ["network.target"]; #FIXME: doesn't start after network.
|
||||
wantedBy = ["default.target"];
|
||||
description = "Jsw's slaafje, discord bot.";
|
||||
|
||||
environment = {
|
||||
"DENO_DIR" = denoDir;
|
||||
"PATH" = lib.mkForce path;
|
||||
};
|
||||
|
||||
preStart = ''
|
||||
export PATH=${path}
|
||||
|
||||
cd "${mainDir}"
|
||||
mkdir -p "${programDir}" "${dataDir}" "${denoDir}"
|
||||
|
||||
chown -R ${name}:${name} ${mainDir}* || echo
|
||||
chmod -R 750 ${mainDir}* || echo
|
||||
cp --no-preserve=mode,ownership -r ${inputs.dcbot}/* "${programDir}/"
|
||||
|
||||
rm "${dataDir}/.env" || echo
|
||||
ln -s "${config.age.secrets.jsw-bot.path}" "${dataDir}/.env"
|
||||
|
||||
cd "${programDir}"
|
||||
DENO_DIR=${denoDir} deno i
|
||||
'';
|
||||
|
||||
serviceConfig = {
|
||||
StateDirectory = name;
|
||||
ExecStart = "${bash} -c 'cd ${dataDir} && deno run -A ${programDir}/src/main.ts'";
|
||||
User = name;
|
||||
Group = name;
|
||||
Restart = "always";
|
||||
};
|
||||
};
|
||||
|
||||
services.caddy = {
|
||||
enable = true;
|
||||
virtualHosts.${cfg.domain} = {
|
||||
extraConfig = ''
|
||||
reverse_proxy :9001
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
users.groups."dcbot" = {
|
||||
members = optional nextcloud.enable "nextcloud"; #TODO: if config.niksos.server.nextcloud
|
||||
#NOTE: for nextcloud mounted folder
|
||||
};
|
||||
users.users."dcbot" = {
|
||||
group = "dcbot";
|
||||
isSystemUser = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue