intellij and java

This commit is contained in:
Daniel Langbein 2025-01-26 13:24:07 +01:00
parent e0faf9d6bc
commit 083de5031e
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
3 changed files with 65 additions and 21 deletions

43
modules/java.nix Normal file
View File

@ -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
];
}

View File

@ -18,6 +18,12 @@ in
[ [
# Rust programming lang # Rust programming lang
./rust.nix ./rust.nix
# Java programming lang (with Gradle and Maven)
#
# For IntelliJ to use Gradles toolchain,
# see `shell-intellij-gradle-openjdk.nix`.
./java.nix
]; ];
allowUnfree = [ allowUnfree = [
@ -30,15 +36,6 @@ in
# This makes it easier to configure it as interpreter in Jetbrain's IDE. # This makes it easier to configure it as interpreter in Jetbrain's IDE.
python3 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 # Markdown preview
#pandoc #pandoc
# TODO: Currently markdown previews are broken anyways because of issues with the sandboxed webbrowser on NixOS # TODO: Currently markdown previews are broken anyways because of issues with the sandboxed webbrowser on NixOS

View File

@ -1,24 +1,28 @@
# Example from my (non public) Software Quality course homework. # Example from my (non public) Software Quality course homework.
# That (private) repo might contain a more up to date version. # That (private) repo might contain a more up to date version.
{ { }:
pkgs ? import <nixpkgs> {
# https://github.com/NixOS/nixpkgs/issues/166220#issuecomment-1745803058
config.allowUnfree = true;
}
}:
let 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 # https://github.com/NixOS/nixpkgs/blob/d9e98537533e7d978556bd58739813a47db5d591/pkgs/top-level/all-packages.nix#L14078-L14083
jdk = unstable.jdk23.override { jdk = pkgs.jdk23.override {
enableJavaFX = true; 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 # 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 in
( (