By searching pnpm on search.nixos.org . It seems only option to install pnpm is to use nodePackages.pnpm
. But I want to install pnpm
as standalone (It installs pnpm even before installing node).
By this I can use pnpm as node version manager too.
Documentation to install pnpm as standalone can be found here Installation | pnpm
Basically we have to run curl -fsSL https://get.pnpm.io/install.sh | sh -
.
I am wondering how to install this declaratively in my nixos (it uses flakes)
pnpm is JavaScript, so surely that curl is installing a bundled nodejs and pnpm. That’s exactly what you’ll get with the nix package but it’ll be sure to work wirh nixos.
Have you tried managing extra versions of nodejs with the pnpm from nixpkgs?
I was wondering this too. It looks like pnpm is only available in nixpkgs via corepack
, which I was not able to get working. I also tried nodePackages.pnpm
, but this way it prevents you from managing the node version via pnpm
.
prevents you from managing the node version via pnpm
.
I realized that managing node this way goes against the ethos of the whole declarative thing so it makes sense why the standalone install would not be of much use to nixos.
I used to install pnpm
using the “standalone installation”, as described in the initial post, but I’m now using it with success via the corepack nix package. Quick example:
~$ mkdir testing-pnpm
~$ cd testing-pnpm/
~/testing-pnpm$ nix-shell -p nodejs_22 corepack_22
# ...
[nix-shell:~/testing-pnpm]$ which pnpm
/nix/store/kmm9fi163v374gv6i9qyi3crrhy85r1l-corepack-nodejs-22.3.0/bin/pnpm
[nix-shell:~/testing-pnpm]$
[nix-shell:~/testing-pnpm]$
[nix-shell:~/testing-pnpm]$ pnpm --version
! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-9.5.0.tgz
? Do you want to continue? [Y/n] Y
9.5.0
When we add some npm package for the first time, it will automatically add the packageManager
field to package.json
:
[nix-shell:~/testing-pnpm]$ pnpm init
[nix-shell:~/testing-pnpm]$ pnpm add underscore
! The local project doesn't define a 'packageManager' field. Corepack will now add one referencing pnpm@9.5.0+sha512.140036830124618d624a2187b50d04289d5a087f326c9edfc0ccd733d76c4f52c3a313d4fc148794a2a9d81553016004e6742e8cf850670268a7387fc220c903.
! For more details about this field, consult the documentation at https://nodejs.org/api/packages.html#packagemanager
Packages: +1
+
Progress: resolved 1, reused 0, downloaded 1, added 1, done
dependencies:
+ underscore 1.13.6
Done in 2.1s
[nix-shell:~/testing-pnpm]$
Here is how package.json
looks like now:
{
"name": "testing-pnpm",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"packageManager": "pnpm@9.5.0+sha512.140036830124618d624a2187b50d04289d5a087f326c9edfc0ccd733d76c4f52c3a313d4fc148794a2a9d81553016004e6742e8cf850670268a7387fc220c903",
"dependencies": {
"underscore": "^1.13.6"
}
}
1 Like