I’m trying to override the JDK used for Gradle in a flake that combines Gradle and GraalVM for development. It’d be nice if I could make Gradle use GraalVM, but that’s not strictly necessary – jdk21
is enough. Please let me know if there is a way though, as that would make the derivation smaller.
However, I’m having trouble getting this to work at all. Documentation on these features seems scarce and confusing and the error messages I’ve encountered have not been very helpful. When the flake’s dev shell does build successfully (using the code below), gradle -version
shows JDK 17.
{
inputs = {
nixpkgs = {
url = "github:nixos/nixpkgs?ref=057f9aecfb71c4437d2b27d3323df7f93c010b7e";
};
};
outputs = { self, nixpkgs }:
let pkgs = import nixpkgs {
system = "x86_64-linux";
config.allowUnfree = true;
overlays = [
(self: super: {
gradle = super.gradle.override {
jdk = super.jdk21;
};
})
];
};
in {
devShell.x86_64-linux = pkgs.mkShell {
buildInputs = with pkgs; [
graalvm-ce
gradle
];
};
};
}
The docs don’t always take into account non-NixOS environments and often don’t cover flakes. Sadly, this is an issue that involves both – flakes on an Ubuntu 22.04 system. I have NixOS on my personal laptop but don’t have enough nixperience to proceed.
In general, I don’t know how to provide arguments for nixpkgs packages. It seems like it should be far simpler than the overlay approach, but I haven’t been able to find any alternatives online. I’ve tried using gradle.override ...
or gradle.overrideAttrs ...
in place of gradle
in buildInputs
, but that only leads to errors. Any help is much appreciated.