{ description = "PDS Dashboard Flake"; inputs = { nixpkgs.url = "nixpkgs/nixpkgs-unstable"; }; outputs = { nixpkgs, ... }: let forAllSystems = function: nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ] (system: function nixpkgs.legacyPackages.${system}); in { devShells = forAllSystems (pkgs: { default = pkgs.mkShell { packages = with pkgs; [ deno ]; }; }); packages = forAllSystems (pkgs: let deps = pkgs.stdenv.mkDerivation { name = "pds-dash-deps"; src = ./.; nativeBuildInputs = [ pkgs.deno ]; buildPhase = '' export DENO_DIR=$out export DENO_NO_UPDATE_CHECK=1 deno install --frozen ''; installPhase = '' echo "Dependencies cached in $out" ''; outputHashMode = "recursive"; outputHashAlgo = "sha256"; outputHash = "sha256-SQbclPzhmcrsTHvYBoYC53zcedorb7yE5w63xGNoZpw="; }; in { default = pkgs.stdenv.mkDerivation { pname = "pds-dash"; version = "0.1.0"; src = ./.; nativeBuildInputs = [ pkgs.deno ]; configurePhase = '' runHook preConfigure if [ ! -f config.ts ]; then echo "Error: config.ts not found." exit 1 fi # Copy dependencies to a writable location export DENO_DIR="$TMPDIR/deno-cache" mkdir -p "$DENO_DIR" cp -r ${deps}/* "$DENO_DIR/" chmod -R +w "$DENO_DIR" export DENO_NO_UPDATE_CHECK=1 # Install dependencies (will use the local cache) deno install --frozen runHook postConfigure ''; buildPhase = '' runHook preBuild export DENO_DIR="$TMPDIR/deno-cache" export DENO_NO_UPDATE_CHECK=1 deno task build runHook postBuild ''; installPhase = '' runHook preInstall mkdir -p $out cp -r dist/* $out/ runHook postInstall ''; }; }); apps = forAllSystems (pkgs: { # build static files for production use default = { type = "app"; program = toString (pkgs.writeShellScript "build-pds-dash" '' set -e echo "Building pds-dash..." RESULT=$(nix build .#default --no-link --print-out-paths 2>&1 | grep -v "^warning:" | tail -1) echo "Build complete!" echo "Output is in: $RESULT" echo "To serve the built files:" echo " python3 -m http.server --directory $RESULT 8080" ''); }; # deno dev server dev = { type = "app"; program = toString (pkgs.writeShellScript "dev-pds-dash" '' set -e if [ ! -f config.ts ]; then echo "Error: config.ts not found." exit 1 fi # Setup cleanup trap to remove deno cache on exit cleanup() { echo "Cleaning up .deno-cache..." rm -rf "$PWD/.deno-cache" echo "Done!" } trap cleanup EXIT INT TERM echo "Installing dependencies..." export DENO_DIR="$PWD/.deno-cache" export DENO_NO_UPDATE_CHECK=1 ${pkgs.deno}/bin/deno install echo "Starting development server..." ${pkgs.deno}/bin/deno task dev ''); }; }); }; }