diff mbox series

[bug#71586] services: web: Improve nginx formatting for extra-content

Message ID 9556afd9d860c28ea5abe15fd42d8e2989e5244c.1718510232.git.richard@freakingpenguin.com
State New
Headers show
Series [bug#71586] services: web: Improve nginx formatting for extra-content | expand

Commit Message

Richard Sent June 16, 2024, 3:57 a.m. UTC
* gnu/services/web (default-nginx-config): When extra-content is a list, add 4
space indentation and a newline to every line. If it's a string, continue
inserting it directly. This makes the list serialization behavior more
consistent with other services.

Change-Id: Iec8614ba3cfc37292a566197e8d39b352b04846a
---
 gnu/services/web.scm | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)


base-commit: 612e4dd98f7d1d015e405af9d029bede3fe3c280

Comments

Tomas Volf June 19, 2024, 5:55 p.m. UTC | #1
Hello,

On 2024-06-15 23:57:12 -0400, Richard Sent wrote:
> * gnu/services/web (default-nginx-config): When extra-content is a list, add 4
> space indentation and a newline to every line. If it's a string, continue
> inserting it directly. This makes the list serialization behavior more
> consistent with other services.
>
> Change-Id: Iec8614ba3cfc37292a566197e8d39b352b04846a
> ---
>  gnu/services/web.scm | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/gnu/services/web.scm b/gnu/services/web.scm
> index 406117c457..094b1e4b45 100644
> --- a/gnu/services/web.scm
> +++ b/gnu/services/web.scm
> @@ -771,7 +771,12 @@ (define (default-nginx-config config)
>             "\n"
>             (map emit-nginx-upstream-config upstream-blocks)
>             (map emit-nginx-server-config server-blocks)
> -           extra-content
> +           (match extra-content
> +             ((? string? extra-content) extra-content)
> +             ((? list? extra-content)
> +              (map (lambda (line)
> +                     (simple-format #f "    ~A\n" line))

The format here sadly prevents producing `include' directives with link to the
store, since any file-like object will be just serialized as its representation:

  `("foo"
    "bar"
    ("aa" "bb")
    ,(plain-file "foo" "baz"))

Will end up as:

    foo
    bar
    (aa bb)
    #<<plain-file> name: "foo" content: "baz" references: ()>

Neither the list nor the plain-file are as expected.  What about doing just
this:

    (match extra-content
      ((? string? extra-content) extra-content)
      ((? list? extra-content)
       (map (lambda (line)
              `("    " ,line "\n"))
            extra-content)))

This produces the expected (in my opinion) output:

    foo
    bar
    aabb
    /gnu/store/7pz4iczjvgvn9ikpp1ip50bk6vi4sk7b-foo

Meaning you can now do things like

    (extra-content `(("include " ,%some-file.conf ";")))

And it will work as expected.  It already works like this for raw-content in the
nginx-server-configuration.

Thoughts?

> +                   extra-content)))
>             "\n}\n"))))
>
>  (define %nginx-accounts
>
> base-commit: 612e4dd98f7d1d015e405af9d029bede3fe3c280
> --
> 2.45.1
>
>

Have a nice day,
Tomas Volf

--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.
diff mbox series

Patch

diff --git a/gnu/services/web.scm b/gnu/services/web.scm
index 406117c457..094b1e4b45 100644
--- a/gnu/services/web.scm
+++ b/gnu/services/web.scm
@@ -771,7 +771,12 @@  (define (default-nginx-config config)
            "\n"
            (map emit-nginx-upstream-config upstream-blocks)
            (map emit-nginx-server-config server-blocks)
-           extra-content
+           (match extra-content
+             ((? string? extra-content) extra-content)
+             ((? list? extra-content)
+              (map (lambda (line)
+                     (simple-format #f "    ~A\n" line))
+                   extra-content)))
            "\n}\n"))))
 
 (define %nginx-accounts