Yet another way of packaging Node applications with Nix. Unlike alternatives, this plugin is built for performance (both speed and disk usage) and aims to be unique with the following goals:
Requires a Yarn version > 4 project using PnP linking (the default). Zero installs are not required, so it's recommended to just use the global cache when developing your project rather than storing dependencies in your repo.
yarnpnp2nix is currently tested with Yarn version 4.0.1.
Install Yarn plugin in your project:
yarn plugin import https://github.com/madjam002/yarnpnp2nix/raw/master/plugin/dist/plugin-yarnpnp2nix.js
Run yarn
to make sure all packages are installed and to automatically generate a yarn-manifest.nix
for your project.
Create a flake.nix
if you haven't already for your project, add this repo (yarnpnp2nix
) as an input (e.g yarnpnp2nix.url = github:madjam002/yarnpnp2nix;
)
See test/flake.nix for an example on how to create Nix derivations for Yarn packages using mkYarnPackagesFromManifest
.
Setting a build command for a package:
mkYarnPackagesFromManifest {
yarnManifest = import ./workspace/yarn-manifest.nix;
packageOverrides = {
"my-package@workspace:packages/my-package".build = ''
// Any custom build logic here
'';
};
};
Fixing a hash mismatch:
mkYarnPackagesFromManifest {
yarnManifest = import ./workspace/yarn-manifest.nix;
packageOverrides = {
"my-package@workspace:packages/my-package".outputHash = "sha512-4pNZfI6GbsEsBySIs+gK98AGZhWf9QZ3SLytsWIzLnCeJYt2ma6qVK5Gk4TSHsUOmSjqUX8seBCKBBL7f1pvTQ==";
};
};
Known caveats:
nix build
(either using the -j
argument or setting your Nix config appropriately)Patched packages with localy stored patches need to have their revision strings updated to use relative paths instead of the default ~/
prefix
For example, to fix a revision of a package stored in packages/my-package
(relative to the workspace root), update the revision as such:
Possible future improvements:
Licensed under the MIT License.
View the full license here.