From 4504c0f122ccbea42e80cd095677fb768f8373f8 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Thu, 28 Jul 2022 23:37:55 +0200 Subject: [PATCH] Add Node.js environment --- README.md | 3 +++ flake.nix | 5 +++++ node/.envrc | 1 + node/flake.lock | 42 ++++++++++++++++++++++++++++++++++++++++++ node/flake.nix | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 87 insertions(+) create mode 100644 node/.envrc create mode 100644 node/flake.lock create mode 100644 node/flake.nix diff --git a/README.md b/README.md index d9a61bc..7d07121 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,9 @@ nix flake init --template github:the-nix-way/dev-templates#go_1_17 # Go 1.18 nix flake init --template github:the-nix-way/dev-templates#go_1_18 +# Node.js +nix flake init --template github:the-nix-way/dev-templates#node + # Rust nix flake init --template github:the-nix-way/dev-templates#rust diff --git a/flake.nix b/flake.nix index afc61b3..bf58963 100644 --- a/flake.nix +++ b/flake.nix @@ -18,6 +18,11 @@ description = "Go 1.18 development environment"; }; + node = { + path = ./node; + description = "Node.js development environment"; + }; + rust = { path = ./rust; description = "Rust development environment"; diff --git a/node/.envrc b/node/.envrc new file mode 100644 index 0000000..a5dbbcb --- /dev/null +++ b/node/.envrc @@ -0,0 +1 @@ +use flake . diff --git a/node/flake.lock b/node/flake.lock new file mode 100644 index 0000000..26c4e97 --- /dev/null +++ b/node/flake.lock @@ -0,0 +1,42 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1656928814, + "narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1659041591, + "narHash": "sha256-kKoy3tDZl3w0GuVlvJ6W/ERGRqeXy2+IGXL9g1a3F68=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ab0794b1ae2756411d176dd5b82843a4ae56fe6e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/node/flake.nix b/node/flake.nix new file mode 100644 index 0000000..c96901f --- /dev/null +++ b/node/flake.nix @@ -0,0 +1,36 @@ +{ + description = "A Nix-flake-based Node.js development environment"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + + inherit (pkgs) mkShell; + + nodejs = pkgs.nodejs; + pnpm = pkgs.nodePackages.pnpm; + yarn = pkgs.yarn; + + in { + devShells = { + default = pkgs.mkShell { + nativeBuildInputs = [ + nodejs + pnpm + (yarn.override { inherit nodejs; }) + ]; + + shellHook = '' + echo "node `${nodejs}/bin/node --version`" + ''; + }; + }; + } + ); +}