diff --git a/modules/project-common.nix b/modules/project-common.nix index 119e3cdb2..60776e4cc 100644 --- a/modules/project-common.nix +++ b/modules/project-common.nix @@ -21,7 +21,7 @@ with lib.types; shell = mkOption { type = submodule [ (import ./shell.nix { projectConfig = config; }) - { _module.args = { inherit (pkgs.haskell-nix) haskellLib; }; } + { _module.args = { inherit pkgs; inherit (pkgs.haskell-nix) haskellLib; }; } ]; default = { }; description = '' diff --git a/modules/shell.nix b/modules/shell.nix index 1eab8d137..19c4a7ebc 100644 --- a/modules/shell.nix +++ b/modules/shell.nix @@ -63,7 +63,25 @@ }; shellHook = lib.mkOption { type = lib.types.str; - default = ""; + # Shell hook to set EM_CACHE to a writable temporary directory if not already set + default = lib.optionalString pkgs.stdenv.hostPlatform.isGhcjs '' + if [ -z "$EM_CACHE" ]; then + # Create a unique temporary directory using mktemp + EM_CACHE_DIR=$(mktemp -d -t emcache-ghcjs-XXXXXX) + + # Copy the default Emscripten cache contents to the temporary directory + DEFAULT_EM_CACHE="${pkgs.pkgsBuildBuild.emscripten}/share/emscripten/cache" + if [ -d "$DEFAULT_EM_CACHE" ]; then + cp -r "$DEFAULT_EM_CACHE"/* "$EM_CACHE_DIR" 2>/dev/null || true + chmod -R u+w "$EM_CACHE_DIR" + fi + + export EM_CACHE="$EM_CACHE_DIR" + echo "Set EM_CACHE to $EM_CACHE" + else + echo "EM_CACHE already set to $EM_CACHE" + fi + ''; }; # mkDerivation args diff --git a/test/cabal.project.local b/test/cabal.project.local index 114e70a31..d42019341 100644 --- a/test/cabal.project.local +++ b/test/cabal.project.local @@ -29,7 +29,7 @@ repository head.hackage.ghc.haskell.org f76d08be13e9a61a377a85e2fb63f4c5435d40f8feb3e12eb05905edb8cdea89 26021a13b401500c8eb2761ca95c61f2d625bfef951b939a8124ed12ecf07329 7541f32a4ccca4f97aea3b22f5e593ba2c0267546016b992dfadcd2fe944e55d - --sha256: sha256-T8qW/tiaMGcxxxA4OXBQc07EYXjhYMXSXSgW0Zg3aRo= + --sha256: sha256-GDbFKWPkG3IXjgL3DEywVgnMvEMciBfMHdMjhIRFJK4= repository ghcjs-overlay url: https://raw.githubusercontent.com/input-output-hk/hackage-overlay-ghcjs/ffb32dce467b9a4d27be759fdd2740a6edd09d0b