Nix Shell for Node.js development
A Nix shell that pins Node.js, Yarn and common tooling for a JavaScript project.
1 min read
Updated
A shell.nix that pins Node.js, Yarn and the everyday tools around a JavaScript project, so nix-shell gives everyone the same environment. The usage notes and the shell expression are below.
Usage
- First install the Nix Package Manager
- Then download
shell.nixfile to your project root directory - Finally run
nix-shell. This will automatically setup the environment and open a shell session for you.
Note: You can found more packages here: https://search.nixos.org/packages
shell.nix
text
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
name = "workspace";
nativeBuildInputs = [
pkgs.tig
pkgs.git
pkgs.git-radar
pkgs.git-secret
pkgs.vim
pkgs.nodejs
pkgs.nodePackages.nodemon
pkgs.yarn
pkgs.docker
pkgs.docker-compose
pkgs.gnumake
pkgs.tmux
pkgs.tmuxPlugins.resurrect
pkgs.tmuxPlugins.continuum
pkgs.jq
];
shellHook = ''
mkdir -p .nix-node
export NODE_PATH=$PWD/.nix-node
export PATH=$NODE_PATH/bin:$PATH
export PS1='\[\033[1;32m\][nix-shell]:\[\033[0;34m\]\w\[\033[0;37m\]\$\[\033[0m\]\n\[\033[0;37m\]$(if [ -f package.json ]; then jq -r .name package.json; else echo git; fi):(\[\033[1;37m\]$(git rev-parse --abbrev-ref HEAD)\[\033[0;37m\])>\[\033[0m\] '
tmux set-option -g prefix C-e
git config --global core.editor "vim"
npm config set prefix $NODE_PATH
'';
}