Skip to content

Commit

Permalink
fix flake
Browse files Browse the repository at this point in the history
  • Loading branch information
lessuselesss committed Dec 20, 2024
1 parent 6540eac commit be753c6
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 110 deletions.
52 changes: 8 additions & 44 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

166 changes: 100 additions & 66 deletions flake.nix
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
"""
'';
};
});
}

0 comments on commit be753c6

Please sign in to comment.