Skip to content
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
15 changes: 13 additions & 2 deletions nixos/modules/services/web-servers/nginx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,12 @@ let
${optionalString (hasSSL && vhost.sslTrustedCertificate != null) ''
ssl_trusted_certificate ${vhost.sslTrustedCertificate};
''}
${optionalString vhost.rejectSSL ''
${optionalString (hasSSL && vhost.rejectSSL) ''
ssl_reject_handshake on;
''}
${optionalString (hasSSL && vhost.kTLS) ''
ssl_conf_command Options KTLS;
''}

${mkBasicAuth vhostName vhost}

Expand Down Expand Up @@ -820,6 +823,14 @@ in
'';
}

{
assertion = any (host: host.kTLS) (attrValues virtualHosts) -> versionAtLeast cfg.package.version "1.21.4";
message = ''
services.nginx.virtualHosts.<name>.kTLS requires nginx version
1.21.4 or above; see the documentation for services.nginx.package.
'';
}

{
assertion = all (host: !(host.enableACME && host.useACMEHost != null)) (attrValues virtualHosts);
message = ''
Expand Down Expand Up @@ -896,7 +907,7 @@ in
PrivateMounts = true;
# System Call Filtering
SystemCallArchitectures = "native";
SystemCallFilter = "~@cpu-emulation @debug @keyring @ipc @mount @obsolete @privileged @setuid @mincore";
SystemCallFilter = [ "~@cpu-emulation @debug @keyring @mount @obsolete @privileged @setuid @mincore" ] ++ optionals (cfg.package != pkgs.tengine) [ "~@ipc" ];
};
};

Expand Down
11 changes: 11 additions & 0 deletions nixos/modules/services/web-servers/nginx/vhost-options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ with lib;
'';
};

kTLS = mkOption {
type = types.bool;
default = false;
description = ''
Whether to enable kTLS support.
Implementing TLS in the kernel (kTLS) improves performance by significantly
reducing the need for copying operations between user space and the kernel.
Required Nginx version 1.21.4 or later.
'';
};

sslCertificate = mkOption {
type = types.path;
example = "/var/host.cert";
Expand Down
1 change: 1 addition & 0 deletions pkgs/development/libraries/openssl/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ let
"-DUSE_CRYPTODEV_DIGESTS"
] ++ lib.optional enableSSL2 "enable-ssl2"
++ lib.optional enableSSL3 "enable-ssl3"
++ lib.optional (versionAtLeast version "3.0.0") "enable-ktls"
++ lib.optional (versionAtLeast version "1.1.0" && stdenv.hostPlatform.isAarch64) "no-afalgeng"
# OpenSSL needs a specific `no-shared` configure flag.
# See https://wiki.openssl.org/index.php/Compilation_and_Installation#Configure_Options
Expand Down
3 changes: 3 additions & 0 deletions pkgs/servers/http/nginx/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
, nixosTests
, substituteAll, gd, geoip, perl
, withDebug ? false
, withKTLS ? false
, withStream ? true
, withMail ? false
, withPerl ? true
Expand Down Expand Up @@ -80,6 +81,8 @@ stdenv.mkDerivation {
"--http-scgi-temp-path=/var/cache/nginx/scgi"
] ++ optionals withDebug [
"--with-debug"
] ++ optionals withKTLS [
"--with-openssl-opt=enable-ktls"
] ++ optionals withStream [
"--with-stream"
"--with-stream_realip_module"
Expand Down
1 change: 1 addition & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21035,6 +21035,7 @@ with pkgs;

nginxMainline = callPackage ../servers/http/nginx/mainline.nix {
zlib = zlib-ng.override { withZlibCompat = true; };
withKTLS = true;
withPerl = false;
# We don't use `with` statement here on purpose!
# See https://github.com/NixOS/nixpkgs/pull/10474#discussion_r42369334
Expand Down