WIP: shell.nix

This commit is contained in:
Daniel Langbein 2024-11-20 13:49:18 +01:00
parent 21012c1c2b
commit b8c1b79916
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
4 changed files with 89 additions and 6 deletions

6
.gitignore vendored
View File

@ -1,5 +1,7 @@
/.sgp
# Ignore Gradle project-specific cache directory # Ignore Gradle project-specific cache directory
.gradle /.gradle
# Ignore Gradle build output directory # Ignore Gradle build output directory
build /build

View File

@ -4,12 +4,18 @@
### Setup ### Setup
**Commandline**
Check which Java toolchains can be found by Gradle: Check which Java toolchains can be found by Gradle:
```shell ```shell
./gradlew javaToolchains ./gradlew javaToolchains
``` ```
- `shell.nix` -> broken (as well for `gradle javaToolchains`
- `shell1.nix` -> works
- `shell2.nix` -> broken (as well for `gradle javaToolchains`)
This should include version >= 17, e.g.: This should include version >= 17, e.g.:
``` ```
@ -22,6 +28,19 @@ This should include version >= 17, e.g.:
| Detected by: Current JVM | Detected by: Current JVM
``` ```
**IntelliJ**
TODO, nothing has worked so far.
Open issue: gradle's toolchain support does not work with IntelliJ
- `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
### Tasks ### Tasks
List all Gradle tasks which can be run: List all Gradle tasks which can be run:

View File

@ -5,10 +5,6 @@ let
jdk = unstable.jdk23; jdk = unstable.jdk23;
in in
# Open issue: gradle's toolchain support does not work with IntelliJ
# Solution from 2022 did no longer work: https://github.com/NixOS/nixpkgs/issues/207153#issue-1506967648
# Instead we found this: https://discourse.nixos.org/t/overriding-the-jdk-for-gradle-in-a-nix-flake/36541/2
pkgs.mkShell { pkgs.mkShell {
buildInputs = with pkgs; [ buildInputs = with pkgs; [
jdk jdk

66
shell2.nix Normal file
View File

@ -0,0 +1,66 @@
{ pkgs ? import <nixpkgs> { } }:
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 <<EOF
org.gradle.java.installations.paths=${unstable.lib.concatStringsSep "," toolchains}
EOF
'';
});
nodePackages18 = unstable.nodePackages.override { nodejs = unstable.nodejs-18_x; };
in
unstable.mkShell {
nativeBuildInputs = [
patchedGradle
unstable.nodejs-18_x
nodePackages18.pnpm
unstable.prisma-engines
nodePackages18.prisma
];
shellHook = ''
export PRISMA_MIGRATION_ENGINE_BINARY="${unstable.prisma-engines}/bin/schema-engine"
export PRISMA_QUERY_ENGINE_BINARY="${unstable.prisma-engines}/bin/query-engine"
export PRISMA_QUERY_ENGINE_LIBRARY="${unstable.prisma-engines}/lib/libquery_engine.node"
export PRISMA_INTROSPECTION_ENGINE_BINARY="${unstable.prisma-engines}/bin/introspection-engine"
export PRISMA_FMT_BINARY="${unstable.prisma-engines}/bin/prisma-fmt"
export PATH="$PATH:$PWD/node_modules/.bin"
export GRADLE_HOME=${patchedGradle}
echo -e '\033[0;33m!!! Run ./.sgp (set gradle path) from the root of this repository BEFORE running IntelliJ IDEA !!!\033[0m'
echo -e '\033[0;33m(restart IntelliJ IDEA if you already started it)\033[0m'
cat > ./.sgp <<EOS
#!/bin/sh
mkdir -p .idea
rm -f .idea/gradle.xml
cat > .idea/gradle.xml <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="delegatedBuild" value="true" />
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="\\\$PROJECT_DIR\\\$" />
<option name="gradleHome" value="${patchedGradle}/lib/gradle" />
<option name="gradleJvm" value="#JAVA_HOME" />
<option name="modules">
<set>
<option value="\\\$PROJECT_DIR\\\$" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>
EOF
echo IntelliJ IDEA configured, restart running instances
EOS
chmod +x ./.sgp
'';
}