Beware, new nix user here so this may be entirely my fault. Apparently, the "yarn" package gets its own nodes version and ignores the nodejs version configured in the default.nix file.
I have tried finding docs on how to control a possible "indirect" dependency but couldn't figure this out.
I have this default.nix file
with import <nixpkgs> {};
stdenv.mkDerivation rec {
name = "env";
env = buildEnv { name = name; paths = buildInputs; };
buildInputs = [
yarn
nodejs-10_x
];
}
Running yarn however for a package.json that restricts
"engines": {
"node": "^10.12.0"
}
results in an error.
[nix-shell:~/dev/mc/meshfed-release/panel]$ yarn
yarn install v1.12.3
[1/5] 馃攳 Validating package.json...
error [email protected]: The engine "node" is incompatible with this module. Expected version "^10.12.0". Got "8.14.1"
error Found incompatible module
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
[nix-shell:~/dev/mc/meshfed-release/panel]$ node --version
v10.12.0
Please run nix-shell -p nix-info --run "nix-info -m" and paste the
results.
- system: `"x86_64-darwin"`
- host os: `Darwin 18.2.0, macOS 10.14.1`
- multi-user?: `no`
- sandbox: `no`
- version: `nix-env (Nix) 2.1.3`
- channels(jrudolph): `"nixpkgs-19.03pre165281.7d864c6bd63"`
- nixpkgs: `/Users/jrudolph/.nix-defexpr/channels/nixpkgs`
you need to override the nodejs version used by yarn https://nixos.org/nixos/nix-pills/nixpkgs-overriding-packages.html
--- i/shell.nix
+++ w/shell.nix
@@ -3,7 +3,7 @@ stdenv.mkDerivation rec {
name = "env";
env = buildEnv { name = name; paths = buildInputs; };
buildInputs = [
- yarn
+ (yarn.override { nodejs = nodejs-10_x; })
nodejs-10_x
];
}
Thanks @marsam, that did the job! Looks like there's some good stuff in nix-pills that's not immediately apparent from the main docs.
For anyone else using nvm:
With nvm, you can't have any version of node to be installed with yarn. To solve this, you can do: (pkgs.yarn.override { nodejs = null; })
Most helpful comment
you need to override the nodejs version used by yarn https://nixos.org/nixos/nix-pills/nixpkgs-overriding-packages.html