These unofficial patches were applied to this fork for our use:
- 6290fed32c4bbaf422ca4d385ab1ff932715666f
- 4b705a2554a4cbfef9494fafc29152eeb0586509
There is also a minimal but much more reliable mkYarnPackage alternative which
does not perform link farming nor most of the indirections that yarn2nix likes
to do, since it is extremely brittle on large projects (especially those with
Git dependencies that have Git submodules).
Converts yarn.lock files into nix expression.
- Make yarn and yarn2nix available in your shell.
cd $GIT_REPO nix-env -i yarn2nix -f . nix-env -i yarn -f .
- Go to your project dir
- If you have not generated a yarn.lock file before, run
yarn install
- Create a
yarn.nixvia:yarn2nix > yarn.nix - Create a
default.nixto build your application (see the example below)
Make sure to generate the lock file with yarn >= 1.10.1
For example, for the front-end of weave's microservice reference application:
with (import <nixpkgs> {});
with (import /home/maarten/code/nixos/yarn2nix { inherit pkgs; });
rec {
weave-front-end = mkYarnPackage {
name = "weave-front-end";
src = ./.;
packageJSON = ./package.json;
yarnLock = ./yarn.lock;
# NOTE: this is optional and generated dynamically if omitted
yarnNix = ./yarn.nix;
};
}note: you must modify /home/maarten/code/nixos/yarn2nix
To make this work nicely, I exposed the express server in server.js as a binary:
- Add a
binentry topackages.jsonwith the valueserver.js - Add
#!/usr/bin/env nodeat the top of the file chmod +x server.js
- Run
nix-buildIn thefront-enddirectory. Copy the result path. - Create an isolated environment
cd /tmp; nix-shell --pure -p bash. /nix/store/some-path-to-frontend/bin/weave-demo-frontend
./update-yarn-nix.sh
./tests/no-import-from-derivation/update-yarn-nix.sh
./run-tests.shyarn2nix is released under the terms of the GPL-3.0 license.