Replies: 3 comments 11 replies
-
You can prepare your build with |
Beta Was this translation helpful? Give feedback.
-
That looks like mill will fetch stuff into the out folder. I would be more interested in understanding what I have to fetch from where myself and where to put it so that mill will find it. Or is this kind of info not exposed? Otherwise I would have to execute the |
Beta Was this translation helpful? Give feedback.
-
In case it helps anyone, I managed to make this work by caching manually some deps using coursier (for a Scala 3 project):
Using Here is a full Nix Flake example including dev env and packaging of backend and frontend webapp: {
description = "myapp";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }:
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
millWithJdk11 = pkgs.mill.override { jre = pkgs.jdk11; };
depsDir = ".cache";
millDeps = pkgs.stdenv.mkDerivation {
name = "coursier-cache";
nativeBuildInputs = [ millWithJdk11 pkgs.coursier ];
outputHash = "sha256-bhMch0UyqHegXQEfgguGr50z/5QobnNWX5/tGdYeaCk=";
outputHashAlgo = "sha256";
outputHashMode = "recursive";
COURSIER_CACHE = "${depsDir}/coursier";
src = ./.;
buildPhase = ''
runHook preBuild
mill __.prepareOffline
mill show webapp.scalaJSToolsClasspath
cs fetch org.scalameta:scalafmt-core_2.13:3.0.0
cs fetch org.scala-lang:scala-reflect:2.13.8
cs fetch com.github.liancheng:organize-imports_2.12:0.6.0
cs fetch org.scala-lang:scala3-compiler_3:3.1.3
cs fetch org.scala-lang:scala3-sbt-bridge:3.1.3
cs fetch com.lihaoyi:mill-scalalib_2.13:0.10.5
cs fetch org.scala-js:scalajs-test-bridge_2.13:1.10.1
cs fetch org.scala-js:scalajs-library_2.13:1.7.1
echo "stripping out comments containing dates"
find ${depsDir} -name '*.properties' -type f -exec sed -i '/^#/d' {} \;
echo "removing non-reproducible accessory files"
find ${depsDir} -name '*.lock' -type f -print0 | xargs -r0 rm -rfv
find ${depsDir} -name '*.log' -type f -print0 | xargs -r0 rm -rfv
# echo "removing runtime jar"
# find ${depsDir} -name rt.jar -delete
echo "removing empty directories"
find ${depsDir} -type d -empty -delete
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r ${depsDir}/coursier $out
runHook postInstall
'';
};
yarnDeps = pkgs.fetchYarnDeps {
yarnLock = ./yarn.lock;
sha256 = "sha256-uL3e44tIkeEOWgWczBqRFUroz39CWDfdQfrepVDhie8=";
};
in
{
devShells.x86_64-linux.default = pkgs.mkShell {
buildInputs = with pkgs; [
nodejs
yarn
millWithJdk11
curl
cacert
postgresql
];
shellHook = ''
set -a
JAVA_HOME=${pkgs.jdk11}
set +a
'';
};
packages.x86_64-linux.default = self.packages.x86_64-linux.myapp;
packages.x86_64-linux.myapp = pkgs.stdenv.mkDerivation {
pname = "myapp";
version = "0.0.1";
nativeBuildInputs = with pkgs; [
nodejs
yarn
millWithJdk11
];
COURSIER_CACHE = "${depsDir}/coursier";
postConfigure = ''
mkdir -p ${depsDir}
cp -r ${millDeps}/coursier ${depsDir}
chmod -R +rwX ${depsDir}
'';
src = ./.;
buildPhase = ''
# Yarn writes temporary files to $HOME.
export HOME=$NIX_BUILD_TOP/yarn_home
# Make yarn install packages from our offline cache, not the registry
yarn config --offline set yarn-offline-mirror ${yarnDeps}
# Fixup "resolved"-entries in yarn.lock to match our offline cache
${pkgs.fixup_yarn_lock}/bin/fixup_yarn_lock yarn.lock
yarn install --offline --frozen-lockfile --ignore-scripts --no-progress --non-interactive
patchShebangs node_modules
mill mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll __.sources
mill __.fix --check
mill all all _.test backend.assembly webapp.fullLinkJS
yarn build:prod --offline
'';
installPhase = ''
runHook preInstall
mkdir -p $out
cp out/backend/assembly.dest/out.jar $out/backend.jar
cp -r dist $out/webapp
runHook postInstall
'';
};
}
;
} Credit due to sbt-derivation for understanding how to prefetch the build dependencies. |
Beta Was this translation helpful? Give feedback.
-
I am using NixOS and the Nix package manager. They enforce deterministic builds by building packages in a sandbox without internet connection.
Is it possible to use mill in an environment without internet? If I can figure out what needs to be downloaded and where to beforehand I can tell the package manager to fetch stuff outside of the sandbox. The nix package manager just wants to track all inputs for the build itself.
Beta Was this translation helpful? Give feedback.
All reactions