Giter Site home page Giter Site logo

aminechikhaoui / yarn2nix Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nix-community/yarn2nix

0.0 1.0 0.0 677 KB

Generate nix expressions from a yarn.lock file [maintainer=???]

License: GNU General Public License v3.0

Nix 91.95% JavaScript 7.20% Shell 0.85%

yarn2nix's Introduction

yarn2nix

Converts yarn.lock files into nix expression.

  1. Make yarn and yarn2nix available in your shell.
    cd $GIT_REPO
    nix-env -i yarn2nix -f .
    nix-env -i yarn -f .
  2. Go to your project dir
  3. If you have not generated a yarn.lock file before, run
    yarn install
  4. Create a yarn.nix via:
    yarn2nix > yarn.nix
  5. Create a default.nix to build your application (see the example below)

Requirements

Make sure to generate the lock file with yarn >= 1.10.1

Example default.nix

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:

  1. Add a bin entry to packages.json with the value server.js
  2. Add #!/usr/bin/env node at the top of the file
  3. chmod +x server.js

Testing the example

  1. Run nix-build In the front-end directory. Copy the result path.
  2. Create an isolated environment cd /tmp; nix-shell --pure -p bash.
  3. /nix/store/some-path-to-frontend/bin/weave-demo-frontend

Run tests locally

./update-yarn-nix.sh
./tests/no-import-from-derivation/update-yarn-nix.sh
./run-tests.sh

Troubleshooting

nix-build fails with "found changes in the lockfile" error

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).

License

yarn2nix is released under the terms of the GPL-3.0 license.

yarn2nix's People

Contributors

adrian-gierakowski avatar albertov avatar betaboon avatar chekoopa avatar chpatrick avatar dasj avatar dywedir avatar flokli avatar fmnxl avatar frontsideair avatar johnchildren avatar lheckemann avatar manveru avatar moretea avatar nh2 avatar nicknovitski avatar nightkr avatar phryneas avatar sbjorn avatar srghma avatar thatsmydoing avatar yurrriq avatar zimbatm avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.