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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Izorkin
Copy link
Contributor

@Izorkin Izorkin commented Sep 10, 2024

Description of changes

Allow to change maximum size of the types hash tables.
It is recommended to reduce the size if a custom file with mime-types is used.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@pbsds
Copy link
Member

pbsds commented Sep 10, 2024

It is recommended to reduce the size if a custom file with mime-types is used.

source?

This strikes me like the kinda thing that explodes at runtime, not build/eval time. Can this be added to the tests?

@@ -896,6 +893,22 @@ 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.

@Izorkin
Copy link
Contributor Author

Izorkin commented Sep 11, 2024

source?

https://nginx.org/en/docs/hash.html

This strikes me like the kinda thing that explodes at runtime, not build/eval time. Can this be added to the tests?

I'll see what I can do.

@Izorkin
Copy link
Contributor Author

Izorkin commented Sep 11, 2024

Updated test.

Copy link
Member

@pbsds pbsds left a comment

Choose a reason for hiding this comment

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

I played a bit around with this.
If set to 1024:

vm-test-run-nginx> subtest: check optimal size of types_hash
vm-test-run-nginx> webserver: must fail: journalctl --unit nginx --grep 'could not build optimal types_hash'
vm-test-run-nginx> Test "check optimal size of types_hash" failed with error: "command `journalctl --unit nginx --grep 'could not build optimal types_hash'` unexpectedly succeeded"

if set to 4096, it passes.

if set to 16400, it passes.

How did you arrive at 2688? Is there any way to test for the max_size being too big? (assuming there is a performance penalty for that)

nixos/modules/services/web-servers/nginx/default.nix Outdated Show resolved Hide resolved
@Izorkin
Copy link
Contributor Author

Izorkin commented Sep 12, 2024

How did you arrive at 2688? Is there any way to test for the max_size being too big? (assuming there is a performance penalty for that)

I adjusted the parameter manually, in increments of 64 and the current mime.types file in the mailcap package.
If use a smaller mime.types file, the types_hash_max_size can be reduced.

Copy link
Member

@pbsds pbsds left a comment

Choose a reason for hiding this comment

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

LGTM, i leave it to code-owner to decide if the typesHashMaxSize limit should be this tight, and whether the types_hash test should be a (i assume) release blocker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants