Mill always lazily evaluate Ivy dependencies, so it is not possible to get a lock file before starting Mill to actually compile a project. However the needs for a elaborate information of each dependency is fundamental to make a project reproducible. This project are some efforts to split a bunch Ivy dependencies into small pieces.
- mill 1.1.0
- Get help information
mill -i mif.run --help- Prepare offline dependencies
cacheDir=$(mktemp -d)
mill -i mif.run fetch --project-dir <project> -c "$cacheDir"- Generate Nix expression for runtime and compile dependencies
# point to same cache dir
mill -i mif.run codegen --cache "$cacheDir" -o lock.nix- Don't care anything and just wanna generate a lock for current project
mill -i mif.run run -o lock.nixMill doesn't provide any straightforward CLI interface to get Ivy dependencies
tree. The only way to know all the necessary build time dependencies is to run
mill __.prepareOffline once. Given that Mill use Coursier library to download
JAR package, we can gather dependency information by searching Coursier cache
directory.
This project provides executable mif. It will
recursively search all .pom file in Coursier cache and extract necessary
information like project name, version...etc and convert those information to
maven central download URL. Then convert that URL to a nix fetchurl expression.
- Add this project in your overlay
# flake.nix
{
description = "flake.nix";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
mill-ivy-fetcher.url = "github:Avimitin/mill-ivy-fetcher";
};
outputs = { self, nixpkgs, flake-utils, mill-ivy-fetcher }@inputs:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs { inherit system; overlays = [ mill-ivy-fetcher.overlays.default mill-ivy-fetcher.overlays.mill-overlay ]; };
in
{
legacyPackages = pkgs;
devShells = {
default = pkgs.mkShell {
buildInputs = with pkgs; [
ammonite
mill
mill-ivy-fetcher
];
};
};
formatter = pkgs.nixpkgs-fmt;
}
)
// { inherit inputs; };
}- Use the provided
mifexecutable to generate lock file for a project:
nix shell '.#mill' '.#mill-ivy-fetcher' -c mif run -p path/to/project -o project-lock.nix- Add the lock file to
publishMillJar(optional)
{ publishMillJar }:
publishMillJar {
name = "chisel";
src = ./.;
lockFile = ./project-lock.nix;
publishTargets = [
"foo"
];
}- Or if you want to build an application, try
{ stdenv, ivy-gather }:
let
ivyCache = ivy-gather ./project-lock.nix;
in
stdenv.mkDerivation {
#...
buildInputs = [ ivyCache ];
# ...
}- See
./.github/integration/chisel.nixfor a detailed explanation. - See
./nix/mill-ivy-fetcher-overlay.nixfor a function documents.
- Install Nix package manager (Nix is not NixOS): https://nixos.org/download/
- Enable experimental features
nix-commandandflakes: https://wiki.nixos.org/wiki/Flakes
nix develop .
$EDITOR .You can set NIX_DEBUG larger than 4 to have cache installation log:
publishMillJar {
# ...
env.NIX_DEBUG = 4;
# ...
}
./bump.sh