Getting Started
Flake setup and the recommended sbtix workflow
How?
Sbtix is intended to be used as a Nix-provided command-line tool. The tool loads a matching sbt plugin into a separate sbt global base while it generates repo.nix and sbtix-generated.nix. In normal projects, you should not add sbtix to project/plugins.sbt yourself; using the Nix CLI keeps the plugin jar, Nix builders, templates, and generated source pin on the same sbtix version or commit.
Direct sbt-plugin use is mainly for sbtix development or custom internal workflows where you deliberately publish/provide the plugin artifact yourself and take responsibility for keeping it in sync with the Nix expressions.
To install sbtix either:
nix shell github:natural-transformation/sbtix
Or, from this repository:
nix build '.#sbtix'
./result/bin/sbtix --help
sbtix provides a number of scripts to generate and update Nix expressions to fetch your dependencies and build your sbt project. These scripts work by opening your project in sbt and loading an additional sbtix plugin (via the sbt.global.base directory to $HOME/.sbtix). After generation, you don't need the sbtix command-line tools to actually build your project from nix.
Using sbtix from a flake (recommended)
If your project is already a Nix flake, adding sbtix as a flake input is the most reliable way to keep generation reproducible and flake-pure-safe.
Full runnable example: examples/flake-app/ builds a minimal app with nix build using the flake-native workflow (sbtix-gen + buildSbtProgram). Copy flake.nix.example into your own project for a starting template.
Add an input and expose the sbtix CLI in your dev shell:
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# Prefer a tag (or pinned commit) so the sbtix input is stable.
sbtix.url = "github:natural-transformation/sbtix/v1.1.1";
# Optional: keep nixpkgs consistent across inputs.
sbtix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, sbtix, ... }:
let
system = "x86_64-linux"; # or use flake-parts / supported systems
pkgs = import nixpkgs { inherit system; };
in {
devShells.${system}.default = pkgs.mkShell {
packages = [
sbtix.packages.${system}.sbtix
];
};
};
}
Then choose the workflow that owns your Nix build expression:
nix develop
sbtix-gen
Use sbtix-gen when your flake imports sbtix's helper functions from the flake input and defines the package itself. This generates the repo.nix lockfiles that your flake imports; it does not generate or require sbtix-generated.nix.
Use sbtix-gen-all2 when you want sbtix to generate a standalone Nix composition:
nix develop
sbtix-gen-all2
That path generates sbtix-generated.nix, sbtix.nix, and sbtix-plugin-repo.nix in addition to the repo.nix lockfiles. Commit those files only if your project actually imports the generated composition, for example through default.nix.
When sbtix is run from a flake-provided binary, sbtix-generated.nix embeds a pinned sbtix source reference (builtins.fetchTree / fetchgit) so downstream flake evaluation stays pure.
To call sbtix's Nix helpers directly from your flake, import them from the sbtix input and pick the builder that matches your packaging layout:
let
sbtixLib = pkgs.callPackage "${sbtix}/plugin/nix-exprs/sbtix.nix" {
jdk = pkgs.jdk;
jre = pkgs.jdk;
};
in
sbtixLib.buildSbtProject {
name = "my-app";
src = pkgs.lib.cleanSource ./.;
repo = [
(import ./manual-repo.nix)
(import ./repo.nix)
(import ./project/repo.nix)
];
buildPhase = ''
sbt assembly
'';
installPhase = ''
mkdir -p $out/lib
cp target/scala-*/my-app.jar $out/lib/
'';
}
For a project with an sbt-native-packager stage task, use buildSbtProgram. For a library, use buildSbtLibrary. For custom layouts such as assembly jars, use buildSbtProject with an explicit installPhase.
See examples/flake-app/flake.nix for a complete devShells + packages.default setup.