nix-java
Skill3 starsChanged 18 days agoApache-2.0View on GitHub
Pin the JDK for JVM projects packaged with Nix (Java, Kotlin, Scala, Clojure). Covers a `nix-jdk` symlink in the workspace that keeps IDEs working when the JDK's store path changes, the argument each JVM tool's `override` takes for its JDK (`jdk` on clojure, `java` on gradle, `jdk_headless` on maven, `jre` on sbt), and `lib.lowPrio` for two packages that put the same binary on `PATH`. Use when packaging anything JVM-based with Nix, when an IDE loses its JDK after a nixpkgs bump, or when JDK wrapper binaries clash on `PATH`.
In this repository6 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- nix-clojureSkill
- nix-flake-recursive-bump-input-versionsSkill
- nix-flakesSkill
- nix-language-packagingSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 22
Add nix-jdk to .gitignore.
- Very specific: line 61
If your agent doesn't run the line above, read these files yourself if they exist: nix-java.preferences.md next to this skill's folder, …
- Distinctive: line 68
When one of these applies and it's in your skill listing, load it without asking.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Nix + JVM / Java
The toolchain-pinning rule in nix-flakes applies: define one JDK and thread it through every consumer. This skill adds the JVM-specific parts.
IDE-friendly JDK symlink
A JDK's Nix store path changes on every nixpkgs update. IDEs (IntelliJ, Cursor, VS Code, Eclipse) store the project JDK by absolute path, so each update breaks them until the developer reconfigures.
Symlink the resolved JDK into the workspace at a stable path from a devshell.startup hook, and point the IDE at the symlink. Bumping the JDK pin updates the symlink in place.
devshell.startup.link-jdk.text = ''
ln -sfn ${pinnedJdk} "$PRJ_ROOT/nix-jdk"
'';Add nix-jdk to .gitignore.
Override the JDK on JVM-based tools
Each tool picks its own default JDK. Override it explicitly; the argument name differs per tool:
clojure.override { jdk = pinnedJdk; }
gradle.override { java = pinnedJdk; }
maven.override { jdk_headless = pinnedJdk; }
sbt.override { jre = pinnedJdk; }- gradle: the wrapper passes every argument on to
gradle-unwrappedand ignores any it doesn't know, sogradle.override { jdk = … }builds the default JDK without an error. Usejava. - maven:
maven.override { jdk = … }fails to evaluate; the argument isjdk_headless.
With the single toolchain constant from nix-flakes, one edit retargets the build, tests, REPL and IDE.
lowPrio for clashing wrappers
A tool wrapped with the pinned JDK and another package that re-exports the same binary can shadow each other on PATH. Demote one with lib.lowPrio instead of removing it:
packages = [
(clojure.override { jdk = pinnedJdk; })
(lib.lowPrio someOtherToolThatExportsClojure)
];Both stay installed, and the other one wins on PATH.
References
- Nixpkgs manual: Java: JDK and JRE packages, and overriding the JRE a package uses.
Your preferences
!cat "${CLAUDE_SKILL_DIR}/../nix-java.preferences.md" "${CLAUDE_PROJECT_DIR}/.agents/skills/nix-java.preferences.md" 2>/dev/null || true
If your agent doesn't run the line above, read these files yourself if they
exist: nix-java.preferences.md next to this skill's folder, then
.agents/skills/nix-java.preferences.md in the project. A project's
file overrides the user's, and the user's overrides this skill's defaults.
Related skills
When one of these applies and it's in your skill listing, load it without asking. If it isn't in your listing, tell the user which skill is missing and ask whether to install it from the same collection this skill came from; don't apply it from memory.
nix-flakes: flake conventions this skill builds on, single-source toolchain pinning among them.nix-clojure: Clojure and ClojureScript packaging with clj-nix, which takes the pinned JDK throughclojure.override.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

