3

Say I'd like to install @squoosh/cli, this package is mentioned in nixpkgs here. Is there a way to specify the package in configuration.nix, or in the home-manager, to have it be installed by nixos-rebuild?

1 Answers1

3

Yes, the packages in node-packages.json appear in pkgs.nodePackages.

In NixOS, you can add it as follows:

{ pkgs, ... }: {

  # ...

  environment.systemPackages = [
    pkgs.nodePackages."@squoosh/cli"
  ];

}

In Home Manager it's similar, but home.packages instead of environment.systemPackages.

EDIT: Some node packages are packaged differently. It's worth giving search.nixos.org a try. Personally I don't think any of the current node packaging methods work well for Nixpkgs. The implementation of dynamic derivations will likely lead to a significantly improved solution.

Robert Hensing
  • 6,708
  • 18
  • 23
  • this doesn't work on 22 and on i think. I tried but it didn't. Instead there a .npm-global folder and .npmrc placed for that purpose so i think it's easier to install npm packages globally now. – Theo Oliveira Apr 08 '23 at 14:24
  • 1
    `pkgs.nodePackages` is still around, although this specific package does not build anymore. I don't see any extra node infrastructure in Nixpkgs though, specifically no `.npm-global` or `.npmrc` files. – Robert Hensing Apr 09 '23 at 15:10
  • Surprisingly i didn't change anything on this setup though, i just installed and worked lol. you can see my setup here. I don't want to mislead anyone, just letting people know. [here](https://github.com/TheoOliveira/dotfiles-nix) – Theo Oliveira Apr 09 '23 at 15:30