{ description = "Spazer - Web Graphics Project"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; }; outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; config = { permittedInsecurePackages = [ "nodejs-16.20.2" ]; }; }; in { packages.default = pkgs.mkYarnPackage { name = "spazer"; src = ./.; packageJSON = ./package.json; yarnLock = ./yarn.lock; buildPhase = '' echo "Current directory structure:" ls -la echo "Node modules location:" ls -la node_modules/.bin || true export HOME=$(mktemp -d) export NODE_ENV=production # Move to the package directory where the source is cd deps/Spazer # Ensure Parcel cache directory exists and is writable mkdir -p .parcel-cache chmod -R 755 .parcel-cache # Add node_modules/.bin to PATH so parcel can be found export PATH="$PATH:$(pwd)/../../node_modules/.bin" # Run the build with explicit entry point for all HTML files yarn parcel build src/index.html src/**/index.html --no-cache --public-url ./ # Move back to the root directory cd ../.. ''; installPhase = '' echo "Current directory for install phase:" pwd echo "Directory contents:" ls -la deps/Spazer mkdir -p $out/dist if [ -d deps/Spazer/dist ]; then cp -r deps/Spazer/dist/* $out/dist else echo "Error: dist directory not found after build" echo "Current directory: $(pwd)" echo "Contents of deps/Spazer:" ls -la deps/Spazer exit 1 fi ''; distPhase = "true"; buildInputs = with pkgs; [ nodejs ]; nativeBuildInputs = with pkgs; [ yarn python3 # Sometimes needed by node-gyp ]; # Prevent yarn from trying to download during the build yarnPreBuild = '' mkdir -p $HOME/.cache/yarn mkdir -p $HOME/.config/yarn chmod -R 755 $HOME/.cache chmod -R 755 $HOME/.config ''; # Don't attempt to do any post-build optimizations dontFixup = true; }; # Development shell with required dependencies devShell = pkgs.mkShell { buildInputs = with pkgs; [ nodejs yarn python3 ]; }; # Add a simple app that can serve the built files apps.default = flake-utils.lib.mkApp { drv = pkgs.writeShellScriptBin "serve-spazer" '' ${pkgs.python3}/bin/python3 -m http.server --directory ${self.packages.${system}.default}/dist 8080 ''; }; }); }