-
-
Notifications
You must be signed in to change notification settings - Fork 16.6k
nixos/nginx: add option addMimeTypes #341414
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of conditioning the use of defaultMimeTypes
on the custom mime-types being empty, would it make sense to make defaultMimeTypes
nullable?
6a91bc2
to
c223d28
Compare
If The |
A common use case I see is that one would like to keep the default mime-types, but add one or two additional file types. |
Add another parameter |
This is what i envison: In addition to defaults:
Replacing defaults:
with a warning in This is only my preference however, and maybe code-owner @RaitoBezarius have a different opinion |
Perhaps renaming |
Allow this variant? diff --git a/nixos/modules/services/web-servers/nginx/default.nix b/nixos/modules/services/web-servers/nginx/default.nix
index f523833e5b66..5b425c147b6d 100644
--- a/nixos/modules/services/web-servers/nginx/default.nix
+++ b/nixos/modules/services/web-servers/nginx/default.nix
@@ -128,6 +128,10 @@ let
}
''));
+ addMimeTypeConfig = lib.concatLines (flip mapAttrsToList cfg.addMimeTypes (addMimeType: extensions: ''
+ ${addMimeType} ${concatStringsSep " " extensions};
+ ''));
+
mimeTypeConfig = lib.concatLines (flip mapAttrsToList cfg.mimeTypes (mimeType: extensions: ''
${mimeType} ${concatStringsSep " " extensions};
''));
@@ -136,7 +140,10 @@ let
# Load mime types.
default_type application/octet-stream;
${optionalString (cfg.mimeTypes == {}) "include ${cfg.defaultMimeTypes};"}
- ${optionalString (cfg.mimeTypes != {}) "types {\n${mimeTypeConfig}\n}"}
+ ${optionalString (cfg.mimeTypes != {} || cfg.addMimeTypes != {}) "types {\n"}
+ ${optionalString (cfg.addMimeTypes != {} && cfg.mimeTypes == {}) "${addMimeTypeConfig}"}
+ ${optionalString (cfg.mimeTypes != {}) "${mimeTypeConfig}"}
+ ${optionalString (cfg.mimeTypes != {} || cfg.addMimeTypes != {}) "\n}"}
# 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.
@@ -646,6 +653,19 @@ in
'';
};
+ addMimeTypes = mkOption {
+ type = with types; submodule {
+ freeformType = types.attrsOf (types.listOf str);
+ };
+ default = {};
+ example = literalExpression ''
+ "model/stl" = [ "stl" ];
+ '';
+ description = ''
+ Enabling custom mime types to an existing list {option}`services.nginx.defaultMimeTypes`.
+ '';
+ };
+
mimeTypes = mkOption {
type = with types; submodule {
freeformType = types.attrsOf (types.listOf str);
|
Convert the ${pkgs.mailcap}/etc/nginx/mime.types file to this form?
|
c223d28
to
f432ef3
Compare
322f08f
to
883421c
Compare
I don't like having both
and
are not equivalent, since the second That means the initial version of the PR was more correct, but still a major UX footgun.
That would mean essentially vendoring the mailcap mimetypes list to avoid IFD, which puts its maintanance burden on us. (This could be aided with a test to check for equivalence with the one in mailcap.) What about perhaps a scripted approach? Meaning a script that extracts the content of |
In this variant, both types are added.
I tried to do something similar here: |
883421c
to
ec8c8fa
Compare
Removed parametr 'addMimeTypes'.
Сould try using an variant like this. Tested it, it works.
I don't know any other simple options for changing mime-types yet. |
dfecc89
to
03675ef
Compare
2ebb777
to
8b24a2b
Compare
I don't get it. If that's the case, what's wrong with @pbsds's suggestion from #341414 (comment) |
To reduce the likelihood of conflicts in mime parameters. This is an alternative method of managing mime types, which allows you to specify the minimum required for the site to work. |
Well, for that you may set the default mime types to Having this explicit seems less surprising to me. |
Something like this? |
As mentioned above, I'm referring to #341414 (comment). |
8b24a2b
to
c76a5ef
Compare
Update PR. |
c76a5ef
to
f4e3296
Compare
But I would prefer the previous variant :( |
bc92f3b
to
e420326
Compare
e420326
to
014acd0
Compare
@@ -766,6 +776,23 @@ in | |||
''; | |||
}; | |||
|
|||
addMimeTypes = mkOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this still addMimeTypes?
This isn't necessarily additive.
description = '' | ||
Enabling custom mime types to an existing list {option}`services.nginx.defaultMimeTypes`. | ||
This option does not allow overriding existing mime-types in | ||
{option}`services.nginx.defaultMimeTypes` and may cause duplicate mime-types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description needs an update: this behavior can be changed by setting defaultMimeTypes to null.
Description of changes
Allow configure and use custom mime-types.
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.