Skip to content

Instantly share code, notes, and snippets.

@r-k-b
Last active May 14, 2022 18:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r-k-b/71232a4e0ceacaa15eccd4355781804e to your computer and use it in GitHub Desktop.
Save r-k-b/71232a4e0ceacaa15eccd4355781804e to your computer and use it in GitHub Desktop.
nix shell for a development environment for a Gradle project

I was getting errors like...

$ ./gradlew build
... snip ...
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':buildSearchableOptions'.
> A problem occurred starting process 'command '/home/rkb/.gradle/caches/modules-2/files-2.1/com.jetbrains/jbre/jbrx-8u202-linux-x64-b1483.49/jre/bin/java''
libfreetype.so.6: cannot open shared object file: No such file or directory
could not open terminal for stdout: could not get termcap entry

usage

$ nix-shell default.nix

then gradle build or whatever

see also

https://github.com/r-k-b/intellij-elm/commit/829154f3c10a3953889b86216ba1dd3f79a2a153

# h/t: https://discourse.nixos.org/t/problem-with-gradle-building-kotlin-native/7272/2?u=r-k-b
# initially written for hacking on https://github.com/klazuka/intellij-elm
# Note that certain gradle tasks may still fail, if `GRADLE_USER_HOME` contains files downloaded
# by a previous gradle instance run outside of the FHS environment this nix file provides.
# (that is, if something weird happens, `rm -rf ~/.gradle` and try again)
{ pkgs ? import <nixpkgs> { } }:
let
fhs = pkgs.buildFHSUserEnv {
name = "gradle-env";
targetPkgs = pkgs:
(with pkgs; [
gradle
kotlin
jdk
zlib
ncurses
freetype # for missing libfreetype.so.6
]);
};
in pkgs.stdenv.mkDerivation {
name = "gradle-env-shell";
nativeBuildInputs = [ fhs ];
# this seems to trigger an infinite loop when direnv loads this nix file... how to avoid that?
shellHook = "exec gradle-env";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment