From 25bd410599b17e21a8e03e9f6370e98cbf8c4185 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 23 Aug 2024 02:50:01 +0200 Subject: [PATCH] cluster/services/ways: support gRPC --- cluster/services/ways/host.nix | 9 ++++++++- cluster/services/ways/options/way.nix | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cluster/services/ways/host.nix b/cluster/services/ways/host.nix index 2185c72..90455c3 100644 --- a/cluster/services/ways/host.nix +++ b/cluster/services/ways/host.nix @@ -25,7 +25,14 @@ in ]; locations = lib.mkMerge [ { - "/".proxyPass = cfg.target; + "/" = if cfg.grpc then { + extraConfig = '' + set $nix_proxy_grpc_target ${cfg.target}; + grpc_pass $nix_proxy_grpc_target; + ''; + } else { + proxyPass = cfg.target; + }; "${cfg.healthCheckPath}".extraConfig = "access_log off;"; } { diff --git a/cluster/services/ways/options/way.nix b/cluster/services/ways/options/way.nix index 5206222..9c22016 100644 --- a/cluster/services/ways/options/way.nix +++ b/cluster/services/ways/options/way.nix @@ -35,6 +35,12 @@ with lib; }; }; + grpc = mkOption { + description = "Whether this endpoint is a gRPC service."; + type = types.bool; + default = false; + }; + target = mkOption { type = types.str; }; @@ -101,7 +107,7 @@ with lib; (lib.mkIf options.consulService.isDefined { useConsul = true; nginxUpstreamName = "ways_upstream_${builtins.hashString "md5" options.consulService.value}"; - target = "http://${options.nginxUpstreamName.value}"; + target = "${if config.grpc then "grpc" else "http"}://${options.nginxUpstreamName.value}"; }) (lib.mkIf options.bucket.isDefined { consulService = "garage-web";