mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 12:29:19 -08:00
chore(bbuddy): websocket screen service
This commit is contained in:
parent
dc0c84c0a0
commit
c51fdb847b
2 changed files with 48 additions and 8 deletions
|
|
@ -42,6 +42,13 @@ in {
|
|||
default = [ "127.0.0.1" "::1" ];
|
||||
};
|
||||
};
|
||||
screen = {
|
||||
enable = mkEnableOption "websocket server";
|
||||
websocketPort = mkOption {
|
||||
type = port;
|
||||
default = 47631;
|
||||
};
|
||||
};
|
||||
redis = {
|
||||
enable = mkEnableOption "redis cache";
|
||||
server = mkOption {
|
||||
|
|
@ -77,7 +84,7 @@ in {
|
|||
bbuddyConfig.services.barcodebuddy = {
|
||||
settings = let
|
||||
defaults = mapOptionDefaults {
|
||||
PORT_WEBSOCKET_SERVER = 47631;
|
||||
${if cfg.screen.enable then "PORT_WEBSOCKET_SERVER" else null} = cfg.screen.websocketPort;
|
||||
SEARCH_ENGINE = "https://google.com/search?q=";
|
||||
${if cfg.reverseProxy.enable then "TRUSTED_PROXIES" else null} = cfg.reverseProxy.trustedAddresses;
|
||||
DISABLE_AUTHENTICATION = false;
|
||||
|
|
@ -133,7 +140,9 @@ in {
|
|||
all.pdo_sqlite
|
||||
all.sockets
|
||||
all.gettext
|
||||
] ++ optional cfg.redis.enable all.redis);
|
||||
all.session
|
||||
all.redis
|
||||
]);
|
||||
|
||||
settings = mapOptionDefaults {
|
||||
"pm.max_children" = 10;
|
||||
|
|
@ -157,6 +166,9 @@ in {
|
|||
virtualHosts."${cfg.hostName}" = {
|
||||
root = "${cfg.package}";
|
||||
locations = {
|
||||
"/api/".extraConfig = ''
|
||||
try_files $uri /api/index.php$is_args$query_string;
|
||||
'';
|
||||
"~ \\.php$".extraConfig = cfg.nginxPhpConfig;
|
||||
};
|
||||
extraConfig = ''
|
||||
|
|
@ -164,5 +176,18 @@ in {
|
|||
'';
|
||||
};
|
||||
};
|
||||
conf.systemd.services.bbuddy-websocket = mkIf cfg.screen.enable {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
environment = mapAttrs' toEnvPair cfg.settings;
|
||||
unitConfig = {
|
||||
Description = "Run websocket server for barcodebuddy screen feature";
|
||||
};
|
||||
serviceConfig = {
|
||||
ExecStart = "${config.services.phpfpm.pools.barcodebuddy.phpPackage}/bin/php ${cfg.package}/wsserver.php";
|
||||
Restart = "on-failure";
|
||||
StandardOutput = "null";
|
||||
User = "barcodebuddy";
|
||||
};
|
||||
};
|
||||
in mkMerge [ bbuddyConfig (mkIf cfg.enable conf) ];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
{config, lib, ...}: let
|
||||
inherit (lib.modules) mkDefault;
|
||||
inherit (lib.modules) mkIf mkMerge mkAfter mkDefault;
|
||||
inherit (config.services) nginx;
|
||||
cfg = config.services.barcodebuddy;
|
||||
in {
|
||||
|
|
@ -11,11 +11,23 @@ in {
|
|||
EXTERNAL_GROCY_URL = "https://grocy.${config.networking.domain}";
|
||||
DISABLE_AUTHENTICATION = true;
|
||||
};
|
||||
nginxPhpConfig = ''
|
||||
nginxPhpConfig = mkMerge [
|
||||
''
|
||||
include ${config.sops.secrets.barcodebuddy-fastcgi-params.path};
|
||||
'';
|
||||
''
|
||||
(mkIf nginx.virtualHosts.barcodebuddy.proxied.enabled (mkAfter ''
|
||||
set $bbuddy_https "";
|
||||
if ($x_scheme = https) {
|
||||
set $bbuddy_https 1;
|
||||
}
|
||||
fastcgi_param HTTPS $bbuddy_https if_not_empty;
|
||||
fastcgi_param REQUEST_SCHEME $x_scheme;
|
||||
fastcgi_param HTTP_HOST $x_forwarded_host;
|
||||
''))
|
||||
];
|
||||
};
|
||||
config.services.nginx.virtualHosts.barcodebuddy = {
|
||||
config.services.nginx.virtualHosts.barcodebuddy = mkIf cfg.enable {
|
||||
proxied.xvars.enable = true;
|
||||
vouch = {
|
||||
enable = true;
|
||||
requireAuth = false;
|
||||
|
|
@ -31,7 +43,10 @@ in {
|
|||
};
|
||||
};
|
||||
};
|
||||
config.sops.secrets.barcodebuddy-fastcgi-params = {
|
||||
config.users.users.barcodebuddy = mkIf cfg.enable {
|
||||
uid = 912;
|
||||
};
|
||||
config.sops.secrets.barcodebuddy-fastcgi-params = mkIf cfg.enable {
|
||||
sopsFile = mkDefault ./secrets/barcodebuddy.yaml;
|
||||
owner = mkDefault nginx.user;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue