diff --git a/hosts/hetzner-vm/modules/piped/backend.nix b/hosts/hetzner-vm/modules/piped/backend.nix index 11b2163..df5bad2 100644 --- a/hosts/hetzner-vm/modules/piped/backend.nix +++ b/hosts/hetzner-vm/modules/piped/backend.nix @@ -47,7 +47,7 @@ let (mapAttrsToList (n: v: "${n}:${cfgToString v}") backend_config)); in { - config = (lib.mkIf cfg.enable) { + config = lib.mkIf (cfg.enable && !cfg.disableBackend) { systemd.tmpfiles.rules = [ "d /run/piped-backend - root root" ]; systemd.services.piped-backend = { diff --git a/hosts/hetzner-vm/modules/piped/default.nix b/hosts/hetzner-vm/modules/piped/default.nix index 768c5de..b154877 100644 --- a/hosts/hetzner-vm/modules/piped/default.nix +++ b/hosts/hetzner-vm/modules/piped/default.nix @@ -6,10 +6,32 @@ in { enable = mkEnableOption "piped"; frontendDomain = mkOption { type = types.str; }; - backendDomain = mkOption { type = types.str; }; + backendDomain = mkOption { + type = types.nullOr types.str; + default = null; + description = "Set to null to use project default backend"; + }; proxyDomain = mkOption { type = types.str; }; #rydProxyDomain = mkOption { type = types.str; }; + disableFrontend = mkOption { + type = types.bool; + default = false; + description = "Don't host frontend"; + }; + + disableBackend = mkOption { + type = types.bool; + default = false; + description = "Don't host backend"; + }; + + disableProxy = mkOption { + type = types.bool; + default = false; + description = "Don't host proxy"; + }; + feedRetentionDays = mkOption { type = types.number; default = 30; diff --git a/hosts/hetzner-vm/modules/piped/frontend.nix b/hosts/hetzner-vm/modules/piped/frontend.nix index b18e283..6ab01b9 100644 --- a/hosts/hetzner-vm/modules/piped/frontend.nix +++ b/hosts/hetzner-vm/modules/piped/frontend.nix @@ -4,9 +4,8 @@ let cfg = config.services.piped; frontend-package = (pkgs.piped-frontend.override { backendDomain = cfg.backendDomain; }); - in { - config = (lib.mkIf cfg.enable) { + config = lib.mkIf (cfg.enable && !cfg.disableFrontend) { services.nginx.virtualHosts."${cfg.frontendDomain}" = { forceSSL = true; enableACME = true; diff --git a/hosts/hetzner-vm/modules/piped/proxy.nix b/hosts/hetzner-vm/modules/piped/proxy.nix index fba2c8c..2e8fa80 100644 --- a/hosts/hetzner-vm/modules/piped/proxy.nix +++ b/hosts/hetzner-vm/modules/piped/proxy.nix @@ -23,35 +23,37 @@ let access_log off; ''; in { - systemd.tmpfiles.rules = [ - "d /run/piped-proxy - nginx nginx" - "d /run/piped-proxy/socket - nginx nginx" - ]; + config = lib.mkIf (cfg.enable && !cfg.disableProxy) { + systemd.tmpfiles.rules = [ + "d /run/piped-proxy - nginx nginx" + "d /run/piped-proxy/socket - nginx nginx" + ]; - systemd.services.piped-proxy = { - wantedBy = [ "multi-user.target" ]; - environment.UDS = "1"; - serviceConfig = { - User = "nginx"; - WorkingDirectory = "/run/piped-proxy"; - ExecStart = "${pkgs.piped-proxy}/bin/piped-proxy"; + systemd.services.piped-proxy = { + wantedBy = [ "multi-user.target" ]; + environment.UDS = "1"; + serviceConfig = { + User = "nginx"; + WorkingDirectory = "/run/piped-proxy"; + ExecStart = "${pkgs.piped-proxy}/bin/piped-proxy"; + }; }; - }; - services.nginx.virtualHosts."${cfg.proxyDomain}" = { - forceSSL = true; - enableACME = true; - locations."/" = { - proxyPass = "http://unix:/run/piped-proxy/socket/actix.sock"; - extraConfig = proxy_nginx_extras + '' - add_header Cache-Control "public, max-age=604800"; - ''; - }; - locations."~ (/videoplayback|/api/v4/|/api/manifest/)" = { - proxyPass = "http://unix:/run/piped-proxy/socket/actix.sock"; - extraConfig = proxy_nginx_extras + '' - add_header Cache-Control private always; - ''; + services.nginx.virtualHosts."${cfg.proxyDomain}" = { + forceSSL = true; + enableACME = true; + locations."/" = { + proxyPass = "http://unix:/run/piped-proxy/socket/actix.sock"; + extraConfig = proxy_nginx_extras + '' + add_header Cache-Control "public, max-age=604800"; + ''; + }; + locations."~ (/videoplayback|/api/v4/|/api/manifest/)" = { + proxyPass = "http://unix:/run/piped-proxy/socket/actix.sock"; + extraConfig = proxy_nginx_extras + '' + add_header Cache-Control private always; + ''; + }; }; }; } diff --git a/overlay/piped/frontend/default.nix b/overlay/piped/frontend/default.nix index 087028a..972eb50 100644 --- a/overlay/piped/frontend/default.nix +++ b/overlay/piped/frontend/default.nix @@ -1,5 +1,6 @@ -{ stdenv, nodejs, nodePackages, mkYarnPackage, rsync, fetchFromGitHub -, backendDomain ? "CHANGE_ME", }: +{ stdenv, nodejs, nodePackages, mkYarnPackage, rsync, fetchFromGitHub, +# Backend domain override, if unset then use project default +backendDomain ? null, }: let meta = builtins.fromJSON (builtins.readFile ../meta.json); rev = meta.frontend.rev; @@ -18,8 +19,11 @@ in mkYarnPackage rec { yarnNix = ./yarn.nix; patchPhase = '' - sed -i "s#pipedapi.kavin.rocks#${backendDomain}#g" src/main.js - sed -i "s#pipedapi.kavin.rocks#${backendDomain}#g" src/components/PreferencesPage.vue + ${if backendDomain != null then '' + sed -i "s#pipedapi.kavin.rocks#${backendDomain}#g" src/main.js + sed -i "s#pipedapi.kavin.rocks#${backendDomain}#g" src/components/PreferencesPage.vue + '' else + ""} ''; buildPhase = ''