~abcdw/rde-discuss

1

Importing and building NPM packages

Details
Message ID
<87h75le7yt.fsf@minikn.xyz>
DKIM signature
pass
Download raw message
Hello,

in the last couple of days I've dug into the possibilities of packaging
NPM packages in Guix. The situation itself is pretty dire, the node eco
system Guix has to offer by default is basically not existing with only
a handful of packages packaged in Guix.

A couple of days ago however I stumbled across this post on the Guix ML:
https://www.mail-archive.com/guix-devel@gnu.org/msg48964.html

This was a WIP npm importer for Guix which made it possible to
recursively import and build (with a "dummy" build-system that just
executes 'npm install') a package and all of its dependencies.

I merged the commits into a fresh Guix checkout, but was unable to get
it working. After talking to the author, the pointed me towards a Guix
branch with a newer version of this:

https://git.savannah.gnu.org/cgit/guix.git/log/?h=wip-node-importer

I was actually able to recursively import and guild `typscript` and
`typescript-language-server` using this branch. It uses the already
existing node-build-system and just adds the npm importer.

You can see the result here:
https://github.com/minikN/guix/blob/main/config/packages/node-xyz.scm

Steps to reproduce:
1. clone Guix and checkout the wip-node-importer branch.
2. Add guile-semver
(https://git.ngyro.com/guix-npm/diff/guile-semver.scm?id=e1d52ca9258e6d371fab7dfdd51592650d4ae7bc)
package definition and build it.
3. Run `guix shell guile guile-semver -D guix`
4. Build Guix like you normally would
5. Create an output file (e.g. gnu/packages/node-typescript.scm)
6. Add

--8<---------------cut here---------------start------------->8---
(define-module (gnu packages node-typescript)
      #:use-module (gnu packages node-xyz)
      #:use-module (guix build-system node)
      #:use-module (guix download)
      #:use-module ((guix licenses) #:prefix license:)
      #:use-module (guix packages))
--8<---------------cut here---------------end--------------->8---

to the file.
7. Run `./pre-inst-env guix import npm-binary -r PACKAGE | tee -a
gnu/packages/node-typescript.scm` to build PACKAGE.

The stuff with `guile-semver` probably isn't necessary. I just copied
them from the inital ML post I found, can probably be skipped.

It should output a lot of package definitions into the file. There is
one bug I encountered: If a dependency is already present in Guix
(https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/packages/node-xyz.scm)
it will not outpur a package definition. This is fine, however it'll add
the package with the version appended as a dependency (like here
https://github.com/minikN/guix/blob/main/config/packages/node-xyz.scm#L1370),
but in Guix, the package doesn't have the version appended to the name
(https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/packages/node-xyz.scm#n336)
which will throw an unbound variable error upon building. This can be
remedied by importing the specific version of the package:

`./pre-inst-env guix import npm-binary -r once 1.4.0 | tee -a
gnu/packages/node-typescript.scm`

Building typescript-language-server, I had to manually do this for
node-once and node-wrappy.

The branch should be fixed up and merged into master imo. I wish I had
found out about this sooner.

-- 
Best regards / Mit freundlichen Grüßen,
Demis Balbach

Re: Importing and building NPM packages

Details
Message ID
<87sfp0pl8w.fsf@trop.in>
In-Reply-To
<87h75le7yt.fsf@minikn.xyz> (view parent)
DKIM signature
pass
Download raw message
On 2022-05-19 19:40, Demis Balbach wrote:

> Hello,
>
> in the last couple of days I've dug into the possibilities of packaging
> NPM packages in Guix. The situation itself is pretty dire, the node eco
> system Guix has to offer by default is basically not existing with only
> a handful of packages packaged in Guix.
>
> A couple of days ago however I stumbled across this post on the Guix ML:
> https://www.mail-archive.com/guix-devel@gnu.org/msg48964.html
>
> This was a WIP npm importer for Guix which made it possible to
> recursively import and build (with a "dummy" build-system that just
> executes 'npm install') a package and all of its dependencies.
>
> I merged the commits into a fresh Guix checkout, but was unable to get
> it working. After talking to the author, the pointed me towards a Guix
> branch with a newer version of this:
>
> https://git.savannah.gnu.org/cgit/guix.git/log/?h=wip-node-importer
>
> I was actually able to recursively import and guild `typscript` and
> `typescript-language-server` using this branch. It uses the already
> existing node-build-system and just adds the npm importer.
>
> You can see the result here:
> https://github.com/minikN/guix/blob/main/config/packages/node-xyz.scm
>
> Steps to reproduce:
> 1. clone Guix and checkout the wip-node-importer branch.
> 2. Add guile-semver
> (https://git.ngyro.com/guix-npm/diff/guile-semver.scm?id=e1d52ca9258e6d371fab7dfdd51592650d4ae7bc)
> package definition and build it.
> 3. Run `guix shell guile guile-semver -D guix`
> 4. Build Guix like you normally would
> 5. Create an output file (e.g. gnu/packages/node-typescript.scm)
> 6. Add
>
> --8<---------------cut here---------------start------------->8---
> (define-module (gnu packages node-typescript)
>       #:use-module (gnu packages node-xyz)
>       #:use-module (guix build-system node)
>       #:use-module (guix download)
>       #:use-module ((guix licenses) #:prefix license:)
>       #:use-module (guix packages))
> --8<---------------cut here---------------end--------------->8---
>
> to the file.
> 7. Run `./pre-inst-env guix import npm-binary -r PACKAGE | tee -a
> gnu/packages/node-typescript.scm` to build PACKAGE.
>
> The stuff with `guile-semver` probably isn't necessary. I just copied
> them from the inital ML post I found, can probably be skipped.
>
> It should output a lot of package definitions into the file. There is
> one bug I encountered: If a dependency is already present in Guix
> (https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/packages/node-xyz.scm)
> it will not outpur a package definition. This is fine, however it'll add
> the package with the version appended as a dependency (like here
> https://github.com/minikN/guix/blob/main/config/packages/node-xyz.scm#L1370),
> but in Guix, the package doesn't have the version appended to the name
> (https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/packages/node-xyz.scm#n336)
> which will throw an unbound variable error upon building. This can be
> remedied by importing the specific version of the package:
>
> `./pre-inst-env guix import npm-binary -r once 1.4.0 | tee -a
> gnu/packages/node-typescript.scm`
>
> Building typescript-language-server, I had to manually do this for
> node-once and node-wrappy.
>
> The branch should be fixed up and merged into master imo. I wish I had
> found out about this sooner.

It looks good.  

I would like to implement a tooling to build a list of guix packages
from package-lock.json/yarn.lock.  This way we will be able to easily
make per-project dev environment with all necessary dependencies
(nodejs, make, linters, lsp server and node packages as well) without
actually packaging "node ecosystem".  It's probably will be similiar to
poetry2nix project.

-- 
Best regards,
Andrew Tropin
Reply to thread Export thread (mbox)