Skip to content

Commit

Permalink
nixos/nginx: add option typesHashMaxSize
Browse files Browse the repository at this point in the history
  • Loading branch information
Izorkin committed Sep 12, 2024
1 parent d77ecc7 commit a1dac0a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
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;
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
5 changes: 5 additions & 0 deletions nixos/tests/nginx.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ import ./make-test-python.nix ({ pkgs, ... }: {
wait_for_nginx_on_port(80)
with subtest("check optimal size of types_hash"):
webserver.fail(
"journalctl --unit nginx --grep 'could not build optimal types_hash'"
)
with subtest("check ETag if serving Nix store paths"):
old_etag = check_etag()
webserver.succeed(
Expand Down
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 = nixosTests.nginx;

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

0 comments on commit a1dac0a

Please sign in to comment.