Skip to content

Set EM_CACHE if needed in dev shell for GHCJS #2397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/project-common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand Down
20 changes: 19 additions & 1 deletion modules/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/cabal.project.local
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading