Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/nginx: add option typesHashMaxSize #341072

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions nixos/modules/services/web-servers/nginx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,9 @@ let
''));

commonHttpConfig = ''
# Load mime types.
# Load mime types and configure maximum size of the types hash tables.
include ${cfg.defaultMimeTypes};
# When recommendedOptimisation is disabled nginx fails to start because the mailmap mime.types database
# contains 1026 entries and the default is only 1024. Setting to a higher number to remove the need to
# overwrite it because nginx does not allow duplicated settings.
types_hash_max_size 4096;
types_hash_max_size ${toString cfg.typesHashMaxSize};

include ${cfg.package}/conf/fastcgi.conf;
include ${cfg.package}/conf/uwsgi_params;
Expand Down Expand Up @@ -896,6 +893,19 @@ in
'';
};

typesHashMaxSize = mkOption {
type = types.ints.positive;
default = if cfg.defaultMimeTypes == "${pkgs.mailcap}/etc/nginx/mime.types" then 2688 else 1024;
Copy link
Member

@SuperSandro2000 SuperSandro2000 Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should move this into a let in and deduplicate with the other option to prevent it accidentally getting out of date.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mime.types file is rarely updated. If it is, the test will show that a change will be required.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean defaultText? That option is in the very next line.

defaultText = literalExpression ''if cfg.defaultMimeTypes == "''${pkgs.mailcap}/etc/nginx/mime.types" then 2688 else 1024'';
description = ''
Sets the maximum size of the types hash tables (`types_hash_max_size`).
It is recommended that the minimum size possible size is used.
If {option}`recommendedOptimisation` is disabled, nginx would otherwise
fail to start since the mailmap `mime.types` database has more entries
than the nginx default value 1024.
'';
};

proxyCachePath = mkOption {
type = types.attrsOf (types.submodule ({ ... }: {
options = {
Expand Down
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ in {
nginx-etag-compression = handleTest ./nginx-etag-compression.nix {};
nginx-globalredirect = handleTest ./nginx-globalredirect.nix {};
nginx-http3 = handleTest ./nginx-http3.nix {};
nginx-mime = handleTest ./nginx-mime.nix {};
nginx-modsecurity = handleTest ./nginx-modsecurity.nix {};
nginx-moreheaders = handleTest ./nginx-moreheaders.nix {};
nginx-njs = handleTest ./nginx-njs.nix {};
Expand Down
26 changes: 26 additions & 0 deletions nixos/tests/nginx-mime.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import ./make-test-python.nix (
{ lib, pkgs, ... }:
{
name = "nginx-mime";
meta.maintainers = with pkgs.lib.maintainers; [ izorkin ];

nodes = {
server =
{ pkgs, ... }:
{
services.nginx = {
enable = true;
virtualHosts."localhost" = { };
};
};
};

testScript = ''
server.start()
server.wait_for_unit("nginx")
# Check optimal size of types_hash
server.fail("journalctl --unit nginx --grep 'could not build optimal types_hash'")
server.shutdown()
'';
}
)
3 changes: 3 additions & 0 deletions pkgs/data/misc/mailcap/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ lib
, stdenv
, fetchurl
, nixosTests

# updater
, git
Expand Down Expand Up @@ -44,6 +45,8 @@ stdenv.mkDerivation rec {
exec nix-update --version "$VERSION" "$@"
'';

passthru.tests.nginx-mime = nixosTests.nginx-mime;

meta = with lib; {
description = "Helper application and MIME type associations for file types";
homepage = "https://pagure.io/mailcap";
Expand Down