Skip to content

Commit 28ec6de

Browse files
committed
Set EM_CACHE if needed in dev shell for GHCJS
1 parent ebb2877 commit 28ec6de

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
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

0 commit comments

Comments
 (0)