All Projects → nix-community → Yarn2nix

nix-community / Yarn2nix

Licence: gpl-3.0
Generate nix expressions from a yarn.lock file [maintainer=???]

Labels

Projects that are alternatives of or similar to Yarn2nix

Vuizvui
Nix(OS) expressions used by the OpenLab and its members
Stars: ✭ 87 (-20.91%)
Mutual labels:  nix
System
My system configuration
Stars: ✭ 94 (-14.55%)
Mutual labels:  nix
Cached Nix Shell
Instant startup time for nix-shell
Stars: ✭ 103 (-6.36%)
Mutual labels:  nix
Bauer
An Emacs+Nix IDE
Stars: ✭ 89 (-19.09%)
Mutual labels:  nix
Ghc.nix
Nix (shell) expression for working on GHC
Stars: ✭ 94 (-14.55%)
Mutual labels:  nix
Nixcloud Webservices
This nixpkgs extension, called nixcloud-webservices, focuses on ease of deployment of web-related technologies.
Stars: ✭ 98 (-10.91%)
Mutual labels:  nix
Nixos Configs
My NixOS configs
Stars: ✭ 86 (-21.82%)
Mutual labels:  nix
Powerline Rs
GitLab: https://gitlab.com/jD91mZM2/powerline-rs
Stars: ✭ 108 (-1.82%)
Mutual labels:  nix
Stack2nix
Generate nix expressions for Haskell projects
Stars: ✭ 93 (-15.45%)
Mutual labels:  nix
Nixos Config
Mirror of https://code.balsoft.ru/balsoft/nixos-config
Stars: ✭ 100 (-9.09%)
Mutual labels:  nix
Upcast
Abandonware
Stars: ✭ 91 (-17.27%)
Mutual labels:  nix
Pre Commit Hooks.nix
Seamless integration of https://pre-commit.com git hooks with Nix.
Stars: ✭ 92 (-16.36%)
Mutual labels:  nix
Styx
Static site generator in Nix expression language.
Stars: ✭ 99 (-10%)
Mutual labels:  nix
Rules nixpkgs
Rules for importing Nixpkgs packages into Bazel.
Stars: ✭ 88 (-20%)
Mutual labels:  nix
Nix Tree
Interactively browse the dependency graph of your Nix derivations.
Stars: ✭ 104 (-5.45%)
Mutual labels:  nix
Homies
linux package management
Stars: ✭ 86 (-21.82%)
Mutual labels:  nix
Hydra Tutorial
Sample configuration files for setting up your own Hydra continuous integration server.
Stars: ✭ 95 (-13.64%)
Mutual labels:  nix
Nix Haskell Monorepo
Pragmatic tutorial on how to use nix with a haskell monorepo
Stars: ✭ 111 (+0.91%)
Mutual labels:  nix
Nix Home
Utilities for working with user configurations in Nix.
Stars: ✭ 107 (-2.73%)
Mutual labels:  nix
Nix Linter
Linter for the Nix expression language
Stars: ✭ 100 (-9.09%)
Mutual labels:  nix

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].