-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6540eac
commit be753c6
Showing
2 changed files
with
108 additions
and
110 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,112 @@ | ||
{ | ||
description = "Your project description"; | ||
description = "Node.js development environment with NVM and PNPM"; | ||
|
||
inputs = { | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | ||
pnpm2nix.url = "github:nzbr/pnpm2nix-nzbr"; | ||
nixpkgs.url = "github:nixos/nixpkgs"; | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
}; | ||
|
||
outputs = { | ||
self, | ||
nixpkgs, | ||
pnpm2nix, | ||
flake-utils, | ||
}: | ||
flake-utils.lib.eachDefaultSystem ( | ||
system: let | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
pnpm2nix-lib = pnpm2nix.packages.${system}; | ||
in { | ||
packages.default = pnpm2nix-lib.mkPnpmPackage { | ||
src = ./.; | ||
|
||
# Install dependencies in source directory for workspace support | ||
installInPlace = true; | ||
|
||
# Run recursive build across all workspace packages | ||
script = "-r build"; | ||
|
||
# Copy all build outputs | ||
distDir = "."; | ||
|
||
buildPhase = '' | ||
export HOME=$(mktemp -d) | ||
pnpm install --frozen-lockfile | ||
pnpm -r build | ||
''; | ||
|
||
installPhase = '' | ||
mkdir -p $out | ||
cp -r . $out/ | ||
''; | ||
}; | ||
|
||
devShells.default = pkgs.mkShell { | ||
packages = with pkgs; [ | ||
nodePackages.pnpm | ||
cairo | ||
pango | ||
libpng | ||
]; | ||
|
||
shellHook = '' | ||
export PATH="$PWD/node_modules/.bin:$PATH" | ||
export PKG_CONFIG_PATH="${pkgs.cairo}/lib/pkgconfig:${pkgs.pango}/lib/pkgconfig:${pkgs.libpng}/lib/pkgconfig:$PKG_CONFIG_PATH" | ||
echo "π€ Eliza development environment loaded π" | ||
echo "------------------------------------------" | ||
echo "Using:" | ||
echo " - Node.js $(node --version)" | ||
echo " - pnpm $(pnpm --version)" | ||
echo """ | ||
ποΈ Quickstart Guide: | ||
------------------------ | ||
ββ> 1. pnpm i (Install dependencies) | ||
β 2. pnpm build (Build project) | ||
ββ 3. pnpm clean (Clear Artifacts, for a fresh start) | ||
4. pnpm test (Run tests) | ||
For more commands, run: pnpm --help | ||
------------------------ | ||
""" | ||
''; | ||
}; | ||
} | ||
); | ||
flake-utils.lib.eachDefaultSystem (system: let | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
fallbackNodeVersion = "23.3.0"; | ||
fallbackPnpmVersion = "9.14.4"; | ||
|
||
# Read and parse package.json | ||
packageJson = let | ||
path = ./package.json; | ||
in | ||
if builtins.pathExists path | ||
then builtins.fromJSON (builtins.readFile path) | ||
else { | ||
engines = {node = fallbackNodeVersion;}; | ||
packageManager = "pnpm@${fallbackPnpmVersion}"; | ||
}; # Default if no package.json | ||
|
||
# Extract Node.js version from engines field | ||
nodeVersion = let | ||
engineVersion = packageJson.engines.node or fallbackNodeVersion; | ||
cleanVersion = builtins.replaceStrings ["^" ">" "=" "~" " "] ["" "" "" "" ""] engineVersion; | ||
in | ||
cleanVersion; | ||
|
||
# Extract PNPM version from packageManager field | ||
# Handles format: "[email protected]+sha512..." or "[email protected]" | ||
pnpmVersion = let | ||
packageManager = packageJson.packageManager or "pnpm@${fallbackPnpmVersion}"; | ||
# First split on '+' to remove SHA, then extract version | ||
withoutSha = builtins.head (builtins.split "[+]" packageManager); | ||
versionMatch = builtins.match "pnpm@([0-9]+[.][0-9]+[.][0-9]+).*" withoutSha; | ||
in | ||
if versionMatch == null | ||
then fallbackPnpmVersion | ||
else builtins.head versionMatch; | ||
in { | ||
devShell = pkgs.mkShell { | ||
buildInputs = with pkgs; [ | ||
curl | ||
git | ||
]; | ||
|
||
shellHook = '' | ||
# Install nvm if it's not already installed | ||
export NVM_DIR="$HOME/.nvm" | ||
if [ ! -d "$NVM_DIR" ]; then | ||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash | ||
fi | ||
# Load nvm | ||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | ||
# Install and use the specified version if not already installed | ||
if ! nvm ls ${nodeVersion} >/dev/null 2>&1; then | ||
nvm install ${nodeVersion} | ||
fi | ||
nvm use ${nodeVersion} | ||
# Enable and configure corepack for PNPM | ||
corepack enable | ||
corepack prepare pnpm@${pnpmVersion} --activate | ||
# Setup PNPM environment | ||
export PNPM_HOME="$HOME/.local/share/pnpm" | ||
export PATH="$PNPM_HOME:$PATH" | ||
# Get clean versions for comparison | ||
NODE_ACTUAL=$(node --version | sed 's/^v//') | ||
PNPM_ACTUAL=$(pnpm --version) | ||
echo "π€ Development environment loaded π" | ||
echo "------------------------------------------" | ||
echo "package.json version(s) = environment:" | ||
if [ "$NODE_ACTUAL" = "${nodeVersion}" ]; then | ||
echo "β Node.js (v${nodeVersion})" | ||
else | ||
echo "β Node.js (v${nodeVersion} != v$NODE_ACTUAL)" | ||
fi | ||
if [ "$PNPM_ACTUAL" = "${pnpmVersion}" ]; then | ||
echo "β PNPM (v${pnpmVersion})" | ||
else | ||
echo "β PNPM (v${pnpmVersion} != v$PNPM_ACTUAL)" | ||
fi | ||
echo """ | ||
ποΈ Quickstart Guide: | ||
-------------------- | ||
ββ> 1. pnpm i (Install dependencies) | ||
β 2. pnpm build (Build project) | ||
ββ 3. pnpm clean (Clear Artifacts, for a fresh start) | ||
4. pnpm test (Run tests) | ||
For more commands, run: pnpm --help | ||
""" | ||
''; | ||
}; | ||
}); | ||
} |