Created
April 30, 2025 05:56
-
-
Save katrinafyi/b4691914d5e26727bdd3790d3827d9ea to your computer and use it in GitHub Desktop.
Building a Mill derivation with Nix, using sbt-derivation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/mill-derivation/lib/dependencies.nix b/mill-derivation/lib/dependencies.nix | |
index 422dacb..346ecea 100644 | |
--- a/mill-derivation/lib/dependencies.nix | |
+++ b/mill-derivation/lib/dependencies.nix | |
@@ -6,7 +6,9 @@ | |
gnused, | |
lib, | |
rdfind, | |
- sbt, | |
+ mill, | |
+ curl, | |
+ cacert, | |
stdenv, | |
strip-nondeterminism, | |
symlinks, | |
@@ -31,7 +33,7 @@ | |
name = namePrefix + archivalStrategy.fileExtension; | |
nativeBuildInputs = | |
- [sbt gnused strip-nondeterminism file findutils] | |
+ [mill curl cacert gnused strip-nondeterminism file findutils] | |
++ nativeBuildInputs | |
++ archivalStrategy.nativeBuildInputs; | |
diff --git a/mill-derivation/lib/sbt-derivation.nix b/mill-derivation/lib/sbt-derivation.nix | |
index ca4d082..c46cbb1 100644 | |
--- a/mill-derivation/lib/sbt-derivation.nix | |
+++ b/mill-derivation/lib/sbt-derivation.nix | |
@@ -2,7 +2,7 @@ | |
lib, | |
stdenv, | |
callPackage, | |
- sbt, | |
+ mill, | |
}: { | |
pname, | |
version, | |
@@ -18,7 +18,7 @@ | |
depsSha256, | |
# | |
# Command to run to let sbt fetch all the required dependencies for the build. | |
- depsWarmupCommand ? "sbt compile", | |
+ depsWarmupCommand ? "mill compile", | |
# | |
# Strategy to use to package and unpackage the dependencies | |
# - copy: regular directory, copy before build | |
@@ -41,6 +41,16 @@ | |
# this convenient for testing. | |
sbtEnvSetupCmds = '' | |
export SBT_DEPS=$(mktemp -d) | |
+ | |
+ if [[ -x ./mill ]]; then | |
+ patchShebangs ./mill | |
+ fi | |
+ | |
+ export XDG_CACHE_HOME=$SBT_DEPS/project/.cache | |
+ | |
+ echo "" >> .mill-jvm-opts | |
+ echo "-Divy.home=$SBT_DEPS/project/.ivy" >> .mill-jvm-opts | |
+ | |
export SBT_OPTS="-Dsbt.global.base=$SBT_DEPS/project/.sbtboot -Dsbt.boot.directory=$SBT_DEPS/project/.boot -Dsbt.ivy.home=$SBT_DEPS/project/.ivy $SBT_OPTS" | |
export COURSIER_CACHE=$SBT_DEPS/project/.coursier | |
mkdir -p $SBT_DEPS/project/{.sbtboot,.boot,.ivy,.coursier} | |
@@ -59,7 +69,7 @@ | |
in | |
stdenv.mkDerivation (drvAttrs | |
// { | |
- nativeBuildInputs = [sbt] ++ nativeBuildInputs; | |
+ nativeBuildInputs = [mill] ++ nativeBuildInputs; | |
passthru = | |
passthru | |
diff --git a/mill-derivation/overlay.nix b/mill-derivation/overlay.nix | |
index 4138774..ac01328 100644 | |
--- a/mill-derivation/overlay.nix | |
+++ b/mill-derivation/overlay.nix | |
@@ -1,11 +1,3 @@ | |
final: prev: { | |
- mkSbtDerivation = import ./lib/bootstrap.nix final; | |
- | |
- sbt = prev.sbt.overrideAttrs (old: { | |
- passthru = | |
- (old.passthru or {}) | |
- // { | |
- mkDerivation = args: prev.lib.warn "sbt.mkDerivation is deprecated. Use mkSbtDerivation instead." (final.mkSbtDerivation args); | |
- }; | |
- }); | |
+ mkMillDerivation = import ./lib/bootstrap.nix final; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment