Skip to content

Commit

Permalink
[mill-flows] simplify setup process
Browse files Browse the repository at this point in the history
  • Loading branch information
Avimitin committed Jan 26, 2025
1 parent 4699928 commit 2dee8ac
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 96 deletions.
81 changes: 35 additions & 46 deletions overlays/mill-flows/fetch-mill-deps.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,62 +15,51 @@
}@args:

let
self = stdenvNoCC.mkDerivation (lib.recursiveUpdate
{
name = "${name}-mill-deps";
inherit src;
buildAttr = {
name = "${name}-mill-deps";
inherit src;

nativeBuildInputs = [
mill
configure-mill-home-hook
] ++ (args.nativeBuildInputs or [ ]);
propagatedBuildInputs = [
mill
configure-mill-home-hook
lndir
] ++ (args.propagatedBuildInputs or [ ]);

impureEnvVars = [ "JAVA_OPTS" ];
impureEnvVars = [ "JAVA_OPTS" ];

buildPhase = ''
runHook preBuild
buildPhase = ''
runHook preBuild
# Use "https://repo1.maven.org/maven2/" only to keep dependencies integrity
export COURSIER_REPOSITORIES="ivy2local|central"
# Use "https://repo1.maven.org/maven2/" only to keep dependencies integrity
export COURSIER_REPOSITORIES="ivy2local|central"
mill -i __.prepareOffline
mill -i __.scalaCompilerClasspath
mill -i __.prepareOffline
mill -i __.scalaCompilerClasspath
runHook postBuild
'';
runHook postBuild
'';

installPhase = ''
runHook preInstall
installPhase = ''
runHook preInstall
mkdir -p $out/.cache
mv "$NIX_MILL_HOME"/.cache/coursier $out/.cache/coursier
mkdir -p $out/.cache
mv "$NIX_MILL_HOME"/.cache/coursier $out/.cache/coursier
runHook postInstall
'';
mkdir -p $out/nix-support
cp ${./setup-mill-deps.sh} $out/nix-support/setup-hook
recordPropagatedDependencies
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = millDepsHash;
runHook postInstall
'';

dontShrink = true;
dontPatchELF = true;
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = millDepsHash;

passthru.setupHook = makeSetupHook
{
name = "mill-setup-hook.sh";
propagatedBuildInputs = [ mill configure-mill-home-hook ];
}
(writeText "mill-setup-hook" ''
setupMillCache() {
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+=(setupMillCache)
'');
}
(builtins.removeAttrs args [ "name" "src" "millDepsHash" "nativeBuildInputs" ]));
dontShrink = true;
dontPatchELF = true;
};
in
self
stdenvNoCC.mkDerivation
(lib.recursiveUpdate buildAttr
(builtins.removeAttrs args [ "name" "src" "millDepsHash" "propagatedBuildInputs" ]))
8 changes: 8 additions & 0 deletions overlays/mill-flows/install-ivy-repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
setupIvyLocalRepo() {
mkdir -p "$NIX_MILL_HOME/.ivy2/local"
lndir ../../.ivy2/local "$NIX_MILL_HOME/.ivy2/local"

echo "Copied ivy repo to $NIX_MILL_HOME"
}

postUnpackHooks+=(setupIvyLocalRepo)
75 changes: 32 additions & 43 deletions overlays/mill-flows/publish-mill-jar.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,46 @@
{ name, src, publishTargets, ... }@args:

let
self = stdenvNoCC.mkDerivation (lib.recursiveUpdate
{
name = "${name}-mill-local-ivy";
inherit src;
buildAttr = {
name = "${name}-mill-local-ivy";
inherit src;

nativeBuildInputs = [
mill
configure-mill-home-hook
] ++ (args.nativeBuildInputs or [ ]);
propagatedBuildInputs = [
mill
configure-mill-home-hook
lndir
] ++ (args.propagatedBuildInputs or [ ]);

publishTargets = lib.escapeShellArgs publishTargets;
publishTargets = lib.escapeShellArgs publishTargets;

buildPhase = ''
runHook preBuild
buildPhase = ''
runHook preBuild
publishTargetsArray=( "$publishTargets" )
for target in "''${publishTargetsArray[@]}"; do
mill -i "$target.publishLocal"
done
publishTargetsArray=( "$publishTargets" )
for target in "''${publishTargetsArray[@]}"; do
mill -i "$target.publishLocal"
done
runHook postBuild
'';
runHook postBuild
'';

installPhase = ''
runHook preInstall
installPhase = ''
runHook preInstall
mkdir -p $out/.ivy2
mv $NIX_MILL_HOME/.ivy2/local $out/.ivy2/
mkdir -p $out/.ivy2
mv $NIX_MILL_HOME/.ivy2/local $out/.ivy2/
runHook postInstall
'';
mkdir -p "$out"/nix-support
cp ${./install-ivy-repo.sh} "$out"/nix-support/setup-hook
recordPropagatedDependencies
dontShrink = true;
dontPatchELF = true;
runHook postInstall
'';

passthru.setupHook = makeSetupHook
{
name = "mill-local-ivy-setup-hook.sh";
propagatedBuildInputs = [ mill configure-mill-home-hook ];
}
(writeText "mill-setup-hook" ''
setupIvyLocalRepo() {
mkdir -p "$NIX_MILL_HOME/.ivy2/local"
${lndir}/bin/lndir "${self}/.ivy2/local" "$NIX_MILL_HOME/.ivy2/local"
echo "Copy ivy repo to $NIX_MILL_HOME"
}
postUnpackHooks+=(setupIvyLocalRepo)
'');
}
(builtins.removeAttrs args [ "name" "src" "nativeBuildInputs" ]));
dontShrink = true;
dontPatchELF = true;
};
in
self
stdenvNoCC.mkDerivation
(lib.recursiveUpdate buildAttr
(builtins.removeAttrs args [ "name" "src" "propagatedBuildInputs" ]))
8 changes: 8 additions & 0 deletions overlays/mill-flows/setup-mill-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
setupMillCache() {
mkdir -p "$NIX_MILL_HOME/.cache/coursier"
lndir ../../.cache/coursier "$NIX_MILL_HOME"/.cache/coursier

echo "Copied mill deps into $NIX_MILL_HOME"
}

postUnpackHooks+=(setupMillCache)
6 changes: 0 additions & 6 deletions overlays/mill-flowss.nix

This file was deleted.

2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ publishMillJar {
];
buildInputs = [
chiselDeps.setupHook
chiselDeps
];
nativeBuildInputs = [
Expand Down

0 comments on commit 2dee8ac

Please sign in to comment.