1
0
Fork 0
piped-flake/module/frontend.nix

39 lines
963 B
Nix
Raw Normal View History

2023-09-08 10:59:27 +01:00
{
config,
lib,
...
2023-09-08 11:46:37 +01:00
}: let
inherit (lib.modules) mkIf mkDefault;
2023-09-08 11:46:37 +01:00
2023-09-08 10:59:27 +01:00
cfg = config.services.piped;
2023-09-08 11:46:37 +01:00
backendConfig = cfg.backend;
frontendConfig = cfg.frontend;
nginxConfig = frontendConfig.nginx;
frontendPackage = frontendConfig.package.override {
backendDomain = backendConfig.domain;
};
2023-09-08 10:59:27 +01:00
in {
config = mkIf (cfg.enable && frontendConfig.enable) {
2023-09-08 10:59:27 +01:00
# https://github.com/TeamPiped/Piped/blob/master/docker/nginx.conf
services.nginx = {
enable = true;
virtualHosts."${frontendConfig.domain}" = {
forceSSL = mkDefault nginxConfig.forceSSL;
enableACME = mkDefault nginxConfig.enableACME;
locations."/" = {
root = "${frontendPackage}/share/piped-frontend";
index = "index.html index.htm";
};
# I have no idea why try_files for Single Page Apps doesn't work here
extraConfig = ''
error_page 404 =200 /index.html;
'';
2023-09-08 10:59:27 +01:00
};
};
};
}