8

I can see that NixOS has these versions available for install:

...
nodejs-0.10-statsd-0.7.2
nodejs-0.10.42
nodejs-4.3.1
nodejs-5.9.0
...

yet systemPackages doesn't like me installing nodejs-5.9.0 as it complains that:

error: syntax error, unexpected INT, expecting ID or OR_KW or DOLLAR_CURLY or '"', at /etc/nixos/configuration.nix:49:14
(use ‘--show-trace’ to show detailed location information)
error: syntax error, unexpected INT, expecting ID or OR_KW or DOLLAR_CURLY or '"', at /etc/nixos/configuration.nix:49:14
(use ‘--show-trace’ to show detailed location information)
building the system configuration...
error: syntax error, unexpected INT, expecting ID or OR_KW or DOLLAR_CURLY or '"', at /etc/nixos/configuration.nix:49:14
(use ‘--show-trace’ to show detailed location information)

which suggests to me I'm doing something wrong. I'd rather not just install with nix-env -i ... because I want it system-wide (and I'm building my standard NixOS configuration for all my dev' machines).

According to the nixpkgs repository v6 is available, but I've no idea how to tell nixos-rebuild through configuration.nix or otherwise how to install it.

How can I configure this properly so I can install the latest version of NodeJS, or 5.9.0 specifically?

Alex
  • 8,093
  • 6
  • 49
  • 79
  • 1
    I came here looking for the answer to exactly the same question. There are 2 deleted answers that say to use nvm if you need a _specific_ version of node. They were both unfortunately downvoted and their authors deleted them. It turns out that the [authors of nix suggest exactly this](https://github.com/NixOS/nixpkgs/issues/9682). If you need an _exact_ version nix is not your tool. – JohnnyLambada Jun 20 '21 at 04:41

2 Answers2

11

Turns out it was possible but I was using the wrong package name. If you query with nix-env -qaP | grep nodejs you get the name from its namespace:

$ nix-env -qaP | grep nodejs
nixos.statsd                                                          nodejs-0.10-statsd-0.7.2
nixos.nodejs-0_10                                                     nodejs-0.10.42
nixos.nodejs                                                          nodejs-4.3.1
*nixos.nodejs-5_x                                                      nodejs-5.9.0*
nixos.azure-cli                                                       nodejs-azure-cli-0.9.15
nixos.dnschain                                                        nodejs-dnschain-0.5.3
nixos.groovebasin                                                     nodejs-groovebasin-1.5.1
nixos.keybase                                                         nodejs-keybase-0.8.25
nixos.npm2nix                                                         nodejs-npm2nix-5.12.0
nixos.pumpio                                                          nodejs-pump.io-git-2015-11-09
nixos.ripple-rest                                                     nodejs-ripple-rest-1.7.0-rc1
nixos.shout                                                           nodejs-shout-0.51.1
nixos.sloc                                                            nodejs-sloc-0.1.9
nixos.wring                                                           nodejs-wring-1.0.0

I wanted nodejs-5.9.0 specifically, which means I need to use the nodejs-5_x package as described above (emphasis mine).

Alex
  • 8,093
  • 6
  • 49
  • 79
  • when writing answers it helps to put the final solution ya know what I am saying, like I got here from google b/c I want to install nodejs on nixos and given your answer which only helps you, I can't just copy the command to run it –  Jun 14 '19 at 01:55
1

only some node versions are provided by the latest nixpkgs. other node versions (like nodejs-11) were removed due to product end of life (EOL)

these removed versions can be found with the famous lazamar tool

so to use nodejs-11 (for example)

{ stdenv }:
let
  # nodejs-11_x was removed, EOL 2019-06-01
  # https://github.com/NixOS/nixpkgs/pull/70256
  nodejs-11_x = (import (builtins.fetchGit {
    # https://lazamar.co.uk/nix-versions/?channel=nixpkgs-unstable&package=nodejs
    name = "nixpkgs-nodejs-11.15.0"; # name in nix store
    url = "https://github.com/NixOS/nixpkgs/";
    ref = "refs/heads/nixpkgs-unstable";
    rev = "84f318e323989435d5dd54b4038b0af728f20c85";
  }) {}).nodejs-11_x;
in
stdenv.mkDerivation {
  # ...
}

note: this will compile nodejs from source, which can take some hours. todo: find a public binary cache

milahu
  • 2,447
  • 1
  • 18
  • 25