Skip to content
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

[mill-flows] simplify setup process #63

Closed
wants to merge 1 commit into from
Closed
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
84 changes: 39 additions & 45 deletions overlays/mill-flows/fetch-mill-deps.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,62 +15,56 @@
}@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;
postFixup = ''
cat "$out"/nix-support/setup-hook
cat "$out"/nix-support/propagated-build-inputs
'';

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
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = millDepsHash;

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 $out/.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 $out/.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