Open Source Docs

Sbtix

Reproducible Nix builds for sbt projects

Commands & Regeneration

sbtix-gen, sbtix-gen-all2, and lockfile maintenance


Sbtix commands

  • sbtix - loads the sbtix global plugin and launches sbt. Sets sbt.global.base directory to $HOME/.sbtix.

  • sbtix-gen - generates repo.nix lockfiles (including nested project/**/repo.nix layers as needed). Internally runs: sbtix genNix.

  • sbtix-gen-all - kept for backwards compatibility. Internally runs: sbtix genNix.

  • sbtix-gen-all2 - generates repo.nix lockfiles (including nested project/**/repo.nix layers) and runs genComposition to render sbtix-generated.nix. Internally runs: sbtix genComposition.

By default, sbtix keeps verbose resolver diagnostics off for performance. To enable the full [SBTIX_DEBUG] output, set SBTIX_DEBUG=1 (or pass -Dsbtix.debug=true).

By default, generated locks include main artifacts plus the tests and sources classifier artifacts, and skip javadoc jars to avoid extra downloads. To include javadocs, add this to your sbt build:

sbtixArtifactClassifiers += "javadoc"

Set sbtixArtifactClassifiers := Seq.empty if you only want main artifacts.

Typical regeneration flow

Choose the regeneration flow that matches your Nix build entry point:

  1. Flake-native helper builds: run sbtix-gen to regenerate every repo.nix layer (repo.nix, project/repo.nix, project/project/repo.nix). Commit those lockfiles so CI and teammates get the same dependencies. This is the usual flow when your flake imports ${sbtix}/plugin/nix-exprs/sbtix.nix and calls buildSbtProgram, buildSbtLibrary, or buildSbtProject itself.

  2. Generated composition builds: run sbtix-gen-all2 to regenerate the repo.nix layers and run genComposition to render sbtix-generated.nix. Commit the generated composition files only when your project imports them as part of its build.

  3. For generated composition builds, if you did not use sbtix-gen-all2, run sbtix genComposition to render sbtix-generated.nix using the shared template.

    • When sbtix is run from a flake-provided binary (or when SBTIX_SOURCE_URL, SBTIX_SOURCE_REV, and SBTIX_SOURCE_NAR_HASH are set), the generated file embeds a pinned builtins.fetchTree/fetchgit block that points back to the exact sbtix revision you used for generation. This keeps flake evaluation pure.

    • If those pins are not available, sbtix cannot emit a portable, flake-pure-safe source reference. In that case, regenerate using a flake-provided sbtix (or provide the pins) before running nix build in a downstream flake.

  4. Commit the refreshed repo.nix files (and any generated .nix files that your build actually imports, e.g. sbtix-generated.nix) before running nix build.