All Projects → stephank → yarn-plugin-nixify

stephank / yarn-plugin-nixify

Licence: BSD-2-Clause license
Yarn v3 plugin to help with Nix packaging

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Labels

Projects that are alternatives of or similar to yarn-plugin-nixify

nix-npm-buildpackage
Build nix packages that use npm/yarn
Stars: ✭ 48 (+17.07%)
Mutual labels:  nix, yarn
nix-xdg
[WIP] Nix overlay for making programs xdg compliant
Stars: ✭ 18 (-56.1%)
Mutual labels:  nix
nvfetcher
Generate nix sources expr for the latest version of packages
Stars: ✭ 95 (+131.71%)
Mutual labels:  nix
nix-configs
My Nix{OS} configuration files
Stars: ✭ 54 (+31.71%)
Mutual labels:  nix
flink-spark-submiter
从本地IDEA提交Flink/Spark任务到Yarn/k8s集群
Stars: ✭ 157 (+282.93%)
Mutual labels:  yarn
marayarn
Marathon on yarn
Stars: ✭ 13 (-68.29%)
Mutual labels:  yarn
eris
Serve your /nix/store directory over the internet ✨
Stars: ✭ 73 (+78.05%)
Mutual labels:  nix
freebsd-ports-nix
Nix package manager port for the FreeBSD Ports Collection
Stars: ✭ 33 (-19.51%)
Mutual labels:  nix
ts-react-boilerplate
A very opinionated (React/TypeScript/Redux/etc) frontend boilerplate
Stars: ✭ 43 (+4.88%)
Mutual labels:  yarn
terranix
terranix is a terraform.json generator with a nix-like feeling
Stars: ✭ 164 (+300%)
Mutual labels:  nix
psc-package2nix
Tool to derive a Nix expression from a psc-package.json configuration.
Stars: ✭ 13 (-68.29%)
Mutual labels:  nix
nyoom.emacs
Configurable, Minimal, Fast emacs config based on Nano-emacs and Doom
Stars: ✭ 59 (+43.9%)
Mutual labels:  nix
restql
RESTful API Resolver for Nested-Linked Resources | 🕸 🕷
Stars: ✭ 16 (-60.98%)
Mutual labels:  yarn
yall
Yarn/npm for monorepos
Stars: ✭ 27 (-34.15%)
Mutual labels:  yarn
nixpkgs-review-checks
Add additional checks and more information from build logs and outputs to the reports generated by nixpkgs-review.
Stars: ✭ 27 (-34.15%)
Mutual labels:  nix
awesome-env-config-cn
各种开发语言项目环境国内(中国国内加速镜像)配置教程和部分实践经验,包括github.com, nodejs,npm,nvm, yarn, java, maven, gradle, python, mysys2, elasticsearch, php,golang等等,更多正在加入中...
Stars: ✭ 50 (+21.95%)
Mutual labels:  yarn
dns.nix
A Nix DSL for DNS zone files
Stars: ✭ 69 (+68.29%)
Mutual labels:  nix
MacOS-All-In-One-Update-Script
Mac update shell script (Appstore, macOS, Homebrew and others)
Stars: ✭ 39 (-4.88%)
Mutual labels:  yarn
nix-config
A collection of my system configs and dotfiles
Stars: ✭ 35 (-14.63%)
Mutual labels:  nix
frontend-gradle-plugin
All-in-one Gradle Node plugin, Gradle NPM plugin, Gradle Yarn Berry plugin to build Javascript applications with Gradle: distribution management, built-in tasks.
Stars: ✭ 120 (+192.68%)
Mutual labels:  yarn

yarn-plugin-nixify

Upgrading the plugin? See UPGRADING.md

Generates a Nix expression to build a Yarn v3 project (not using zero-install).

  • Provides a yarn shell alias in the Nix builder — no global Yarn v1 install needed.

  • A default configure-phase that runs yarn in your project. (May be all that's needed for plain JavaScript projects.)

  • A default install-phase that creates executables for you based on "bin" in your package.json, making your package readily installable.

  • Granular fetching of dependencies in Nix, speeding up rebuilds and potentially allowing downloads to be shared between projects.

  • Preloading of your Yarn cache into the Nix store, speeding up local nix-build.

  • Automatically keeps your Nix expression up-to-date as you yarn add / yarn remove dependencies.

  • No Nix installation required for the plugin itself, so it should be safe to add to your project even if some developers don't use Nix.

Related projects:

  • node2nix, yarn2nix: Both do a similar job, but as separate commands. By comparison, this plugin tries to automate the process and make things easy for Nix and non-Nix devs alike.

  • composer-plugin-nixify: Similar solution for PHP with Composer.

Usage

The minimum version of Yarn is 3.1.0. Run the following in your project folder to check:

# Check your Yarn version
yarn --version

# Upgrade to the latest version, if necessary
yarn set version berry

To then use the Nixify plugin:

# Install the plugin
yarn plugin import https://raw.githubusercontent.com/stephank/yarn-plugin-nixify/main/dist/yarn-plugin-nixify.js

# Run Yarn as usual
yarn

# Build your project with Nix
nix-build

Running yarn with this plugin enabled will generate two files:

  • yarn-project.nix: This file is always overwritten, and contains a basic derivation for your project.

  • default.nix: Only generated if it does not exist yet. This file is intended to be customized with any project-specific logic you need.

This may already build successfully! But if your project needs extra build steps or native dependencies, you may have to customize default.nix a bit. Some examples of what's possible:

{ pkgs ? import <nixpkgs> { } }:

let

  project = pkgs.callPackage ./yarn-project.nix {

    # Example of selecting a specific version of Node.js.
    nodejs = pkgs.nodejs-14_x;

  } {

    # Example of providing a different source tree.
    src = pkgs.lib.cleanSource ./.;

  };

in project.overrideAttrs (oldAttrs: {

  # If your top-level package.json doesn't set a name, you can set one here.
  name = "myproject";

  # Example of adding packages to the build environment.
  # Especially dependencies with native modules may need a Python installation.
  buildInputs = oldAttrs.buildInputs ++ [ pkgs.python3 ];

  # Example of invoking a build step in your project.
  buildPhase = ''
    yarn build
  '';

})

Settings

Some additional settings are available in .yarnrc.yml:

  • nixExprPath can be set to customize the path where the Nixify plugin writes yarn-project.nix. For example, if you're also using Niv in your project, you may prefer to set this to nix/yarn-project.nix.

  • generateDefaultNix can be set to false to disable generating a default.nix. This file is only generated if it doesn't exist yet, but this flag can be useful if you don't want a default.nix at all.

  • enableNixPreload can be set to false to disable preloading Yarn cache into the Nix store. This preloading is intended to speed up a local nix-build, because Nix will not have to download dependencies again. Preloading does mean another copy of dependencies on disk, even if you don't do local Nix builds, but the size is usually not an issue on modern disks.

  • isolatedNixBuilds, see ISOLATED_BUILDS.md.

  • installNixBinariesForDependencies can be set to also install executables for binaries defined by dependencies. This can be useful if these need to be in $PATH for other tools, or if you're creating a workspace just to collect command-line tools.

Hacking

# In this directory:
yarn
yarn build-dev

# In your test project:
yarn plugin import /path/to/yarn-plugin-nixify/dist/yarn-plugin-nixify.dev.js

(Alternatively, add a direct reference in .yarnrc.yml. This will likely only work if the Nix sandbox is disabled.)

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