Skip to content

Scriptlets to convert mill ivy dependencies to Nix expression

Notifications You must be signed in to change notification settings

Avimitin/mill-ivy-fetcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

194 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mill Ivy Fetcher

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.

Requirements

  • mill 1.1.0

Usage

  • 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.nix

Implementation Details

Mill 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.

Recommended Workflow

  1. 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; };
}
  1. Use the provided mif executable to generate lock file for a project:
nix shell '.#mill' '.#mill-ivy-fetcher' -c mif run -p path/to/project -o project-lock.nix
  1. Add the lock file to publishMillJar (optional)
{ publishMillJar }:
publishMillJar {
  name = "chisel";

  src = ./.;

  lockFile = ./project-lock.nix;

  publishTargets = [
    "foo"
  ];
}
  1. Or if you want to build an application, try
{ stdenv, ivy-gather }:
let
  ivyCache = ivy-gather ./project-lock.nix;
in
stdenv.mkDerivation {
  #...
  buildInputs = [ ivyCache ];
  # ...
}

Dev env setup

  1. Install Nix package manager (Nix is not NixOS): https://nixos.org/download/
  2. Enable experimental features nix-command and flakes: https://wiki.nixos.org/wiki/Flakes
nix develop .
$EDITOR .

Debug installation

You can set NIX_DEBUG larger than 4 to have cache installation log:

publishMillJar {
  # ...
  env.NIX_DEBUG = 4;
  # ...
}

Bump Dependency for Mif

./bump.sh

About

Scriptlets to convert mill ivy dependencies to Nix expression

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •