-
Notifications
You must be signed in to change notification settings - Fork 1
/
mill-builder.nix
68 lines (52 loc) · 1.77 KB
/
mill-builder.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2024 Jiuyang Liu <liu@jiuyang.me>
{ stdenvNoCC, mill, writeText, makeSetupHook, runCommand, lib }:
{ name, src, millDepsHash, ... }@args:
let
mill-rt-version = lib.head (lib.splitString "+" mill.jre.version);
self = stdenvNoCC.mkDerivation ({
name = "${name}-mill-deps";
inherit src;
nativeBuildInputs = [
mill
] ++ (args.nativeBuildInputs or [ ]);
impureEnvVars = [ "JAVA_OPTS" ];
buildPhase = ''
runHook preBuild
export JAVA_OPTS="-Duser.home=$TMPDIR $JAVA_OPTS"
# Use "https://repo1.maven.org/maven2/" only to keep dependencies integrity
export COURSIER_REPOSITORIES="central"
mill -i __.prepareOffline
mill -i __.scalaCompilerClasspath
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/.cache
mv $TMPDIR/.cache/coursier $out/.cache/coursier
runHook postInstall
'';
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = millDepsHash;
dontShrink = true;
dontPatchELF = true;
passthru.setupHook = makeSetupHook
{
name = "mill-setup-hook.sh";
propagatedBuildInputs = [ mill ];
}
(writeText "mill-setup-hook" ''
setupMillCache() {
local tmpdir=$(mktemp -d)
export JAVA_OPTS="$JAVA_OPTS -Duser.home=$tmpdir"
mkdir -p "$tmpdir"/.cache "$tmpdir/.mill/ammonite"
cp -r "${self}"/.cache/coursier "$tmpdir"/.cache/
touch "$tmpdir/.mill/ammonite/rt-${mill-rt-version}.jar"
echo "JAVA HOME dir set to $tmpdir"
}
postUnpackHooks+=(setupMillCache)
'');
} // (builtins.removeAttrs args [ "name" "src" "millDepsHash" "nativeBuildInputs" ]));
in
self