|
3 | 3 |
|
4 | 4 | inputs = {
|
5 | 5 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
6 |
| - pnpm2nix = { |
7 |
| - url = "github:nzbr/pnpm2nix-nzbr"; |
8 |
| - inputs.nixpkgs.follows = "nixpkgs"; |
9 |
| - }; |
| 6 | + pnpm2nix.url = "github:nzbr/pnpm2nix-nzbr"; |
10 | 7 | };
|
11 | 8 |
|
12 | 9 | outputs = {
|
|
16 | 13 | }: let
|
17 | 14 | systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
|
18 | 15 | forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system);
|
19 |
| - |
20 |
| - # Read package.json content directly |
21 |
| - packageJson = builtins.fromJSON (builtins.readFile ./package.json); |
22 |
| - |
23 |
| - # Extract versions directly |
24 |
| - nodeVersion = builtins.replaceStrings ["^" "~"] ["" ""] packageJson.engines.node; |
25 |
| - pnpmVersion = builtins.head (builtins.match "pnpm@([0-9.]+).*" packageJson.packageManager); |
26 |
| - |
27 |
| - # Function to fetch Node.js for a specific system |
28 |
| - fetchNodejs = system: let |
29 |
| - pkgs = nixpkgs.legacyPackages.${system}; |
30 |
| - platformMap = { |
31 |
| - "x86_64-linux" = "linux-x64"; |
32 |
| - "aarch64-linux" = "linux-arm64"; |
33 |
| - "x86_64-darwin" = "darwin-x64"; |
34 |
| - "aarch64-darwin" = "darwin-arm64"; |
35 |
| - }; |
36 |
| - platform = platformMap.${system}; |
37 |
| - in |
38 |
| - pkgs.stdenv.mkDerivation { |
39 |
| - pname = "nodejs"; |
40 |
| - version = nodeVersion; |
41 |
| - |
42 |
| - src = pkgs.fetchurl { |
43 |
| - urls = [ |
44 |
| - "https://nodejs.org/dist/v${nodeVersion}/node-v${nodeVersion}-${platform}.tar.xz" |
45 |
| - "https://nodejs.org/download/release/v${nodeVersion}/node-v${nodeVersion}-${platform}.tar.xz" |
46 |
| - ]; |
47 |
| - hash = null; |
48 |
| - }; |
49 |
| - |
50 |
| - # Skip unnecessary phases |
51 |
| - dontBuild = true; |
52 |
| - dontConfigure = true; |
53 |
| - |
54 |
| - installPhase = '' |
55 |
| - mkdir -p $out |
56 |
| - cp -r * $out/ |
57 |
| - chmod +x $out/bin/* |
58 |
| - ''; |
59 |
| - |
60 |
| - # Add post-fixup phase for NixOS compatibility |
61 |
| - fixupPhase = '' |
62 |
| - patchShebangs $out/bin |
63 |
| - ''; |
64 |
| - }; |
65 |
| - |
66 |
| - # Create pkgs with overlays |
67 |
| - pkgsFor = system: let |
68 |
| - pkgs = nixpkgs.legacyPackages.${system}; |
69 |
| - nodejsCustom = pkgs.stdenv.mkDerivation { |
70 |
| - pname = "nodejs"; |
71 |
| - version = nodeVersion; |
72 |
| - |
73 |
| - src = fetchNodejs system; |
74 |
| - |
75 |
| - # Skip phases that aren't needed for pre-built binaries |
76 |
| - dontBuild = true; |
77 |
| - dontConfigure = true; |
78 |
| - dontPatchELF = true; |
79 |
| - dontPatchShebangs = true; |
80 |
| - |
81 |
| - installPhase = '' |
82 |
| - runHook preInstall |
83 |
| -
|
84 |
| - mkdir -p $out |
85 |
| - cp -R * $out/ |
86 |
| -
|
87 |
| - # Ensure bin directory exists and files are executable |
88 |
| - mkdir -p $out/bin |
89 |
| - chmod +x $out/bin/* |
90 |
| -
|
91 |
| - # Make sure node is executable |
92 |
| - chmod +x $out/bin/node |
93 |
| -
|
94 |
| - runHook postInstall |
95 |
| - ''; |
96 |
| - |
97 |
| - # Only use autoPatchelfHook on Linux systems |
98 |
| - nativeBuildInputs = with pkgs; |
99 |
| - if pkgs.stdenv.isLinux |
100 |
| - then [autoPatchelfHook] |
101 |
| - else []; |
102 |
| - |
103 |
| - # Only include C libraries on Linux |
104 |
| - buildInputs = with pkgs; |
105 |
| - if pkgs.stdenv.isLinux |
106 |
| - then [stdenv.cc.cc.lib] |
107 |
| - else []; |
108 |
| - |
109 |
| - # Add post-fixup phase to ensure executables are properly handled |
110 |
| - postFixup = '' |
111 |
| - # Ensure all executables in bin are actually executable |
112 |
| - find $out/bin -type f -exec chmod +x {} + |
113 |
| - ''; |
114 |
| - }; |
115 |
| - |
116 |
| - # Create a pnpm package directly from npm registry |
117 |
| - pnpmTarball = pkgs.fetchurl { |
118 |
| - urls = [ |
119 |
| - "https://registry.npmjs.org/pnpm/-/pnpm-${pnpmVersion}.tgz" |
120 |
| - "https://registry.npmjs.com/pnpm/-/pnpm-${pnpmVersion}.tgz" |
121 |
| - ]; |
122 |
| - curlOpts = ''-L --retry 3 --retry-delay 3''; |
123 |
| - hash = null; |
124 |
| - }; |
125 |
| - in |
126 |
| - import nixpkgs { |
| 16 | + in { |
| 17 | + devShells = forAllSystems (system: let |
| 18 | + pkgs = import nixpkgs { |
127 | 19 | inherit system;
|
128 |
| - overlays = [ |
129 |
| - (final: prev: { |
130 |
| - nodejs = nodejsCustom; |
131 |
| - pnpm = prev.stdenv.mkDerivation { |
132 |
| - pname = "pnpm"; |
133 |
| - version = pnpmVersion; |
134 |
| - |
135 |
| - src = pnpmTarball; |
136 |
| - |
137 |
| - nativeBuildInputs = with pkgs; [ |
138 |
| - nodejsCustom |
139 |
| - makeWrapper |
140 |
| - ]; |
141 |
| - |
142 |
| - installPhase = '' |
143 |
| - export HOME=$TMPDIR |
144 |
| - mkdir -p $out/bin $out/lib/node_modules/pnpm |
145 |
| - tar xf $src -C $out/lib/node_modules/pnpm --strip-components=1 |
146 |
| - makeWrapper ${nodejsCustom}/bin/node $out/bin/pnpm \ |
147 |
| - --add-flags $out/lib/node_modules/pnpm/bin/pnpm.cjs |
148 |
| - ''; |
149 |
| - }; |
150 |
| - }) |
151 |
| - ]; |
| 20 | + overlays = [pnpm2nix.overlays.default]; |
152 | 21 | };
|
153 |
| - in { |
154 |
| - packages = forAllSystems (system: { |
155 |
| - default = pnpm2nix.lib.${system}.mkPnpmPackage { |
156 |
| - src = ./.; |
157 |
| - nodejs = (pkgsFor system).nodejs; |
158 |
| - installInPlace = true; |
159 |
| - |
160 |
| - installEnv = { |
161 |
| - PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = "1"; |
162 |
| - }; |
163 |
| - |
164 |
| - script = "build"; |
165 | 22 |
|
166 |
| - extraBuildInputs = with (pkgsFor system); [ |
| 23 | + nodePackages = |
| 24 | + (import ./default.nix { |
| 25 | + inherit pkgs system; |
| 26 | + sha256 = null; |
| 27 | + }) |
| 28 | + .buildNodePackages |
| 29 | + pkgs; |
| 30 | + in { |
| 31 | + default = pkgs.mkShell { |
| 32 | + buildInputs = with pkgs; [ |
| 33 | + nodePackages.nodejs |
| 34 | + nodePackages.pnpm |
167 | 35 | python3
|
168 | 36 | pkg-config
|
169 |
| - turbo |
170 | 37 | ];
|
171 | 38 | };
|
172 | 39 | });
|
173 | 40 |
|
174 |
| - devShells = forAllSystems ( |
175 |
| - system: let |
176 |
| - pkgs = pkgsFor system; |
177 |
| - in { |
178 |
| - default = pkgs.mkShell { |
179 |
| - buildInputs = with pkgs; [ |
180 |
| - # Use our custom nodejs and pnpm versions instead of system packages |
181 |
| - nodejs # This will use the custom nodejs defined in the overlay |
182 |
| - pnpm # This will use the custom pnpm defined in the overlay |
183 |
| - python3 |
184 |
| - pkg-config |
185 |
| - |
186 |
| - # Add canvas build dependencies |
187 |
| - cairo |
188 |
| - pango |
189 |
| - libpng |
190 |
| - libjpeg |
191 |
| - giflib |
192 |
| - librsvg |
193 |
| - pixman |
194 |
| - |
195 |
| - # Build essentials |
196 |
| - gcc |
197 |
| - gnumake |
198 |
| - |
199 |
| - # Optional but helpful |
200 |
| - vips |
201 |
| - ]; |
202 |
| - |
203 |
| - shellHook = '' |
204 |
| - export PKG_CONFIG_PATH="${pkgs.cairo}/lib/pkgconfig:${pkgs.pango}/lib/pkgconfig:${pkgs.libpng}/lib/pkgconfig:$PKG_CONFIG_PATH" |
205 |
| - echo "🤖 Eliza development environment loaded 🚀" |
206 |
| - echo "------------------------------------------" |
207 |
| - echo "Using:" |
208 |
| - echo " - Node.js $(node --version)" |
209 |
| - echo " - pnpm $(pnpm --version)" |
210 |
| -
|
211 |
| - echo """ |
212 |
| - 🏗️ Quickstart Guide: |
213 |
| - ------------------------ |
214 |
| - ┌─> 1. pnpm i (Install dependencies) |
215 |
| - │ 2. pnpm build (Build project) |
216 |
| - └─ 3. pnpm clean (Clear Artifacts, for a fresh start) |
217 |
| - 4. pnpm test (Run tests) |
218 |
| -
|
219 |
| - For more commands, run: pnpm --help |
220 |
| - ------------------------ |
221 |
| - """ |
222 |
| - ''; |
223 |
| - }; |
224 |
| - } |
225 |
| - ); |
| 41 | + lib = { |
| 42 | + getPlatformString = system: platform: |
| 43 | + if platform == "nodejs" |
| 44 | + then |
| 45 | + if builtins.match ".*darwin.*" system != null |
| 46 | + then |
| 47 | + if builtins.match ".*aarch64.*" system != null |
| 48 | + then "darwin-arm64" |
| 49 | + else "darwin-x64" |
| 50 | + else if builtins.match ".*aarch64.*" system != null |
| 51 | + then "linux-arm64" |
| 52 | + else "linux-x64" |
| 53 | + else if builtins.match ".*darwin.*" system != null |
| 54 | + then |
| 55 | + if builtins.match ".*aarch64.*" system != null |
| 56 | + then "macos-arm64" |
| 57 | + else "macos-x64" |
| 58 | + else if builtins.match ".*aarch64.*" system != null |
| 59 | + then "linux-arm64" |
| 60 | + else "linux-x64"; |
| 61 | + }; |
226 | 62 | };
|
227 | 63 | }
|
0 commit comments