svanderburg / node2nix

Generate Nix expressions to build NPM packages
MIT License
527 stars 100 forks source link

npm packages with a dot in their name yield an error #265

Closed elmarsto closed 2 years ago

elmarsto commented 3 years ago

The following code, which works for most npm packages, fails when the package name is 'nb.sh'

node2nix -i <(echo '["nb.sh"]')
nix-env -f ./default.nix -iA nb.sh

Specifically, the above generates the following error:

info attempt registry request try #1 at 8:23:50 PM
http request GET https://registry.npmjs.org/nb.sh
http 200 https://registry.npmjs.org/nb.sh
error: attribute 'nb' in selection path 'nb.sh' not found

The error is easily solved by editing node-packages.nix and 9g:s/nb\.sh/nb-sh/ (in vim), and then doing nix-env -f ./default.nix -A nb-sh (note the hyphen,) but it should not in the first place happen.

svanderburg commented 3 years ago

I just tried the latest development version and it seems to work.

I used this input file:

[
  "nb.sh"
]
$ nix-build -A '"nb.sh"'  
these derivations will be built:
  /nix/store/dblyai93yixpagdmwjc5vx3wzshivf94-nb.sh-6.5.1.tgz.drv
  /nix/store/jk52m88mfpp4qqxq5kfynk9gm2cnjnn5-nb.sh-6.5.1.drv
building '/nix/store/dblyai93yixpagdmwjc5vx3wzshivf94-nb.sh-6.5.1.tgz.drv'...

trying https://registry.npmjs.org/nb.sh/-/nb.sh-6.5.1.tgz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  624k  100  624k    0     0   331k      0  0:00:01  0:00:01 --:--:--  331k
building '/nix/store/jk52m88mfpp4qqxq5kfynk9gm2cnjnn5-nb.sh-6.5.1.drv'...
unpacking sources
patching sources
configuring
no configure script, doing nothing
building
installing
unpacking source archive /nix/store/dlmgph2zb849am0hsp0myp33dgszjgyz-nb.sh-6.5.1.tgz
pinpointing versions of dependencies...
patching script interpreter paths in .
./nb.sh/test/fixtures/bin/mock_editor: interpreter directive changed from "#!/usr/bin/env bash" to "/nix/store/jdi2v7ir1sr6vp7pc5x0nhb6lpcmg6xg-bash-4.4-p23/bin/bash"
./nb.sh/test/fixtures/bin/notes: interpreter directive changed from "#!/usr/bin/env bash" to "/nix/store/jdi2v7ir1sr6vp7pc5x0nhb6lpcmg6xg-bash-4.4-p23/bin/bash"
./nb.sh/test/fixtures/bin/mock_editor_no_op: interpreter directive changed from "#!/usr/bin/env bash" to "/nix/store/jdi2v7ir1sr6vp7pc5x0nhb6lpcmg6xg-bash-4.4-p23/bin/bash"
./nb.sh/test/fixtures/bin/nb: interpreter directive changed from "#!/usr/bin/env bash" to "/nix/store/jdi2v7ir1sr6vp7pc5x0nhb6lpcmg6xg-bash-4.4-p23/bin/bash"
./nb.sh/test/fixtures/bin/bookmark: interpreter directive changed from "#!/usr/bin/env bash" to "/nix/store/jdi2v7ir1sr6vp7pc5x0nhb6lpcmg6xg-bash-4.4-p23/bin/bash"
./nb.sh/nb: interpreter directive changed from "#!/usr/bin/env bash" to "/nix/store/jdi2v7ir1sr6vp7pc5x0nhb6lpcmg6xg-bash-4.4-p23/bin/bash"
./nb.sh/bin/notes: interpreter directive changed from "#!/usr/bin/env bash" to "/nix/store/jdi2v7ir1sr6vp7pc5x0nhb6lpcmg6xg-bash-4.4-p23/bin/bash"
./nb.sh/bin/bookmark: interpreter directive changed from "#!/usr/bin/env bash" to "/nix/store/jdi2v7ir1sr6vp7pc5x0nhb6lpcmg6xg-bash-4.4-p23/bin/bash"
./nb.sh/etc/debian/rules: interpreter directive changed from "#!/usr/bin/make -f" to "/nix/store/dk7s6714az7paaqwrca488z7xryh6wf3-gnumake-4.3/bin/make -f"
No package-lock.json file found, reconstructing...
patching script interpreter paths in .
up to date in 0.088s....] \ postinstall: sill install executeActions2cbed27e2b
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/37b1vgxlwqx774j6rfapbqqn0cm1jl7d-nb.sh-6.5.1
rewriting symlink /nix/store/37b1vgxlwqx774j6rfapbqqn0cm1jl7d-nb.sh-6.5.1/bin to be relative to /nix/store/37b1vgxlwqx774j6rfapbqqn0cm1jl7d-nb.sh-6.5.1
patching script interpreter paths in /nix/store/37b1vgxlwqx774j6rfapbqqn0cm1jl7d-nb.sh-6.5.1
checking for references to /build/ in /nix/store/37b1vgxlwqx774j6rfapbqqn0cm1jl7d-nb.sh-6.5.1...
/nix/store/37b1vgxlwqx774j6rfapbqqn0cm1jl7d-nb.sh-6.5.1
sbu@sbu:~/teststuff/dotpkg$ ./result/bin/
bookmark  nb        nb.sh     
sbu@sbu:~/teststuff/dotpkg$ ./result/bin/nb
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                                 Welcome to
                                                                                 __          _
                                                                                 \ \   _ __ | |__
                                                                                  \ \ | '_ \| '_ \
                                                                                  / / | | | | |_) |
                                                                                 /_/  |_| |_|_.__/
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                                        home
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
0 items.

Add a note:
  nb add
Add a bookmark:
  nb <url>
Import a file:
  nb import (<path> | <url>)
Help information:
  nb help
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
❯ nb · nb add · nb <url> · nb edit <id> · nb show <id> · nb open <id> · nb list · nb search <query> · nb browse · nb notebooks add <name> · nb settings · nb help

So my guess is that this command is the problem:

nix-env -f ./default.nix -iA nb.sh

it should be:

nix-env -f ./default.nix -iA '"nb.sh"'

The reason is that because there is a . in the filename that is also an attribute selector in the Nix expression language. Quoting the attribute name solves it.

can you also give it a try?

svanderburg commented 3 years ago

This is a Nix expression language quirk people have to take into account :)

svanderburg commented 2 years ago

I close this issue, because I believe the above description should solve the problem. If it remains a problem, then please reopen this issue.