All Projects → tadfisher → gradle2nix

tadfisher / gradle2nix

Licence: MIT license
Generate Nix expressions which build Gradle-based projects.

Programming Languages

kotlin
9241 projects
Nix
1067 projects
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to gradle2nix

dotfiles
No place like ~. Nix. All. The. Things.
Stars: ✭ 48 (-32.39%)
Mutual labels:  nix, nixos, nixpkgs
crane
A Nix library for building cargo projects. Never build twice thanks to incremental artifact caching.
Stars: ✭ 348 (+390.14%)
Mutual labels:  nix, nixos, nixpkgs
Home Manager
Manage a user environment using Nix [maintainer=@rycee]
Stars: ✭ 2,447 (+3346.48%)
Mutual labels:  nix, nixos, nixpkgs
yants
Yet Another Nix Type System | Source has moved to https://git.tazj.in/tree/nix/yants
Stars: ✭ 35 (-50.7%)
Mutual labels:  nix, nixos, nixpkgs
nix-bisect
Bisect nix builds. Status: alpha/proof of concept. You'll probably have to dig into the implementation if you want to use it. Built for personal use, lightly maintained. PRs welcome. Issues welcome, but I make no promises regarding responses or fix
Stars: ✭ 72 (+1.41%)
Mutual labels:  nix, nixos, nixpkgs
triton
Triton Operating System
Stars: ✭ 56 (-21.13%)
Mutual labels:  nix, nixos, nixpkgs
nixpkgs
Nix Packages collection used in Nubank
Stars: ✭ 24 (-66.2%)
Mutual labels:  nix, nixos, nixpkgs
nixpkgs-python-importer
Violate Nix philosophy, install Python packages mid-session with `from nixpkgs.scipy import scipy`.
Stars: ✭ 27 (-61.97%)
Mutual labels:  nix, nixos, nixpkgs
Nixpkgs
Nix Packages collection
Stars: ✭ 8,322 (+11621.13%)
Mutual labels:  nix, nixos, nixpkgs
Nix Bitcoin
A collection of Nix packages and NixOS modules for easily installing full-featured Bitcoin nodes with an emphasis on security.
Stars: ✭ 154 (+116.9%)
Mutual labels:  nix, nixos
Vulnix
Vulnerability (CVE) scanner for Nix/NixOS.
Stars: ✭ 161 (+126.76%)
Mutual labels:  nix, nixos
dotfiles
My NixOS configuration featuring awesome and neovim
Stars: ✭ 40 (-43.66%)
Mutual labels:  nix, nixos
Dotfiles
My dotfiles
Stars: ✭ 150 (+111.27%)
Mutual labels:  nix, nixos
Appvm
Nix-based app VMs
Stars: ✭ 146 (+105.63%)
Mutual labels:  nix, nixos
Shabka
Shabka. Declaritive description of my network, workstations and servers.
Stars: ✭ 138 (+94.37%)
Mutual labels:  nix, nixos
Nixos Mailserver
A complete and Simple Nixos Mailserver
Stars: ✭ 172 (+142.25%)
Mutual labels:  nix, nixos
Nixpkgs Wayland
Automated, pre-built packages for Wayland (sway/wlroots) tools for NixOS.
Stars: ✭ 178 (+150.7%)
Mutual labels:  nix, nixos
Nixos Weekly
NixOS Weekly Newsletter
Stars: ✭ 137 (+92.96%)
Mutual labels:  nix, nixos
Deploy Rs
A simple multi-profile Nix-flake deploy tool.
Stars: ✭ 164 (+130.99%)
Mutual labels:  nix, nixos
Nix 1p
A (more or less) one page introduction to Nix, the language.
Stars: ✭ 219 (+208.45%)
Mutual labels:  nix, nixos

./assets/gradle2nix.png

Generate Nix expressions which build Gradle-based projects.

Why?

Nix is an OS-agnostic package manager, a language-agnostic build system, and a bespoke programming language. One of its unique features is that it is purely functional; a “package” is a function which accepts inputs (source code, configuration, etc) and produces an output (binaries, a Java JAR, documentation, really anything).

One benefit of a functional build system is reproducibility. If you specify your inputs precisely, and take care not to introduce impurities—such as files retrieved over a network without tracking their content—you will receive, byte-for-byte, the exact output as someone else running the same function over the same inputs.

Gradle is not a functional build system. Most Gradle-based projects will produce highly variable outputs depending on a host of impure inputs, including:

  • The JVM hosting the build
  • The Gradle installation running the build
  • Any usage of dynamic version constraints for dependencies
  • SNAPSHOT dependencies
  • Environment variables and command-line options
  • Artifacts cached on the system hosting the build

gradle2nix helps to solve this problem by leveraging Nix to control the most common inputs to a Gradle build. When run on a project, it will record all dependencies for both the build environment (including plugins and buildscript blocks) and the project, and provide a Nix expression to run the build given these dependencies. The build itself is then run in a sandbox, where only content-tracked network requests are allowed to fetch dependencies, and a local Maven repository is created on-the-fly to host the dependency artifacts somewhere Gradle can resolve them without a network.

This tool is useful for both development and packaging. You can use gradle2nix to:

  • Create isolated and reproducible development environments that work anywhere Nix itself can run;
  • Reduce or eliminate flakiness and maintenance headaches from CI/CD pipelines
  • Distribute a recipe which can reliably build a Gradle project in repositories such as the Nix Package Collection.

Installation

A Nix expression (generated by gradle2nix itself) is provided for convenience. The following expression will fetch and build the latest version of this package:

import (fetchTarball "https://github.com/tadfisher/gradle2nix/archive/master.tar.gz")  {}

If this expression is in, say, gradle2nix.nix, gradle2nix can be built and placed in .//result with the following:

nix build -f gradle2nix.nix

You can also use the following one-liners to build or install gradle2nix in your user profile:

# Build and place in ./result/
nix build -f "https://github.com/tadfisher/gradle2nix/archive/master.tar.gz"

# Build and install in the user profile
nix-env -if "https://github.com/tadfisher/gradle2nix/archive/master.tar.gz"

gradle2nix is not yet packaged in nixpkgs itself, but work is in progress.

Flake (experimental)

A flake.nix is provided for those using Nix flakes. For example, the following will build and run gradle2nix with the arguments provided after --:

nix run github:tadfisher/gradle2nix -- --help

Usage

Usage: gradle2nix [OPTIONS] [PROJECT-DIR]

Options:
  -g, --gradle-version VERSION     Use a specific Gradle version
  -a, --gradle-args ARGS           Extra arguments to pass to Gradle
  -c, --configuration NAME         Add a configuration to resolve (default:
                                   all configurations)
  -i, --include DIR                Add an additional project to include
  -p, --project PATH               Only resolve these subproject paths, e.g.
                                   ':', or ':sub:project' (default: all
                                   projects)
  -o, --out-dir DIR                Path to write generated files (default:
                                   PROJECT-DIR)
  -e, --env FILENAME               Prefix for environment files (.json and
                                   .nix) (default: gradle-env)
  -b, --build-src / -nb, --no-build-src
                                   Include buildSrc project (default: true)
  -q, --quiet                      Disable logging
  -h, --help                       Show this message and exit

Arguments:
  PROJECT-DIR  Path to the project root (default: .)

Simply running gradle2nix in the root directory of a project should be enough for most projects. This will produce two files, by default called gradle-env.json and gradle-env.nix, which contain the pinned dependencies for the project and a standard build expression which can be imported or called by other Nix expressions. An example of such an expression can be found in this project’s default.nix.

Specifying the Gradle version

By default, if the project has configured the Gradle wrapper, that version will be detected and pinned; otherwise, the version of Gradle installed on your system will be pinned. You can override this with the --gradle-version argument, which also avoids the need to have Gradle installed.

gradle2nix -g 6.1

Multi-project builds

If you want to resolve only a subset of projects in a multi-project build, add the --project option for each project. For example, in a project where you only want to build the subprojects :app and :widget:

gradle2nix -p :app -p :widget

Any project dependencies will be also be included when pinning dependency artifacts.

Contributing

Bug reports and feature requests are encouraged.

Create an issue

Code contributions are also encouraged. Please review the test cases in the fixtures directory and create a new one to reproduce any fixes or test new features. See the existing compatibility tests for examples of testing with these fixtures.

License

gradle2nix is licensed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].