From patchwork Mon Feb 26 00:29:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Leo_Nikkil=C3=A4?= X-Patchwork-Id: 61129 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 568C727BBEA; Mon, 26 Feb 2024 01:15:54 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id E3A3927BBE9 for ; Mon, 26 Feb 2024 01:15:48 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rePam-0000Ci-9h; Sun, 25 Feb 2024 20:15:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rePak-0000CD-Hq for guix-patches@gnu.org; Sun, 25 Feb 2024 20:15:38 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rePak-0000N1-20 for guix-patches@gnu.org; Sun, 25 Feb 2024 20:15:38 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rePb8-0007Ci-Hc for guix-patches@gnu.org; Sun, 25 Feb 2024 20:16:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#69399] [PATCH] services: nginx: Make log formats configurable. Resent-From: Leo =?utf-8?q?Nikkil=C3=A4?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 26 Feb 2024 01:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 69399 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 69399@debbugs.gnu.org Cc: Leo =?utf-8?q?Nikkil=C3=A4?= X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.170891011927550 (code B ref -1); Mon, 26 Feb 2024 01:16:02 +0000 Received: (at submit) by debbugs.gnu.org; 26 Feb 2024 01:15:19 +0000 Received: from localhost ([127.0.0.1]:40191 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rePaQ-0007AG-SJ for submit@debbugs.gnu.org; Sun, 25 Feb 2024 20:15:19 -0500 Received: from lists.gnu.org ([209.51.188.17]:40996) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rePaN-00079z-W7 for submit@debbugs.gnu.org; Sun, 25 Feb 2024 20:15:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1reOzD-0000rc-Mv for guix-patches@gnu.org; Sun, 25 Feb 2024 19:36:51 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1reOzB-0003sY-SY for guix-patches@gnu.org; Sun, 25 Feb 2024 19:36:51 -0500 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 06DEA5C005D; Sun, 25 Feb 2024 19:36:48 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sun, 25 Feb 2024 19:36:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lnikki.la; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:message-id:mime-version:reply-to :subject:subject:to:to; s=fm2; t=1708907808; x=1708994208; bh=WI VpXlcck2RcLvHZQuYsrD7WQPEREUHj74U2tSOUbfU=; b=Jp+r7XIoHCMARJQPvY 8+xD2w0StqhipMaG8SQ6qkIwP3PA+OyYOm2E/nG/uOk7Fk9K4i6NB2UDp3LELauh WGUb8eCOhbJl8LQq7IeaDiMIsx4qtjQumLr9T+L9OvxqVs6mzYe4GpWEdMYcFxeb Z9BB8Bq7WkKQfCOq3Y7YAbi4RvHs9TEFt2I/LrCSMDjEvxBbNkZQFDsU9mhcxDiU O+OkajLsVxyT3RpnOxSwsNADGdk9Jkfat6sV4SS65NevjPYjxuU7imZhC69LaZ2r 2Glyx8IgLS64bz3XON9XdktpwFcNuWMksc7C8qS6WAGcg+WawscnMw+bpYMYhofB lgcg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:message-id:mime-version:reply-to:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1708907808; x=1708994208; bh=WIVpXlcck2RcL vHZQuYsrD7WQPEREUHj74U2tSOUbfU=; b=phUHRBTbWTAqM8lGBnzwn39zsYbxz uDostQW9tQ/atoP35rYHWCeCTijhe3iI+DXkuSITSsue2Gx03FYjKx1lTw5awhSI 0rcN/7+/CFRNfO4W+yMl7ThvfXFgYOdnhOGVuYJ6V1mvnZ74rtUXCxYGwYoGbZPa K+h4Z6SidkgSi1tazO4NmDetdr4ROooZFgz2kbTU8IdYRrk6jhH83X7+G1J8zBc5 rprH+Vzw6lf9pCvICwadwV3MIp4YYy1jrI2vmkI4Q+xefsUcXWtJHlZE0Fksh9iJ VguCAXQHkYlcLZo35yW84zQqyqictp3SCFOKZ4lEoJlc7XVc/3sORPbVg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrgedugddvgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofggtgfgsehtkeertd ertdejnecuhfhrohhmpefnvghoucfpihhkkhhilhomuceohhgvlhhloheslhhnihhkkhhi rdhlrgeqnecuggftrfgrthhtvghrnheptdffudehleevjedtvefghfeihefhuedugeeihe ejgeehgfdvffegjeefvdetvdegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghm pehmrghilhhfrhhomhephhgvlhhloheslhhnihhkkhhirdhlrg X-ME-Proxy: Feedback-ID: i41f146a7:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 25 Feb 2024 19:36:47 -0500 (EST) Date: Mon, 26 Feb 2024 02:29:18 +0200 Message-ID: <20240226003615.21481-1-hello@lnikki.la> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Received-SPF: pass client-ip=66.111.4.28; envelope-from=hello@lnikki.la; helo=out4-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Leo =?utf-8?q?Nikkil=C3=A4?= X-ACL-Warn: , =?utf-8?q?Leo_Nikkil=C3=A4_via_Guix-patches?= X-Patchwork-Original-From: =?utf-8?q?Leo_Nikkil=C3=A4_via_Guix-patches?= via From: =?utf-8?q?Leo_Nikkil=C3=A4?= Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Currently it's not possible to configure the log format through Guix, since additional log formats must be declared before they're used, and `extra-content' is always added at the bottom of the `http' block. This patch aims to make these log formats configurable. * gnu/services/web.scm (): New record. ()[log-format, log-formats]: New fields. (assert-valid-log-format-escape): New procedure. (emit-nginx-log-format-config): New procedure. (default-nginx-config): Make log formats configurable. * doc/guix.texi (Web Services): Document it. --- doc/guix.texi | 40 +++++++++++++++++++++++++++++++++++++--- gnu/services/web.scm | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 76 insertions(+), 5 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 671cdab6f8..71a00740bc 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -31684,6 +31693,31 @@ valued G-expression. @end table @end deftp +@deftp {Data Type} nginx-log-format-configuration +Data type representing the configuration of a custom Nginx log format. +This type has the following parameters: + +@table @asis +@item @code{name} (type: symbol) +The name of the log format as a symbol. + +@item @code{escape} (default: @code{'default}) (type: symbol) +The mode used to escape values of variables in the format. The +supported values are: + +@itemize +@item @code{'default}, to escape all characters outside of the ASCII + printable range. +@item @code{'json}, to escape all characters invalid in JSON strings. +@item @code{'none}, to disable escaping. +@end itemize + +@item @code{format} (type: string) +The format as accepted by the @code{log_format} directive. + +@end table +@end deftp + @anchor{nginx-server-configuration} @deftp {Data Type} nginx-server-configuration Data type representing the configuration of an nginx server block. diff --git a/gnu/services/web.scm b/gnu/services/web.scm index 406117c457..5f895bab6d 100644 --- a/gnu/services/web.scm +++ b/gnu/services/web.scm @@ -17,6 +17,7 @@ ;;; Copyright © 2022 Simen Endsjø ;;; Copyright © 2023 Bruno Victal ;;; Copyright © 2023 Miguel Ángel Moreno +;;; Copyright © 2024 Leo Nikkilä ;;; ;;; This file is part of GNU Guix. ;;; @@ -103,6 +104,8 @@ (define-module (gnu services web) nginx-configuration-nginx nginx-configuration-shepherd-requirement nginx-configuration-log-directory + nginx-configuration-log-format + nginx-configuration-log-formats nginx-configuration-log-level nginx-configuration-run-directory nginx-configuration-server-blocks @@ -114,6 +117,12 @@ (define-module (gnu services web) nginx-configuration-extra-content nginx-configuration-file + nginx-log-format-configuration + nginx-log-format-configuration? + nginx-log-format-configuration-name + nginx-log-format-configuration-escape + nginx-log-format-configuration-format + nginx-server-configuration nginx-server-configuration? nginx-server-configuration-listen @@ -522,6 +531,23 @@ (define httpd-service-type (httpd-configuration)) (description "Run the Apache httpd Web server."))) +(define-record-type* + nginx-log-format-configuration make-nginx-log-format-configuration + nginx-log-format-configuration? + (name nginx-log-format-configuration-name) + (escape nginx-log-format-configuration-escape + (sanitize assert-valid-log-format-escape) + (default 'default)) + (format nginx-log-format-configuration-format)) + +(define (assert-valid-log-format-escape escape) + "Ensure @var{escape} is one of @code{'default}, @code{'json}, or +@code{'none}." + (unless (memq escape '(default json none)) + (raise + (formatted-message (G_ "unknown log format escape '~a'~%") escape))) + escape) + (define-record-type* nginx-server-configuration make-nginx-server-configuration nginx-server-configuration? @@ -580,6 +606,10 @@ (define-record-type* (log-level nginx-configuration-log-level (sanitize assert-valid-log-level) (default 'error)) + (log-format nginx-configuration-log-format ;symbol + (default 'combined)) + (log-formats nginx-configuration-log-formats ;list of + (default '())) (run-directory nginx-configuration-run-directory ;string (default "/var/run/nginx")) (server-blocks nginx-configuration-server-blocks @@ -635,6 +665,12 @@ (define emit-global-directive ((key . value) (format #f "~a ~a;~%" key value)))) +(define emit-nginx-log-format-config + (match-lambda + (($ name escape format) + (list " log_format " (symbol->string name) " escape=" + (symbol->string escape) " " format ";\n")))) + (define emit-nginx-location-config (match-lambda (($ uri body) @@ -718,7 +754,7 @@ (define (default-nginx-config config) (match-record config (nginx log-directory run-directory - log-level + log-level log-format log-formats server-blocks upstream-blocks server-names-hash-bucket-size server-names-hash-bucket-max-size @@ -740,7 +776,8 @@ (define (default-nginx-config config) " fastcgi_temp_path " run-directory "/fastcgi_temp;\n" " uwsgi_temp_path " run-directory "/uwsgi_temp;\n" " scgi_temp_path " run-directory "/scgi_temp;\n" - " access_log " log-directory "/access.log;\n" + (map emit-nginx-log-format-config log-formats) + " access_log " log-directory "/access.log " (symbol->string log-format) ";\n" " include " nginx "/share/nginx/conf/mime.types;\n" (if lua-package-path #~(format #f " lua_package_path ~s;~%"