-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch-mill-deps.nix
96 lines (81 loc) · 2.11 KB
/
fetch-mill-deps.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
{
stdenvNoCC,
mill,
writeText,
makeSetupHook,
runCommand,
lib,
configure-mill-home-hook,
lndir,
}:
{
name,
src,
millDepsHash,
fetchTargets ? [ "__" ], # "__" means resolve all targets ivy deps
...
}@args:
let
self = stdenvNoCC.mkDerivation (
lib.recursiveUpdate
{
name = "${name}-mill-deps";
inherit src;
nativeBuildInputs = [
mill
configure-mill-home-hook
] ++ (args.nativeBuildInputs or [ ]);
impureEnvVars = [ "JAVA_OPTS" ];
buildPhase =
''
runHook preBuild
# Use "https://repo1.maven.org/maven2/" only to keep dependencies integrity
export COURSIER_REPOSITORIES="ivy2local|central"
''
+ (lib.concatMapStrings (x: "mill -i '${x}'.prepareOffline\n") fetchTargets)
+ ''
mill -i __.scalaCompilerClasspath
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/.cache
mv "$NIX_MILL_HOME"/.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
configure-mill-home-hook
];
}
(
writeText "mill-setup-hook" ''
setup${name}MillCache() {
mkdir -p "$NIX_MILL_HOME/.cache/coursier"
${lndir}/bin/lndir "${self}"/.cache/coursier "$NIX_MILL_HOME"/.cache/coursier
echo "Copied mill deps into $NIX_MILL_HOME"
}
postUnpackHooks+=(setup${name}MillCache)
''
);
}
(
builtins.removeAttrs args [
"name"
"src"
"millDepsHash"
"nativeBuildInputs"
]
)
);
in
self