86dc80eb3c
Add Java extension support and configure multiple JDK runtimes. Introduce a wrapped VS Code package that includes JDK 25 in the PATH to support the Red Hat Java language server. Switch from using `programs.vscode.userSettings` to a manually managed `settings.json` file via `home.file`. This allows the settings file to be writable by external tools like `kilo-code` at runtime while preserving them across Nix configuration switches by using `force = false`.
101 lines
3.2 KiB
Nix
101 lines
3.2 KiB
Nix
# Visual Studio Code (Microsoft build, unfree). Default extensions + settings shared by all
|
|
# hosts; per-host extras (peacock, comment-anchors, project-manager) go via
|
|
# `chiasson.home.editors.vscode.extensions`.
|
|
{ self, ... }: {
|
|
flake.homeManagerModules.wisdomEditorsVscode =
|
|
{ config, lib, pkgs, ... }:
|
|
let
|
|
root = config.chiasson.home;
|
|
cfg = config.chiasson.home.editors.vscode;
|
|
|
|
defaultExtensions = with pkgs.vscode-extensions; [
|
|
jnoortheen.nix-ide
|
|
yzhang.markdown-all-in-one
|
|
esbenp.prettier-vscode
|
|
vscjava.vscode-java-pack
|
|
redhat.java
|
|
];
|
|
|
|
# Wrap VS Code so a JDK is on PATH — the Red Hat Java language server (and
|
|
# other extension-bundled JVMs) need `java` to run, independent of the
|
|
# per-project `java.configuration.runtimes` setting.
|
|
vscodeWithJdk = pkgs.symlinkJoin {
|
|
name = "vscode-with-jdk";
|
|
paths = [ pkgs.vscode ];
|
|
nativeBuildInputs = [ pkgs.makeWrapper ];
|
|
postBuild = ''
|
|
wrapProgram "$out/bin/code" \
|
|
--prefix PATH : "${pkgs.jdk25}/bin"
|
|
'';
|
|
};
|
|
|
|
coreSettings = {
|
|
"nix.enableLanguageServer" = true;
|
|
"nix.serverPath" = "nixd";
|
|
"nix.serverSettings" = {
|
|
nixd = {
|
|
formatting = {
|
|
command = "nixfmt";
|
|
};
|
|
};
|
|
};
|
|
"diffEditor.ignoreTrimWhitespace" = false;
|
|
"chat.disableAIFeatures" = true;
|
|
|
|
"java.configuration.runtimes" = [
|
|
{
|
|
name = "JavaSE-21";
|
|
path = "${pkgs.jdk21}/lib/openjdk";
|
|
}
|
|
{
|
|
name = "JavaSE-25";
|
|
path = "${pkgs.jdk25}/lib/openjdk";
|
|
default = true;
|
|
}
|
|
];
|
|
};
|
|
|
|
# Seed a *writable* settings.json (not a store symlink) so extensions like
|
|
# kilo-code can edit it at runtime. `force = false` in the config means HM
|
|
# only writes it when absent, preserving kilo's later edits across `switch`.
|
|
settingsJson = pkgs.writeText "vscode-user-settings" (
|
|
builtins.toJSON coreSettings
|
|
);
|
|
in
|
|
{
|
|
options.chiasson.home.editors.vscode = {
|
|
enable = lib.mkEnableOption ''
|
|
Visual Studio Code (Microsoft build; needs `nixpkgs.config.allowUnfree`). Core
|
|
extensions (nix-ide, markdown-all-in-one, prettier) + nixd/nixfmt settings are included.
|
|
'' // {
|
|
default = false;
|
|
};
|
|
|
|
extensions = lib.mkOption {
|
|
type = lib.types.listOf lib.types.package;
|
|
default = [ ];
|
|
description = ''
|
|
Extra extensions not wanted on every host (e.g. peacock, comment-anchors,
|
|
project-manager). Per-host via `chiasson.users.extraModules`.
|
|
'';
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf (root.enable && cfg.enable) {
|
|
home.packages = [ ];
|
|
|
|
# Writable, seed-once user settings (kilo-code can append to it).
|
|
home.file.".config/Code/User/settings.json" = {
|
|
source = settingsJson;
|
|
force = false;
|
|
};
|
|
|
|
programs.vscode = {
|
|
enable = true;
|
|
package = vscodeWithJdk;
|
|
extensions = defaultExtensions ++ cfg.extensions;
|
|
};
|
|
};
|
|
};
|
|
}
|