Skip to content

Commit b731a16

Browse files
committed
Fix macOS compatibility when scala-cli is used
1 parent 79be60b commit b731a16

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

flake.nix

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,28 @@
5858
setupScript = ''
5959
export HOME=$(mktemp -d)
6060
61+
# On macOS, the nix build user's home is /var/empty which is read-only.
62+
# The JVM resolves user.home from getpwuid(), not $HOME, so tools that
63+
# use System.getProperty("user.home") try to write to /var/empty/Library.
64+
# JAVA_TOOL_OPTIONS overrides user.home for regular JVM processes.
65+
# GraalVM native images (e.g. scala-cli) ignore JAVA_TOOL_OPTIONS, so
66+
# we override every directory env var they check to avoid the fallback
67+
# to user.home + /Library/... entirely.
68+
export JAVA_TOOL_OPTIONS="$JAVA_TOOL_OPTIONS -Duser.home=\"$HOME\""
69+
export SCALA_CLI_HOME="$HOME/.scala-cli"
70+
export COURSIER_CACHE="$HOME/.cache/coursier"
71+
export COURSIER_ARCHIVE_CACHE="$HOME/.cache/coursier-arc"
72+
export COURSIER_BIN_DIR="$HOME/.local/bin/coursier"
73+
export COURSIER_CONFIG_DIR="$HOME/.config/coursier"
74+
export COURSIER_JVM_CACHE="$HOME/.cache/coursier-jvm"
75+
6176
# Set up Coursier cache - sbt uses .cache/coursier/https/...
62-
mkdir -p $HOME/.cache
63-
cp -r ${coursierCache} $HOME/.cache/coursier
64-
chmod -R u+w $HOME/.cache/coursier
77+
mkdir -p "$HOME/.cache"
78+
cp -r ${coursierCache} "$HOME/.cache/coursier"
79+
chmod -R u+w "$HOME/.cache/coursier"
6580
6681
# Configure sbt for offline mode
6782
export COURSIER_MODE=offline
68-
export COURSIER_CACHE=$HOME/.cache/coursier
6983
export SBT_OPTS="-Dsbt.offline=true -Dsbt.boot.directory=$HOME/.sbt/boot ${extraSbtOpts}"
7084
'';
7185

0 commit comments

Comments
 (0)