con un clic
node2nix
node2nix Skill
Instalar con Codex o Claude Copia este prompt, pégalo en Codex, Claude u otro asistente, y deja que revise la página de la skill y la instale por ti.
Menú
node2nix Skill
Instalar con Codex o Claude Copia este prompt, pégalo en Codex, Claude u otro asistente, y deja que revise la página de la skill y la instale por ti.
Basado en la clasificación ocupacional SOC
Read, write, search and reorganise notes in the local Obsidian vaults. Use for anything touching ~/Documents/R3_vault, ~/Documents/Synechron or ~/Documents/My_Obsidian_Vault/Privat — finding notes, adding or editing content, renaming/moving notes without breaking links, and daily notes. Triggers on "my notes", "my vault", "Obsidian", "write this up in my notes", or a request to look something up in personal documentation.
Manage DNS records for the user's GoDaddy-registered domains. Add/upsert, delete, list, look up specific records, verify a stored record matches an expected value, and check public DNS resolution via dig. Triggers on `/dns`, requests to add/change/check A, AAAA, CNAME, MX, TXT, NS, SRV records on the user's domains, debugging DNS propagation, or auditing what's set at GoDaddy vs what's resolving in the wild.
Operate Google Workspace from the terminal via the `gog` CLI (gogcli). Use for checking and replying to Gmail, managing Google Tasks, reading and creating Calendar events, Google Chat (spaces/DMs/messages), Meet spaces, Contacts, Drive/Docs/Sheets, and more. Triggers on `/gog`, `/gog mail`, `/gog tasks`, `/gog events`, `/gog chat`, `/gog meet`, or any request to check/read/reply/send email, list or add tasks, see today's agenda, or message someone on Chat for the user's Google account.
Agenix Skill
cargo2nix Skill
COSMIC Desktop Environment Skill
| name | node2nix |
| version | 1 |
| description | node2nix Skill |
A specialized skill for converting NPM packages to Nix expressions using node2nix, enabling declarative and reproducible Node.js package management with Nix.
Purpose: Provide comprehensive support for using node2nix to generate Nix expressions from NPM packages, handle dependencies, and integrate Node.js projects with Nix/NixOS.
Invoke When:
# Install node2nix from nixpkgs
nix-env -f '<nixpkgs>' -iA nodePackages.node2nix
# Or with nix profile
nix profile install nixpkgs#nodePackages.node2nix
# Verify installation
node2nix --version
# /etc/nixos/configuration.nix
environment.systemPackages = with pkgs; [
nodePackages.node2nix
];
# home.nix
home.packages = with pkgs; [
nodePackages.node2nix
];
# Global installation
npm install -g node2nix
# Or use npx (no installation)
npx node2nix
# Navigate to your Node.js project
cd my-nodejs-project
# Generate Nix expressions
node2nix
# This creates three files:
# - node-packages.nix (package definitions)
# - node-env.nix (build logic)
# - default.nix (composition expression)
# Build the package
nix-build -A package
# Result symlink points to build output
./result/bin/my-app
# Or install to profile
nix-env -f default.nix -iA package
default.nix - Main entry point:
{ pkgs ? import <nixpkgs> {} }:
let
nodePackages = import ./node-packages.nix {
inherit pkgs;
inherit (pkgs) system fetchurl fetchgit stdenv lib;
};
in
{
package = nodePackages.package;
shell = nodePackages.shell;
}
node-packages.nix - Package definitions:
# Generated by node2nix
# Contains all package definitions with dependencies
{
# ... dependency definitions
"my-package" = nodeEnv.buildNodePackage {
name = "my-package";
version = "1.0.0";
src = ./.;
dependencies = [ ... ];
# ... build configuration
};
}
node-env.nix - Build environment:
# Shared build logic for all packages
# Handles npm install, dependency linking, etc.
# Usually not modified directly
# Generate with package-lock.json
node2nix -l package-lock.json
# Or explicitly
node2nix --lock package-lock.json
# Ensures exact dependency versions
# Generate with shrinkwrap file
node2nix -l npm-shrinkwrap.json
# Generate with yarn lock file
node2nix -l yarn.lock
# Note: Requires yarn support in node2nix
Why Use Lock Files?
# Only install production dependencies
node2nix
# Explicit production mode
node2nix --production
# Include devDependencies
node2nix --development
# Useful for building developer tools
node2nix --development -i package.json
# For tools like TypeScript compiler
node2nix --development
# Result includes devDependencies
nix-build -A package
# Uses latest LTS Node.js
node2nix
# Enable Node.js 4.x mode
node2nix -4
# Equivalent to:
node2nix --nodejs-4
node2nix -6
node2nix -8
# Override Node.js version in default.nix
{ pkgs ? import <nixpkgs> {} }:
let
nodejs = pkgs.nodejs_20; # Use Node.js 20
nodePackages = import ./node-packages.nix {
inherit pkgs;
inherit (pkgs) system fetchurl fetchgit stdenv lib;
nodejs = nodejs;
};
in
{
package = nodePackages.package;
}
# Use custom package.json location
node2nix -i packages/backend/package.json
# Output to custom directory
node2nix -i package.json -o node-packages.nix
# Custom composition file
node2nix -c my-composition.nix
# Create a node-packages.json file
cat > node-packages.json <<EOF
[
"express",
"lodash",
"axios"
]
EOF
# Generate from package list
node2nix -i node-packages.json
# Builds packages without package.json
# Add extra packages not in dependencies
cat > supplement.json <<EOF
{
"global-tools": {
"pm2": "^5.0.0",
"nodemon": "^2.0.0"
}
}
EOF
# Generate with supplements
node2nix --supplement-input supplement.json
# Configure private registry
node2nix \
--registry "https://registry.company.com" \
--registry-auth-token "YOUR_AUTH_TOKEN"
# With scope
node2nix \
--registry "https://registry.company.com" \
--registry-scope "@mycompany"
# Different registries for different scopes
node2nix \
--registry "https://public.npm.org" \
--registry "https://private.company.com" \
--registry-scope "@company" \
--registry-auth-token "TOKEN"
# node2nix respects .npmrc settings
cat > .npmrc <<EOF
@mycompany:registry=https://registry.company.com/
//registry.company.com/:_authToken=YOUR_TOKEN
EOF
node2nix
# Enable SSH for private git deps
node2nix --use-fetchgit-private
# For dependencies like:
# "my-lib": "git+ssh://git@github.com/company/lib.git"
# Include peer dependencies
node2nix --include-peer-dependencies
# Useful for plugin systems
# Remove optional dependencies
node2nix --strip-optional-dependencies
# Helps when optional deps cause build failures
# Force fresh package metadata fetch
node2nix --bypass-cache
# Useful when registry data is stale
# Don't copy devDependencies to store
node2nix --no-copy-node-env
# Reduces closure size
# default.nix
{ pkgs ? import <nixpkgs> {} }:
let
nodePackages = import ./node-packages.nix {
inherit pkgs;
inherit (pkgs) system fetchurl fetchgit stdenv lib;
};
in
{
package = nodePackages.package.override {
# Add native dependencies
buildInputs = with pkgs; [
python3
pkgs.cairo
pkgs.pango
];
# Skip npm install phase
dontNpmInstall = true;
# Custom build phase
buildPhase = ''
npm run custom-build
'';
};
}
{ pkgs ? import <nixpkgs> {} }:
let
nodePackages = (import ./node-packages.nix {
inherit pkgs;
inherit (pkgs) system fetchurl fetchgit stdenv lib;
}).override {
# Override for specific dependency
"canvas" = oldAttrs: {
buildInputs = oldAttrs.buildInputs ++ [
pkgs.cairo
pkgs.pango
pkgs.giflib
];
preInstall = ''
export CANVAS_NO_REBUILD=1
'';
};
# Fix bcrypt native module
"bcrypt" = oldAttrs: {
buildInputs = [ pkgs.python3 ];
};
};
in
{
package = nodePackages.package;
}
# Override all packages
{ pkgs ? import <nixpkgs> {} }:
let
nodePackages = import ./node-packages.nix {
inherit pkgs;
inherit (pkgs) system fetchurl fetchgit stdenv lib;
# Global overrides
globalBuildInputs = with pkgs; [
python3
pkgs.nodejs.libv8
];
};
in
nodePackages
# Generate with shell support
node2nix
# Enter development shell
nix-shell -A shell
# Now you can:
# - Modify source code
# - Run npm scripts
# - Test without rebuilding
# shell.nix
{ pkgs ? import <nixpkgs> {} }:
let
nodePackages = import ./node-packages.nix {
inherit pkgs;
inherit (pkgs) system fetchurl fetchgit stdenv lib;
};
in
nodePackages.shell.override {
buildInputs = with pkgs; [
# Additional development tools
nodejs_20
nodePackages.typescript
nodePackages.eslint
nodePackages.prettier
# Native dependencies for development
python3
cairo
pango
];
shellHook = ''
echo "Node.js development environment"
echo "Node version: $(node --version)"
echo "npm version: $(npm --version)"
# Set up node_modules symlink
[ -d node_modules ] || ln -s $NODE_PATH node_modules
# Custom environment variables
export NODE_ENV=development
export DEBUG=*
'';
}
# Enter shell
nix-shell
# Run development server
npm run dev
# Run tests
npm test
# Build
npm run build
# Project structure:
# my-cli/
# ├── package.json
# ├── package-lock.json
# └── bin/
# └── my-cli.js
# Generate Nix expressions
cd my-cli
node2nix -l package-lock.json
# Build
nix-build -A package
# Test
./result/bin/my-cli --version
# Install
nix-env -f default.nix -iA package
# Express.js app with dependencies
node2nix -l package-lock.json
# Custom default.nix for systemd service
{ pkgs ? import <nixpkgs> {} }:
let
nodePackages = import ./node-packages.nix {
inherit pkgs;
inherit (pkgs) system fetchurl fetchgit stdenv lib;
};
app = nodePackages.package;
in
{
inherit app;
# Systemd service
service = pkgs.writeTextFile {
name = "my-app.service";
text = ''
[Unit]
Description=My Node.js App
After=network.target
[Service]
Type=simple
ExecStart=${app}/bin/my-app
Restart=on-failure
Environment="NODE_ENV=production"
[Install]
WantedBy=multi-user.target
'';
};
}
# Workspace project
# monorepo/
# ├── package.json
# ├── packages/
# │ ├── app/
# │ │ └── package.json
# │ └── lib/
# │ └── package.json
# Generate from root
node2nix -l package-lock.json
# Or generate per package
cd packages/app
node2nix -l ../../package-lock.json
# Include dev dependencies for TypeScript
node2nix --development -l package-lock.json
# Build includes TypeScript compilation
{ pkgs ? import <nixpkgs> {} }:
let
nodePackages = import ./node-packages.nix {
inherit pkgs;
inherit (pkgs) system fetchurl fetchgit stdenv lib;
};
in
{
package = nodePackages.package.override {
buildPhase = ''
# Compile TypeScript
npm run build
'';
installPhase = ''
mkdir -p $out/bin
cp -r dist/* $out/
# Create wrapper
makeWrapper ${pkgs.nodejs}/bin/node $out/bin/my-app \
--add-flags "$out/index.js"
'';
};
}
# Electron requires development dependencies
node2nix --development -l package-lock.json
{ pkgs ? import <nixpkgs> {} }:
let
nodePackages = import ./node-packages.nix {
inherit pkgs;
inherit (pkgs) system fetchurl fetchgit stdenv lib;
};
in
{
package = nodePackages.package.override {
buildInputs = with pkgs; [
# Electron dependencies
xorg.libX11
xorg.libXtst
gtk3
nss
nspr
alsa-lib
cups
dbus
atk
cairo
pango
gdk-pixbuf
gtk3
];
# Don't rebuild native modules
ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
};
}
# /etc/nixos/configuration.nix
{ config, pkgs, ... }:
let
myNodeApp = import /path/to/my-app {
inherit pkgs;
};
in
{
environment.systemPackages = [
myNodeApp.package
];
# Or as a systemd service
systemd.services.my-node-app = {
description = "My Node.js Application";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${myNodeApp.package}/bin/my-app";
Restart = "on-failure";
User = "nodejs";
# Security hardening
DynamicUser = true;
ProtectSystem = "strict";
NoNewPrivileges = true;
PrivateTmp = true;
};
environment = {
NODE_ENV = "production";
PORT = "3000";
};
};
}
# modules/my-app.nix
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.my-app;
myApp = import ../my-app {
inherit pkgs;
};
in
{
options.services.my-app = {
enable = mkEnableOption "My Node.js App";
port = mkOption {
type = types.int;
default = 3000;
description = "Port to listen on";
};
environment = mkOption {
type = types.attrsOf types.str;
default = {};
description = "Environment variables";
};
};
config = mkIf cfg.enable {
systemd.services.my-app = {
description = "My Node.js Application";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${myApp.package}/bin/my-app";
Restart = "on-failure";
DynamicUser = true;
};
environment = cfg.environment // {
NODE_ENV = "production";
PORT = toString cfg.port;
};
};
networking.firewall.allowedTCPPorts = [ cfg.port ];
};
}
{
description = "My Node.js Application";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
nodePackages = import ./node-packages.nix {
inherit pkgs;
inherit (pkgs) system fetchurl fetchgit stdenv lib;
};
in
{
packages = {
default = nodePackages.package;
my-app = nodePackages.package;
};
apps.default = {
type = "app";
program = "${nodePackages.package}/bin/my-app";
};
devShells.default = nodePackages.shell.override {
buildInputs = with pkgs; [
nodejs_20
nodePackages.typescript
];
};
}
);
}
# Build
nix build
# Run
nix run
# Development shell
nix develop
# Update dependencies
node2nix -l package-lock.json
nix flake lock --update-input nixpkgs
Problem: Package with native dependencies fails to build
Solution:
{ pkgs ? import <nixpkgs> {} }:
let
nodePackages = import ./node-packages.nix {
inherit pkgs;
inherit (pkgs) system fetchurl fetchgit stdenv lib;
};
in
{
package = nodePackages.package.override {
buildInputs = with pkgs; [
python3 # For node-gyp
pkgs.nodejs.libv8
# Common native deps
cairo
pango
giflib
libjpeg
libpng
];
# Environment for native builds
NIX_CFLAGS_COMPILE = "-I${pkgs.cairo.dev}/include/cairo";
NIX_LDFLAGS = "-L${pkgs.cairo}/lib";
};
}
Problem: Application can't find plugins/modules
Solution:
# In development shell
nix-shell -A shell
# Create node_modules symlink
ln -s $NODE_PATH node_modules
# Or in shell.nix:
shellHook = ''
[ -d node_modules ] || ln -s $NODE_PATH node_modules
'';
Problem: node2nix can't fetch package
Solution:
# Bypass cache
node2nix --bypass-cache
# Or update lock file
npm install
npm update
node2nix -l package-lock.json
Problem: Missing peer dependencies
Solution:
# Include peer dependencies
node2nix --include-peer-dependencies -l package-lock.json
Problem: Can't fetch from private git repos
Solution:
# Enable SSH for git
node2nix --use-fetchgit-private
# Ensure SSH keys are configured
# For declarative builds, use fetchgit with SSH URL override
Problem: Generated package has large closure
Solution:
# Production mode (no dev deps)
node2nix --production -l package-lock.json
# Strip optional dependencies
node2nix --strip-optional-dependencies
# Remove unnecessary build dependencies
{
package = nodePackages.package.override {
dontNpmInstall = true;
installPhase = ''
# Install only what's needed
mkdir -p $out
cp -r dist $out/
cp package.json $out/
'';
};
}
# Generate with custom composition file
node2nix -c my-composition.nix
# Allows custom package structure
{ pkgs ? import <nixpkgs> {} }:
let
nodePackages = import ./node-packages.nix {
inherit pkgs;
inherit (pkgs) system fetchurl fetchgit stdenv lib;
};
in
{
package = nodePackages.package.overrideAttrs (oldAttrs: {
patches = [
./patches/fix-vulnerability.patch
];
postPatch = ''
# Patch package.json
substituteInPlace package.json \
--replace "old-version" "new-version"
'';
});
}
{ pkgs ? import <nixpkgs> {} }:
let
nodePackages = import ./node-packages.nix {
inherit pkgs;
inherit (pkgs) system fetchurl fetchgit stdenv lib;
};
# Platform-specific overrides
package = if pkgs.stdenv.isDarwin
then nodePackages.package.override {
buildInputs = with pkgs.darwin.apple_sdk.frameworks; [
CoreServices
Foundation
];
}
else nodePackages.package;
in
{
inherit package;
}
# default.nix
{ pkgs ? import <nixpkgs> {}
, production ? true
}:
let
nodePackages = import ./node-packages.nix {
inherit pkgs;
inherit (pkgs) system fetchurl fetchgit stdenv lib;
};
in
{
package = nodePackages.package.override {
buildPhase = if production
then ''
export NODE_ENV=production
npm run build
''
else ''
export NODE_ENV=development
npm run build:dev
'';
};
}
Always use lock files
node2nix -l package-lock.json
Version control generated files
git add node-packages.nix node-env.nix default.nix
git commit -m "Add Nix expressions for Node.js project"
Use production mode for deployments
node2nix --production -l package-lock.json
Override packages with native deps
buildInputs = [ pkgs.python3 pkgs.cairo ];
Test in nix-shell before building
nix-shell -A shell
npm test
Pin nixpkgs version
pkgs ? import (fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/COMMIT.tar.gz";
sha256 = "...";
}) {}
Document overrides and customizations
# Override for canvas - requires Cairo
buildInputs = [ pkgs.cairo ];
Use flakes for modern projects
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
Separate development and production configs
# dev: node2nix --development
# prod: node2nix --production
Keep node2nix up to date
nix-env -u nodePackages.node2nix
Don't commit node_modules
# .gitignore
node_modules/
Don't skip lock files
# ❌ Bad
node2nix
# ✅ Good
node2nix -l package-lock.json
Don't ignore build failures silently
# ❌ Bad - hides issues
dontBuild = true;
# ✅ Good - fix the issue
buildInputs = [ requiredDeps ];
Don't hardcode paths
# ❌ Bad
"/usr/bin/node"
# ✅ Good
"${pkgs.nodejs}/bin/node"
Don't mix npm and nix package management
# ❌ Don't run npm install manually
# ✅ Let Nix handle it
Don't commit secrets
# Never commit tokens or auth
# Use environment variables or secrets management
Don't skip regeneration after updates
# After npm install/update:
node2nix -l package-lock.json
# Basic usage
node2nix # Generate from package.json
node2nix -l package-lock.json # Use lock file
node2nix --development # Include devDependencies
node2nix -i packages.json # Custom input file
# Node.js versions
node2nix -4 # Node.js 4.x
node2nix -6 # Node.js 6.x
node2nix -8 # Node.js 8.x
# Registry configuration
node2nix --registry URL # Custom registry
node2nix --registry-auth-token TOKEN # Auth token
node2nix --registry-scope SCOPE # Scoped packages
# Dependency handling
node2nix --include-peer-dependencies # Include peers
node2nix --strip-optional-dependencies # Remove optional
node2nix --bypass-cache # Force fresh fetch
# Advanced
node2nix --use-fetchgit-private # Private git repos
node2nix --supplement-input FILE # Additional packages
node2nix --no-copy-node-env # Smaller closure
# Output control
node2nix -o node-packages.nix # Custom output
node2nix -c composition.nix # Custom composition
node2nix -e node-env.nix # Custom environment
# Help
node2nix --help # Show help
node2nix --version # Show version
Ready to convert NPM packages to Nix with node2nix! 📦