From 083de5031e872af8df34d82bc5cbc3e9d272c503 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Sun, 26 Jan 2025 13:24:07 +0100 Subject: [PATCH] intellij and java --- modules/java.nix | 43 +++++++++++++++++++++++++++++++ modules/jetbrains-ide.nix | 15 +++++------ shell-intellij-gradle-openjdk.nix | 28 +++++++++++--------- 3 files changed, 65 insertions(+), 21 deletions(-) create mode 100644 modules/java.nix diff --git a/modules/java.nix b/modules/java.nix new file mode 100644 index 0000000..cdb5f6e --- /dev/null +++ b/modules/java.nix @@ -0,0 +1,43 @@ +{ config, pkgs, lib, ... }: +let + # Select a JDK version + # + jdk = pkgs.jdk23; + # + # If a more recent OpenJDK version than the bundled JDK is needed. + #jdk = pkgs.unstable.jdk; + #jdk = pkgs.unstable.jdk23; + # + # If JavaFX with WebKit is required. + # https://github.com/NixOS/nixpkgs/blob/4b218e54ae22c8b3ad642ff0dec842363c3abd0f/pkgs/top-level/all-packages.nix#L14583-L14588 + #jdk = pkgs.jdk23.override { + # enableJavaFX = true; + # openjfx_jdk = pkgs.openjfx23.override { withWebKit = true; }; + #}; + + # https://github.com/NixOS/nixpkgs/blob/23e89b7da85c3640bbc2173fe04f4bd114342367/pkgs/development/tools/build-managers/gradle/default.nix#L46 + gradle = pkgs.gradle.override { + java = jdk; + javaToolchains = [ jdk ]; + }; +in +{ + # System-wide installation makes pkgs available at: + # /run/current-system/sw/bin/ + # This makes it easier to configure them in Jetbrain's IDE. + environment.systemPackages = with pkgs; [ + # To use Gradle in IntelliJ: + # - Project settings > Add and select JDK + # - `type java` gives `/run/current-system/sw/bin/java`. + # - Somehow IntelliJ can't select it + # - Thus we use the symlinks destination instead ... + jdk + # To use Gradle in IntelliJ: + # - Settings > Build tools > Gradle > Local installation + # - `type gradle` gives `/run/current-system/sw/bin/gradle`. + # - Somehow IntelliJ can't select it + # - Thus we use the symlinks destination instead ... + gradle + maven + ]; +} diff --git a/modules/jetbrains-ide.nix b/modules/jetbrains-ide.nix index 2b4975a..9c165e7 100644 --- a/modules/jetbrains-ide.nix +++ b/modules/jetbrains-ide.nix @@ -18,6 +18,12 @@ in [ # Rust programming lang ./rust.nix + + # Java programming lang (with Gradle and Maven) + # + # For IntelliJ to use Gradles toolchain, + # see `shell-intellij-gradle-openjdk.nix`. + ./java.nix ]; allowUnfree = [ @@ -30,15 +36,6 @@ in # This makes it easier to configure it as interpreter in Jetbrain's IDE. python3 - maven - - # To use Gradle within InelliJ (or to use a specific OpenJDK version with Gradle), see - # shell-intellij-grade-openjd.nix - - # If a more recent OpenJDK version than the bundled JDK is needed - #unstable.jdk - #unstable.jdk23 - # Markdown preview #pandoc # TODO: Currently markdown previews are broken anyways because of issues with the sandboxed webbrowser on NixOS diff --git a/shell-intellij-gradle-openjdk.nix b/shell-intellij-gradle-openjdk.nix index 3d4b6a2..d170c20 100644 --- a/shell-intellij-gradle-openjdk.nix +++ b/shell-intellij-gradle-openjdk.nix @@ -1,24 +1,28 @@ # Example from my (non public) Software Quality course homework. # That (private) repo might contain a more up to date version. -{ - 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) { }; + ### Import nixpkgs with Niv ### + # + sources = import ./nix/sources.nix; + # nixpkgs stable + pkgs = import sources.nixpkgs { + # Required for IntelliJ Ultimate + config.allowUnfree = true; + }; - # https://github.com/NixOS/nixpkgs/blob/4b218e54ae22c8b3ad642ff0dec842363c3abd0f/pkgs/top-level/all-packages.nix#L14583-L14588 - jdk = unstable.jdk23.override { + # https://github.com/NixOS/nixpkgs/blob/d9e98537533e7d978556bd58739813a47db5d591/pkgs/top-level/all-packages.nix#L14078-L14083 + jdk = pkgs.jdk23.override { enableJavaFX = true; - openjfx_jdk = unstable.openjfx23.override { withWebKit = true; }; + openjfx_jdk = pkgs.openjfx23.override { withWebKit = true; }; }; # https://github.com/NixOS/nixpkgs/blob/23e89b7da85c3640bbc2173fe04f4bd114342367/pkgs/development/tools/build-managers/gradle/default.nix#L46 - gradle = unstable.gradle.override { java = jdk; }; + gradle = pkgs.gradle.override { + java = jdk; + javaToolchains = [ jdk ]; + }; in (