Skip to content
/ n2n Public

n2n is a Rust CLI that wraps `node2nix` and `nix-env` to install npm packages into the user's Nix profile.

Notifications You must be signed in to change notification settings

pliosoft/n2n

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

n2n

Install npm packages globally via Nix using node2nix.

Inspired by Nick Novitski's blog post.

Overview

n2n is a CLI tool that acts like npm install -g but uses Nix instead. It allows you to install npm packages into your Nix profile without relying on a global npm installation.

Installation

# Run directly
nix run github:clord/n2n -- <package-name>

# Install to your profile
nix profile install github:clord/n2n

Usage

# Install a package
n2n cowsay
n2n typescript
n2n @fission-ai/openspec

# The binary is now available
cowsay "Hello from Nix!"

Packages are installed to ~/.nix-profile/bin/.

How It Works

  1. Creates a temp directory at /tmp/nix-npm-install/<package>
  2. Runs node2nix --nodejs-18 to generate Nix expressions from the npm package
  3. Runs nix-env --install to install the package to your profile

The tool is self-contained: node2nix and nix are bundled via Nix's wrapProgram.

Features

  • Supports scoped packages (@scope/name)
  • Input validation to prevent injection attacks
  • Works in pure flake environments (no channels required)
  • Uses Node.js 18 (compatible with current nixpkgs)

Development

# Enter dev shell
nix develop

# Build
cargo build

# Run locally
nix run . -- cowsay

License

MIT

About

n2n is a Rust CLI that wraps `node2nix` and `nix-env` to install npm packages into the user's Nix profile.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published