permafrost/modules/foundry.nix

73 lines
2.2 KiB
Nix
Raw Normal View History

2024-12-28 00:22:32 -08:00
{ lib, config, pkgs, ... }:
2024-12-27 06:21:59 -08:00
let
cfg = config.permafrost.foundry;
2024-12-27 22:02:45 -08:00
ACMEEnabled = config.permafrost.acme.enable;
2024-12-27 06:21:59 -08:00
in
{
options.permafrost.foundry = {
enable = lib.mkEnableOption "foundry nixos module";
};
2024-12-27 20:14:55 -08:00
config = lib.mkIf cfg.enable (lib.mkMerge [
{
permafrost.nginx.enable = lib.mkDefault true;
}
2024-12-28 00:22:32 -08:00
{
users.groups.foundry = { };
users.users.foundry = {
group = "foundry";
isSystemUser = true;
description = "foundryvtt user";
};
systemd.services.foundry =
let
mainPath = "/home/foundry/foundryvtt/resources/app/main.js";
dataPath = "/home/foundry/foundrydata";
in
{
description = "foundryvtt service";
enable = true;
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
User = "foundry";
Restart = "always";
WorkingDirectory = "/home/foundry/foundryvtt";
ExecStart = "${lib.getExe pkgs.nodejs_20} ${mainPath} --dataPath=${dataPath}";
};
};
}
2024-12-27 20:14:55 -08:00
{
services.nginx.virtualHosts."scarlet.zynh.me" = {
serverName = "scarlet.zynh.me";
2024-12-27 21:59:07 -08:00
forceSSL = lib.mkIf ACMEEnabled true;
2024-12-27 20:14:55 -08:00
useACMEHost = lib.mkIf ACMEEnabled "permafrost";
locations."/" = {
extraConfig = /* nginx */ ''
# Set proxy headers
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
2024-12-27 06:21:59 -08:00
2024-12-27 20:14:55 -08:00
# These are important to support WebSockets
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
'';
proxyPass = "http://localhost:30000";
};
2024-12-27 06:21:59 -08:00
};
2024-12-27 20:14:55 -08:00
}
{
2024-12-27 22:02:45 -08:00
permafrost.acme.certDomains = lib.mkIf ACMEEnabled [ "ddbimporter.zynh.me" ];
2024-12-27 20:14:55 -08:00
services.nginx.virtualHosts."ddbimporter.zynh.me" = {
2024-12-27 22:02:45 -08:00
forceSSL = true;
2024-12-27 20:14:55 -08:00
useACMEHost = lib.mkIf ACMEEnabled "permafrost";
serverName = "ddbimporter.zynh.me";
locations."/".proxyPass = "http://localhost:3232";
};
}
]);
2024-12-27 06:21:59 -08:00
}