{ lib, config, inputs, ... }: let proxyReverseFixServices = [ "atticd" "audiobookshelf" "gitea" "lidarr" "ombi" "radarr" "sonarr" ]; proxyReversePrivateServices = [ "homepage" "prowlarr" "stash" ]; mkServiceConfig = type: services: lib.listToAttrs (map (name: lib.nameValuePair name { inherit type; }) services); standardProxyServices = (mkServiceConfig "proxyReverseFix" proxyReverseFixServices) // (mkServiceConfig "proxyReversePrivate" proxyReversePrivateServices); generateProxyConfig = serviceName: serviceConfig: let cfg = config.my.servers.${serviceName}; proxyFunc = if serviceConfig.type == "proxyReverse" then inputs.self.lib.proxyReverse else if serviceConfig.type == "proxyReverseFix" then inputs.self.lib.proxyReverseFix else if serviceConfig.type == "proxyReversePrivate" then inputs.self.lib.proxyReversePrivate else throw "Unknown proxy type: ${serviceConfig.type}"; in lib.nameValuePair cfg.host (lib.mkIf cfg.enableProxy (proxyFunc cfg)); standardProxyNames = builtins.attrNames standardProxyServices; customProxyServices = config.my.servers |> lib.filterAttrs ( name: srv: (srv.enableProxy or false) && (srv.useDefaultProxy or true) && !(builtins.elem name standardProxyNames) ) |> lib.mapAttrs (_name: _srv: { type = "proxyReverse"; }); in { config = lib.mkIf config.my.enableProxy { services.nginx.virtualHosts = lib.mapAttrs' generateProxyConfig ( standardProxyServices // customProxyServices ); }; }