Search code examples
npmpackage-managersfirebase-toolsnixnixos

What is the correct way of installing firebase-tools (a npm package) in NixOS/Nix?


I am watching this Udemy course on Firebase. The course is a bit dated, initially made maybe 6 years ago.

At some point the author indicates how to use firebase CLI, hence he indicates the command:

~/projects/chatlive]$ npm install -g firebase-tools

I added sudo to avoid permission problems:

~/projects/chatlive]$ sudo npm install -g firebase-tools

Unfortunately, this error message is retrieved:

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-28T15_33_55_544Z-debug.log

I am using NixOS and this is my config file. Since the error message mentions the nix/store I thought it could be related.

Usually, I install things in NixOS changing my configuration.nix and doing sudo nixos-rebuild switch. But I thought it would not be necessary to do it considering npm was managing the installation.

Searching on Nix packages, I can see firebase-tools: link. Now, it seems that tweaking the config file is the way...

In situations like this, what is the best practice?

Should I force trying to install via npm (how?)? Should I go for a new generation of NixOS and a full system rebuild just because of this package?

Is there another possible path? Am I missing something?

Thanks.


Solution

  • If you just want to play around with firebase-tools in a development environment, create a shell.nix file in your working directory and add the following lines:

    { pkgs ? import <nixpkgs> {}}:
    
    pkgs.mkShell {
      nativeBuildInputs = [ pkgs.nodePackages.firebase-tools ];
    }
    

    Then run nix-shell to start a shell with firebase-tools included. This is considered best practice for local development environments, see https://nixos.wiki/wiki/Development_environment_with_nix-shell .

    If you want to try out packages not in nixpkgs repo you should use npm and install a package locally (without -g ). See https://nixos.wiki/wiki/Node.js#Using_npm_install_-g_fails.