From d856c0374dde8fa015ca4f3d1ab81150ac497d80 Mon Sep 17 00:00:00 2001 From: Izorkin Date: Tue, 10 Sep 2024 21:48:59 +0300 Subject: [PATCH 1/2] nixos/nginx: add option typesHashMaxSize --- .../services/web-servers/nginx/default.nix | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/nixos/modules/services/web-servers/nginx/default.nix b/nixos/modules/services/web-servers/nginx/default.nix index b5ff630a4d48..a7efd69adac3 100644 --- a/nixos/modules/services/web-servers/nginx/default.nix +++ b/nixos/modules/services/web-servers/nginx/default.nix @@ -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; @@ -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; + 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 = { From 9343e69f8fd394b8d54c9486919733bce840b738 Mon Sep 17 00:00:00 2001 From: Izorkin Date: Wed, 25 Sep 2024 20:55:38 +0300 Subject: [PATCH 2/2] nixos/tests/nginx-mime: add check optimal size of types_hash --- nixos/tests/all-tests.nix | 1 + nixos/tests/nginx-mime.nix | 26 ++++++++++++++++++++++++++ pkgs/data/misc/mailcap/default.nix | 3 +++ 3 files changed, 30 insertions(+) create mode 100644 nixos/tests/nginx-mime.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 27d5b79c95c4..4d5fc7884fe9 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -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 {}; diff --git a/nixos/tests/nginx-mime.nix b/nixos/tests/nginx-mime.nix new file mode 100644 index 000000000000..157b9f13f142 --- /dev/null +++ b/nixos/tests/nginx-mime.nix @@ -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() + ''; + } +) diff --git a/pkgs/data/misc/mailcap/default.nix b/pkgs/data/misc/mailcap/default.nix index b3560ecc505c..452e6f661abf 100644 --- a/pkgs/data/misc/mailcap/default.nix +++ b/pkgs/data/misc/mailcap/default.nix @@ -1,6 +1,7 @@ { lib , stdenv , fetchurl +, nixosTests # updater , git @@ -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";