Skip to content

Commit f7bea98

Browse files
authored
Set EM_CACHE if needed in dev shell for GHCJS (#2397)
* Set EM_CACHE if needed in dev shell for GHCJS * Update head.hackage
1 parent ebb2877 commit f7bea98

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

modules/project-common.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ with lib.types;
2121
shell = mkOption {
2222
type = submodule [
2323
(import ./shell.nix { projectConfig = config; })
24-
{ _module.args = { inherit (pkgs.haskell-nix) haskellLib; }; }
24+
{ _module.args = { inherit pkgs; inherit (pkgs.haskell-nix) haskellLib; }; }
2525
];
2626
default = { };
2727
description = ''

modules/shell.nix

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,25 @@
6363
};
6464
shellHook = lib.mkOption {
6565
type = lib.types.str;
66-
default = "";
66+
# Shell hook to set EM_CACHE to a writable temporary directory if not already set
67+
default = lib.optionalString pkgs.stdenv.hostPlatform.isGhcjs ''
68+
if [ -z "$EM_CACHE" ]; then
69+
# Create a unique temporary directory using mktemp
70+
EM_CACHE_DIR=$(mktemp -d -t emcache-ghcjs-XXXXXX)
71+
72+
# Copy the default Emscripten cache contents to the temporary directory
73+
DEFAULT_EM_CACHE="${pkgs.pkgsBuildBuild.emscripten}/share/emscripten/cache"
74+
if [ -d "$DEFAULT_EM_CACHE" ]; then
75+
cp -r "$DEFAULT_EM_CACHE"/* "$EM_CACHE_DIR" 2>/dev/null || true
76+
chmod -R u+w "$EM_CACHE_DIR"
77+
fi
78+
79+
export EM_CACHE="$EM_CACHE_DIR"
80+
echo "Set EM_CACHE to $EM_CACHE"
81+
else
82+
echo "EM_CACHE already set to $EM_CACHE"
83+
fi
84+
'';
6785
};
6886

6987
# mkDerivation args

test/cabal.project.local

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ repository head.hackage.ghc.haskell.org
2929
f76d08be13e9a61a377a85e2fb63f4c5435d40f8feb3e12eb05905edb8cdea89
3030
26021a13b401500c8eb2761ca95c61f2d625bfef951b939a8124ed12ecf07329
3131
7541f32a4ccca4f97aea3b22f5e593ba2c0267546016b992dfadcd2fe944e55d
32-
--sha256: sha256-T8qW/tiaMGcxxxA4OXBQc07EYXjhYMXSXSgW0Zg3aRo=
32+
--sha256: sha256-GDbFKWPkG3IXjgL3DEywVgnMvEMciBfMHdMjhIRFJK4=
3333

3434
repository ghcjs-overlay
3535
url: https://raw.githubusercontent.com/input-output-hk/hackage-overlay-ghcjs/ffb32dce467b9a4d27be759fdd2740a6edd09d0b

0 commit comments

Comments
 (0)