Subject: [bug#74900] [PATCH 1/2] Replace (guix build json) with (json) in node-build-system

From: Ludovic Courtès <[email-masked]>
Date: Fri, 17 Jan 2025 21:36:19 +0100

Hi Daniel,

Daniel Khodabakhsh <[email-masked]> skribis:

> This change replaces the use of (guix build json) with (json) for the
> node ecosystem.
> Since guile-json is a dependency of Guix, and it's used elsewhere in
> the project, it makes sense to use this instead of rolling our own
> JSON implementation with (guix build json).
>
> (guix build json) also has a few issues:
>  - write-json escapes forward slashes in strings for some reason ("/"
> become "\/")
>  - read-json produces a structure similar to an association list but
> with '@' to indicate an object, making it not possible to use
> association list procedures directly.
>
> This is one step to move away from (guix build json), there will be
> other changes to remove the other uses of it.

Thanks for working on this!  This is tedious but important work.

Cc’ing Jelle, who knows Node packaging well.  Could you take a look,
Jelle?

One note:

>  (define %node-build-system-modules
>    ;; Build-side modules imported by default.
>    `((guix build node-build-system)
> -    (guix build json)
> +    (json)
> +    (json builder)
> +    (json parser)
> +    (json record)
>      ,@%default-gnu-imported-modules))

This ends up being used like so:

  (with-imported-modules %node-build-system-modules
    #~(…))

The effect is to copy (json …) from the user’s load path into the build
environment.  But this is not what we want, because one user might have
Guile-JSON 4.1 while another one has 4.7, and so they’d get different
derivations.

Instead, we should do:

  (with-extensions (list guile-json)
    (with-imported-modules %node-build-system-modules
      #~(…)))

With extra care to resolve ‘guile-json’ lazily via ‘module-ref’.

Thanks,
Ludo’.