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.nix
via:
yarn2nix > yarn.nix
- Create a
default.nix
to build your application (see the example below)
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 = buildYarnPackage {
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
bin
entry topackages.json
with the valueserver.js
- Add
#!/usr/bin/env node
at the top of the file chmod +x server.js
- Run
nix-build
In thefront-end
directory. 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
yarn2nix
is released under the terms of the GPL-3.0 license.