Unverified Commit 303bd807 authored by Maximilian Bosch's avatar Maximilian Bosch Committed by GitHub
Browse files

Merge: nixos/nginx: add locations."name".uwsgiPass option and use it (#346776)

parents cc65a31c 2ad694ff
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -447,7 +447,7 @@ in {
      enable = lib.mkDefault true;
      virtualHosts = lib.genAttrs cfg.webHosts (webHost: {
        locations = {
          ${cfg.serve.virtualRoot}.extraConfig = "uwsgi_pass unix:/run/mailman-web.socket;";
          ${cfg.serve.virtualRoot}.uwsgiPass = "unix:/run/mailman-web.socket";
          "${lib.removeSuffix "/" cfg.serve.virtualRoot}/static/".alias = webSettings.STATIC_ROOT + "/";
        };
      });
+54 −1
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ let
    REDIRECT_STATUS   = "200";
  };

  recommendedProxyConfig = pkgs.writeText "nginx-recommended-proxy-headers.conf" ''
  recommendedProxyConfig = pkgs.writeText "nginx-recommended-proxy_set_header-headers.conf" ''
    proxy_set_header        Host $host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -240,6 +240,14 @@ let
        include ${recommendedProxyConfig};
      ''}

      ${optionalString cfg.recommendedUwsgiSettings ''
        uwsgi_connect_timeout   ${cfg.uwsgiTimeout};
        uwsgi_send_timeout      ${cfg.uwsgiTimeout};
        uwsgi_read_timeout      ${cfg.uwsgiTimeout};
        uwsgi_param             HTTP_CONNECTION "";
        include ${cfg.package}/conf/uwsgi_params;
      ''}

      ${optionalString (cfg.mapHashBucketSize != null) ''
        map_hash_bucket_size ${toString cfg.mapHashBucketSize};
      ''}
@@ -444,6 +452,13 @@ let
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
      ''}
      ${optionalString (config.uwsgiPass != null && !cfg.uwsgiResolveWhileRunning)
        "uwsgi_pass ${config.uwsgiPass};"
      }
      ${optionalString (config.uwsgiPass != null && cfg.uwsgiResolveWhileRunning) ''
        set $nix_proxy_target "${config.uwsgiPass}";
        uwsgi_pass $nix_proxy_target;
      ''}
      ${concatStringsSep "\n"
        (mapAttrsToList (n: v: ''fastcgi_param ${n} "${v}";'')
          (optionalAttrs (config.fastcgiParams != {})
@@ -455,6 +470,7 @@ let
      ${optionalString (config.return != null) "return ${toString config.return};"}
      ${config.extraConfig}
      ${optionalString (config.proxyPass != null && config.recommendedProxySettings) "include ${recommendedProxyConfig};"}
      ${optionalString (config.uwsgiPass != null && config.recommendedUwsgiSettings) "include ${cfg.package}/conf/uwsgi_params;"}
      ${mkBasicAuth "sublocation" config}
    }
  '') (sortProperties (mapAttrsToList (k: v: v // { location = k; }) locations)));
@@ -555,6 +571,23 @@ in
        '';
      };

      recommendedUwsgiSettings = mkOption {
        default = false;
        type = types.bool;
        description = ''
          Whether to enable recommended uwsgi settings if a vhost does not specify the option manually.
        '';
      };

      uwsgiTimeout = mkOption {
        type = types.str;
        default = "60s";
        example = "20s";
        description = ''
          Change the uwsgi related timeouts in recommendedUwsgiSettings.
        '';
      };

      defaultListen = mkOption {
        type = with types; listOf (submodule {
          options = {
@@ -864,6 +897,16 @@ in
        '';
      };

      uwsgiResolveWhileRunning = mkOption {
        type = types.bool;
        default = false;
        description = ''
          Resolves domains of uwsgi targets at runtime
          and not only at start, you have to set
          services.nginx.resolver, too.
        '';
      };

      mapHashBucketSize = mkOption {
        type = types.nullOr (types.enum [ 32 64 128 ]);
        default = null;
@@ -1161,6 +1204,16 @@ in
        '';
      }

      {
        assertion = all (host:
          all (location: !(location.proxyPass != null && location.uwsgiPass != null)) (attrValues host.locations))
        (attrValues virtualHosts);
        message = ''
          Options services.nginx.service.virtualHosts.<name>.proxyPass and
          services.nginx.virtualHosts.<name>.uwsgiPass are mutually exclusive.
        '';
      }

      {
        assertion = cfg.package.pname != "nginxQuic" && cfg.package.pname != "angieQuic" -> !(cfg.enableQuicBPF);
        message = ''
+19 −0
Original line number Diff line number Diff line
@@ -53,6 +53,16 @@ with lib;
      '';
    };

    uwsgiPass = mkOption {
      type = types.nullOr types.str;
      default = null;
      example = "unix:/run/example/example.sock";
      description = ''
        Adds uwsgi_pass directive and sets recommended proxy headers if
        recommendedUwsgiSettings is enabled.
      '';
    };

    index = mkOption {
      type = types.nullOr types.str;
      default = null;
@@ -134,5 +144,14 @@ with lib;
        Enable recommended proxy settings.
      '';
    };

    recommendedUwsgiSettings = mkOption {
      type = types.bool;
      default = config.services.nginx.recommendedUwsgiSettings;
      defaultText = literalExpression "config.services.nginx.recommendedUwsgiSettings";
      description = ''
        Enable recommended uwsgi settings.
      '';
    };
  };
}