From 7ccdfe497cdd9078b38a91c3557fc995acf5e375 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Sat, 23 Nov 2024 16:52:35 +0000 Subject: [PATCH] shell.nix --- .gitignore | 1 - README.md | 28 ++++++----------------- shell.nix | 35 ++++++++++++++++++----------- shell1.nix | 15 ------------- shell2.nix | 66 ------------------------------------------------------ shell3.nix | 22 ------------------ shell4.nix | 25 --------------------- 7 files changed, 29 insertions(+), 163 deletions(-) delete mode 100644 shell1.nix delete mode 100644 shell2.nix delete mode 100644 shell3.nix delete mode 100644 shell4.nix diff --git a/.gitignore b/.gitignore index ab0a142..f72df32 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /.idea -/.sgp # Ignore Gradle project-specific cache directory /.gradle diff --git a/README.md b/README.md index 64f857f..72131f6 100644 --- a/README.md +++ b/README.md @@ -4,21 +4,17 @@ ### Setup +Dependencies (JDK23, Gradle, IntelliJ) can be installed by running `nix-shell`. + **Commandline** -Check which Java toolchains can be found by Gradle: +Check which Java toolchains Gradle finds: ```shell ./gradlew javaToolchains ``` -- `shell.nix` -> broken (as well for `gradle javaToolchains` -- `shell1.nix` -> works 🥳 -- `shell2.nix` -> broken (as well for `gradle javaToolchains`) -- `shell3.nix` -> works 🥳 -- `shell4.nix` -> works 🥳 - -This should include version >= 17, e.g.: +This should include version >= 23, e.g.: ``` + N/A JDK 23-ga @@ -32,24 +28,14 @@ This should include version >= 17, e.g.: **IntelliJ** -Open issue: gradle's toolchain support does not work with IntelliJ +When using `nix-shell`, some configuration is necessary: -- `shell.nix` - - Solution from 2022 did no longer work: https://github.com/NixOS/nixpkgs/issues/207153#issue-1506967648 -- `shell1.nix` - - Instead, we found this: https://discourse.nixos.org/t/overriding-the-jdk-for-gradle-in-a-nix-flake/36541/2 -- `shell2.nix` - - Another approach - which did no longer work! https://github.com/utybo/Tegral/blob/main/shell.nix -- `shell3.nix` - - This works with JDK 21 🥳 - - STRG ALT SHIFT s -> SDK -> add JDK -> +- STRG ALT SHIFT s -> SDK -> add JDK -> - home path: /usr/lib/openjdk - name: usr-lib-jdk - - STRG ALT s -> build tools -> gradle -> +- STRG ALT s -> build tools -> gradle -> - local installation: /usr/lib/gradle - Gradle JVM: usr-lib-jdk -- `shell4.nix` - - This works with JDK23 🚀 ### Tasks diff --git a/shell.nix b/shell.nix index b58c056..9a49d71 100644 --- a/shell.nix +++ b/shell.nix @@ -1,18 +1,27 @@ -{ pkgs ? import { } }: +# Gradle's toolchain support does not work with IntelliJ, thus we have to use buildFHSUserEnv + +# https://discourse.nixos.org/t/how-to-create-a-development-environment-with-intellij-idea-and-openjdk/10153 +{ + pkgs ? import { + # https://github.com/NixOS/nixpkgs/issues/166220#issuecomment-1745803058 + config.allowUnfree = true; + } +}: let unstable = import (fetchTarball https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz) { }; - toolchains = [ unstable.jdk23 ]; + jdk = unstable.jdk23; + gradle = unstable.gradle; in -pkgs.mkShell { - nativeBuildInputs = [ - (unstable.gradle.overrideAttrs (curr: old: { - fixupPhase = '' - cat > $out/lib/gradle/gradle.properties < { } }: - -let - unstable = import (fetchTarball https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz) { }; - jdk = unstable.jdk23; -in - -pkgs.mkShell { - buildInputs = with pkgs; [ - jdk - (callPackage gradle-packages.gradle_8 { - java = jdk; - }) - ]; -} diff --git a/shell2.nix b/shell2.nix deleted file mode 100644 index e720bea..0000000 --- a/shell2.nix +++ /dev/null @@ -1,66 +0,0 @@ -{ pkgs ? import { } }: - -let - unstable = import (fetchTarball https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz) { }; - toolchains = [ (unstable.jdk11 + "/lib/openjdk") (unstable.jdk17 + "/lib/openjdk") ]; - patchedGradle = unstable.gradle_8.overrideAttrs (curr: old: { - fixupPhase = (old.fixupPhase or "") + '' - cat > $out/lib/gradle/gradle.properties < ./.sgp < .idea/gradle.xml < - - - - - -EOF -echo IntelliJ IDEA configured, restart running instances -EOS - chmod +x ./.sgp - ''; -} - diff --git a/shell3.nix b/shell3.nix deleted file mode 100644 index f33e594..0000000 --- a/shell3.nix +++ /dev/null @@ -1,22 +0,0 @@ -# https://discourse.nixos.org/t/how-to-create-a-development-environment-with-intellij-idea-and-openjdk/10153 -{ - pkgs ? import { - # https://github.com/NixOS/nixpkgs/issues/166220#issuecomment-1745803058 - config.allowUnfree = true; - } -}: -( - pkgs.buildFHSUserEnv - { - name = "foo"; - targetPkgs = pkgs_: - [ - pkgs_.jetbrains.idea-ultimate - - # Gradle 8.7 is configured for JDK 21 - pkgs_.jdk - pkgs_.gradle - - ]; - } -).env diff --git a/shell4.nix b/shell4.nix deleted file mode 100644 index 6ab56fb..0000000 --- a/shell4.nix +++ /dev/null @@ -1,25 +0,0 @@ -# https://discourse.nixos.org/t/how-to-create-a-development-environment-with-intellij-idea-and-openjdk/10153 -{ - pkgs ? import { - # https://github.com/NixOS/nixpkgs/issues/166220#issuecomment-1745803058 - config.allowUnfree = true; - } -}: - -let - unstable = import (fetchTarball https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz) { }; - jdk = unstable.jdk23; - gradle = unstable.gradle; -in - -( - pkgs.buildFHSUserEnv - { - name = "foo2"; - targetPkgs = pkgs_: [ - pkgs_.jetbrains.idea-ultimate - jdk - gradle - ]; - } -).env