Giter VIP home page Giter VIP logo

mk-node's Introduction

Bundle your node files as a Nix derivation

This is a thin wrapper around node2nix that creates a node environment with the dependencies defined in package-lock.json. It provides convenience (not having to keep several .nix files up-to-date with package.json) at the expense of longer build times.

The package provides an overlay with a single function mkNodeModules, that takes the following arguments:

  • src: the path to your project. Usually ./.
  • node2nix (optional): node2nix package to use. Defaults to pkgs.nodePackages.node2nix
  • nodejs (optional): nodejs package to use. Defaults to pkgs.nodePackages.nodejs-16_x
  • fixNodeGyp (default: false): set to true if you’re having an installation error with node-gyp. See this issue for more information

Example

Assuming you have a project with a package.json and package-lock.json, you can use the following:

{
  inputs.mk-node.url = "github:sephii/mk-node";
  outputs = { self, nixpkgs, mk-node }:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs { inherit system; overlays = [ mk-node.overlay ]; };
      nodejs = pkgs.nodejs-16_x;
      nodeModules = pkgs.mkNodeModules { src = ./.; inherit nodejs; };
    in {
      # Include anything else you need for your derivation (eg. use `buildPythonApplication`, `mkPoetryApplication`, etc)
      defaultPackage.${system} = stdenv.mkDerivation {
        buildPhase = ''
          ln -s ${nodeModules}/lib/node_modules ./node_modules
          export PATH="${nodeModules}/bin:$PATH"
          ${nodejs}/bin/npm run build

          rm -rf ./node_modules
        '';
      };
    };
}

mk-node's People

Contributors

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