Generate nix expressions from a yarn.lock file [maintainer=???]
Nix
127
118 commits
updated Mar 24, 2022
Converts yarn.lock files into nix expression.
cd $GIT_REPO
nix-env -i yarn2nix -f .
nix-env -i yarn -f .
yarn install
yarn.nix via:
yarn2nix > yarn.nix
default.nix to build your application (see the example below)Make sure to generate the lock file with yarn >= 1.10.1
default.nixFor 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:
bin entry to packages.json with the value server.js#!/usr/bin/env node at the top of the filechmod +x server.jsnix-build In the front-end directory. Copy the result path.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.sh
yarn2nix runs on the beginning of build to ensure that yarn.lock is correct (and to collect nix-expressions if you haven't provided them). So, if there is something wrong, yarn2nix tries to change the lockfile, but fails and aborts, as it is run with --no-patch flag (as we can't let changes inside of nix-build).
It can sometimes give false-positives, so the solution at the moment is running yarn2nix --no-nix to patch the lockfile in place (the flag is just to avoid config spam, unless you're up to write yarn.nix).
yarn2nix is released under the terms of the GPL-3.0 license.
302 followers · starred Dec 2019
373 followers · starred Nov 2017
131 followers · starred Feb 2023
36 followers · starred May 2017
Generate nix expressions from a yarn.lock file [maintainer=???]
Nix
127
118 commits
updated Mar 24, 2022
Converts yarn.lock files into nix expression.
cd $GIT_REPO
nix-env -i yarn2nix -f .
nix-env -i yarn -f .
yarn install
yarn.nix via:
yarn2nix > yarn.nix
default.nix to build your application (see the example below)Make sure to generate the lock file with yarn >= 1.10.1
default.nixFor 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:
bin entry to packages.json with the value server.js#!/usr/bin/env node at the top of the filechmod +x server.jsnix-build In the front-end directory. Copy the result path.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.sh
yarn2nix runs on the beginning of build to ensure that yarn.lock is correct (and to collect nix-expressions if you haven't provided them). So, if there is something wrong, yarn2nix tries to change the lockfile, but fails and aborts, as it is run with --no-patch flag (as we can't let changes inside of nix-build).
It can sometimes give false-positives, so the solution at the moment is running yarn2nix --no-nix to patch the lockfile in place (the flag is just to avoid config spam, unless you're up to write yarn.nix).
yarn2nix is released under the terms of the GPL-3.0 license.
302 followers · starred Dec 2019
373 followers · starred Nov 2017
131 followers · starred Feb 2023
36 followers · starred May 2017