A fork of pds-dash-fork for arabica.systems
at main 125 lines 3.7 kB view raw
1{ 2 description = "PDS Dashboard Flake"; 3 inputs = { nixpkgs.url = "nixpkgs/nixpkgs-unstable"; }; 4 outputs = { nixpkgs, ... }: 5 let 6 forAllSystems = function: 7 nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ] 8 (system: function nixpkgs.legacyPackages.${system}); 9 in { 10 devShells = forAllSystems 11 (pkgs: { default = pkgs.mkShell { packages = with pkgs; [ deno ]; }; }); 12 13 packages = forAllSystems (pkgs: 14 let 15 deps = pkgs.stdenv.mkDerivation { 16 name = "pds-dash-deps"; 17 src = ./.; 18 19 nativeBuildInputs = [ pkgs.deno ]; 20 21 buildPhase = '' 22 export DENO_DIR=$out 23 export DENO_NO_UPDATE_CHECK=1 24 deno install --frozen 25 ''; 26 27 installPhase = '' 28 echo "Dependencies cached in $out" 29 ''; 30 31 outputHashMode = "recursive"; 32 outputHashAlgo = "sha256"; 33 outputHash = "sha256-SQbclPzhmcrsTHvYBoYC53zcedorb7yE5w63xGNoZpw="; 34 }; 35 in { 36 default = pkgs.stdenv.mkDerivation { 37 pname = "pds-dash"; 38 version = "0.1.0"; 39 src = ./.; 40 41 nativeBuildInputs = [ pkgs.deno ]; 42 43 configurePhase = '' 44 runHook preConfigure 45 if [ ! -f config.ts ]; then 46 echo "Error: config.ts not found." 47 exit 1 48 fi 49 50 # Copy dependencies to a writable location 51 export DENO_DIR="$TMPDIR/deno-cache" 52 mkdir -p "$DENO_DIR" 53 cp -r ${deps}/* "$DENO_DIR/" 54 chmod -R +w "$DENO_DIR" 55 export DENO_NO_UPDATE_CHECK=1 56 # Install dependencies (will use the local cache) 57 deno install --frozen 58 runHook postConfigure 59 ''; 60 61 buildPhase = '' 62 runHook preBuild 63 export DENO_DIR="$TMPDIR/deno-cache" 64 export DENO_NO_UPDATE_CHECK=1 65 deno task build 66 runHook postBuild 67 ''; 68 69 installPhase = '' 70 runHook preInstall 71 72 mkdir -p $out 73 cp -r dist/* $out/ 74 75 runHook postInstall 76 ''; 77 }; 78 }); 79 80 apps = forAllSystems (pkgs: { 81 # build static files for production use 82 default = { 83 type = "app"; 84 program = toString (pkgs.writeShellScript "build-pds-dash" '' 85 set -e 86 echo "Building pds-dash..." 87 RESULT=$(nix build .#default --no-link --print-out-paths 2>&1 | grep -v "^warning:" | tail -1) 88 echo "Build complete!" 89 echo "Output is in: $RESULT" 90 echo "To serve the built files:" 91 echo " python3 -m http.server --directory $RESULT 8080" 92 ''); 93 }; 94 95 # deno dev server 96 dev = { 97 type = "app"; 98 program = toString (pkgs.writeShellScript "dev-pds-dash" '' 99 set -e 100 101 if [ ! -f config.ts ]; then 102 echo "Error: config.ts not found." 103 exit 1 104 fi 105 106 # Setup cleanup trap to remove deno cache on exit 107 cleanup() { 108 echo "Cleaning up .deno-cache..." 109 rm -rf "$PWD/.deno-cache" 110 echo "Done!" 111 } 112 trap cleanup EXIT INT TERM 113 114 echo "Installing dependencies..." 115 export DENO_DIR="$PWD/.deno-cache" 116 export DENO_NO_UPDATE_CHECK=1 117 ${pkgs.deno}/bin/deno install 118 119 echo "Starting development server..." 120 ${pkgs.deno}/bin/deno task dev 121 ''); 122 }; 123 }); 124 }; 125}