How to install shadow-cljs in NixOS?

Hi,

I am trying to install shadow-cljs . This is a ClojureScript compilation tool. People outside of Nix/NixOS community usually install it via npm.

I had a similar experience recently installing Firebase CLI. And I successfully installed it with this NixOS package which is “pre-fixed” as a node package: nodePackages.firebase-tools.

With shadow-cljs,

1- I cannot find the package on search: #1 attempt, #2 attempt, #3 attempt, #4 attempt

2 - If I try to install it on the terminal the “classic way”, it does not work, since the classic installation kind of violates NixOS architecture (as far as I am concerned):

[pedro@system:~]$ npm -v
6.14.15

[pedro@system:~]$  npm -g install shadow-cljs
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN checkPermissions Missing write access to /nix/store/nm7vm9d7xbvibazz7kl7xkqgjddqgiby-nodejs-14.18.3/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /nix/store/nm7vm9d7xbvibazz7kl7xkqgjddqgiby-nodejs-14.18.3/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/nix/store/nm7vm9d7xbvibazz7kl7xkqgjddqgiby-nodejs-14.18.3/lib/node_modules'
npm ERR!  [Error: EACCES: permission denied, access '/nix/store/nm7vm9d7xbvibazz7kl7xkqgjddqgiby-nodejs-14.18.3/lib/node_modules'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/nix/store/nm7vm9d7xbvibazz7kl7xkqgjddqgiby-nodejs-14.18.3/lib/node_modules'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/pedro/.npm/_logs/2022-07-28T20_24_44_069Z-debug.log

[pedro@system:~]$ sudo  npm -g install shadow-cljs
[sudo] password for pedro: 
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN checkPermissions Missing write access to /nix/store/nm7vm9d7xbvibazz7kl7xkqgjddqgiby-nodejs-14.18.3/lib/node_modules
npm ERR! code EROFS
npm ERR! syscall access
npm ERR! path /nix/store/nm7vm9d7xbvibazz7kl7xkqgjddqgiby-nodejs-14.18.3/lib/node_modules
npm ERR! errno -30
npm ERR! rofs EROFS: read-only file system, access '/nix/store/nm7vm9d7xbvibazz7kl7xkqgjddqgiby-nodejs-14.18.3/lib/node_modules'
npm ERR! rofs Often virtualized file systems, or other file systems
npm ERR! rofs that don't support symlinks, give this error.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-07-28T20_25_19_965Z-debug.log

Is there a way to solve this? Is there way to use npm as a package manager instead of nix while in NixOS?

Thanks

You can’t install packages globally with npm. Try user installation (without -g).

1 Like

Thanks for the help, @Sandro.

Unfortunately, it does not work:

[pedro@system:~/projects/balance]$ npm -v
6.14.15

[pedro@system:~/projects/balance]$ npm install shadow-cljs
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
npm WARN deprecated grpc@1.16.1: This library will not receive further updates other than security fixes. We recommend using @grpc/grpc-js instead.
npm WARN deprecated fsevents@1.2.9: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN checkPermissions Missing write access to /home/pedro/projects/balance/node_modules/@sheet/core
npm WARN @js-joda/timezone@2.2.0 requires a peer of @js-joda/core@^1.11.0 but none is installed. You must install peer dependencies yourself.
npm WARN tallyfor-balance@0.3.0 scripts['server'] should probably be scripts['start'].
npm WARN tallyfor-balance@0.3.0 license should be a valid SPDX license expression

npm ERR! code ENOENT
npm ERR! syscall access
npm ERR! path /home/pedro/projects/balance/node_modules/@sheet/core
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, access '/home/pedro/projects/balance/node_modules/@sheet/core'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/pedro/.npm/_logs/2022-07-31T13_25_37_489Z-debug.log

Is the directory owner by your user and has write permissions?

1 Like

Thanks again, @Sandro.

I have just run the following tests:

pedro@system:~/projects/balance]$ stat -c '%U' ~/projects/balance
pedro

[pedro@system:~/projects/balance]$ sudo test -w ~/projects/balance
[sudo] password for pedro: 

[pedro@system:~/projects/balance]$ ls -l
total 548
drwxr-xr-x   3 pedro users   4096 Jul 26 16:27 config
-rw-r--r--   1 pedro users     92 Jul 26 16:27 dev.cljs.edn
drwxr-xr-x   3 pedro users   4096 Jul 26 16:27 docs
drwxr-xr-x   2 pedro users   4096 Jul 26 16:27 externs
-rw-r--r--   1 pedro users   1126 Jul 26 16:27 firebase-deploy.my-instance-specific-variables.TEMPLATE.edn
-rw-r--r--   1 pedro users    163 Jul 26 16:27 firestore.rules.json
-rw-r--r--   1 pedro users    198 Jul 26 16:27 LICENSE
-rw-r--r--   1 pedro users   1649 Jul 26 16:27 makefile
drwxr-xr-x 694 pedro users  20480 Jul 29 15:12 node_modules
-rwxr-xr-x   1 pedro users   1408 Jul 26 16:27 package.json
-rw-r--r--   1 pedro users 449459 Jul 26 16:27 package-lock.json
-rw-r--r--   1 pedro users   2571 Jul 26 16:27 project.clj
drwxr-xr-x   6 pedro users   4096 Jul 26 16:27 public
-rw-r--r--   1 pedro users  11521 Jul 26 16:27 README.md
drwxr-xr-x   4 pedro users   4096 Jul 26 16:27 semantic
-rw-r--r--   1 pedro users    469 Jul 26 16:27 semantic.json
-rwxr-xr-x   1 pedro users   4034 Jul 26 16:27 shadow-cljs.edn
-rw-r--r--   1 pedro users    356 Aug  2 10:30 shell.nix
-rw-r--r--   1 pedro users    395 Jul 31 11:06 shell.nix~
drwxr-xr-x   4 pedro users   4096 Jul 26 16:27 src
drwxr-xr-x   4 pedro users   4096 Jul 31 10:24 target
drwxr-xr-x   3 pedro users   4096 Jul 26 16:27 tools

[pedro@system:~/projects/balance]$ 

Could this be caused due to the wrong version of node and java?

could be but I am just guessing at this point

Assuming you’re still on lockfile v1, have a look at https://github.com/nix-community/npmlock2nix and its shell - IME one project or another always wants to do something native, and fails horribly because it downloads a random pre-compiled binary.

This doesn’t look like it, but npmlock2nix can probably help sort out this too.

@pdelfino use yarn2nix

package.json

{
    "name": "shadow-cljs",
    "version": "1.0.0",
    "dependencies": {
        "shadow-cljs": "2.15.10"
    },
    "license": "MIT"
}

in shell
yarn ; yarn2nix > yarn.nix

after

in Nix

  shadow-cljs = mkYarnPackage rec {
    name = "shadow-cljs";
    src = ./yarn2nix/shadow-cljs;
    packageJSON = "${src}/package.json";
    yarnLock = "${src}/yarn.lock";
    yarnNix = "${src}/yarn.nix";
  };
  
  shadow-cljs-bin = (runCommand "shadow-cljs" {} '' mkdir -p $out/bin ; cat ${writeText "shadow-cljs" ''
    ${shadow-cljs}/libexec/${shadow-cljs.name}/deps/shadow-cljs/node_modules/.bin/shadow-cljs $@
  ''} > $out/bin/shadow-cljs ; chmod +x $out/bin/shadow-cljs '');

1 Like
Hosted by Flying Circus.