vscode: use mkTarget (#1477)

Link: https://github.com/nix-community/stylix/pull/1477

Reviewed-by: awwpotato <awwpotato@voidq.com>
Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
This commit is contained in:
Flameopathic 2025-06-12 20:29:06 +02:00 committed by GitHub
parent c117edd7ee
commit dcf0f17712
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 54 additions and 48 deletions

View file

@ -1,52 +1,59 @@
{
mkTarget,
pkgs,
config,
lib,
...
}@args:
}:
let
extension =
pkgs.runCommandLocal "stylix-vscode"
mkTarget {
name = "vscode";
humanName = "VSCode";
extraOptions.profileNames = lib.mkOption {
description = "The VSCode profile names to apply styling on.";
type = lib.types.listOf lib.types.str;
default = [ "default" ];
};
configElements = [
(
{ cfg }:
{
vscodeExtUniqueId = "stylix.stylix";
vscodeExtPublisher = "stylix";
version = "0.0.0";
theme = builtins.toJSON (import ./templates/theme.nix args);
passAsFile = [ "theme" ];
warnings =
lib.optional (config.programs.vscode.enable && cfg.profileNames == [ ])
''stylix: vscode: `config.stylix.targets.vscode.profileNames` is empty. No theming will be applied. Add a profile or disable this warning by setting `stylix.targets.vscode.enable = false`.'';
}
''
mkdir -p "$out/share/vscode/extensions/$vscodeExtUniqueId/themes"
ln -s ${./package.json} "$out/share/vscode/extensions/$vscodeExtUniqueId/package.json"
cp "$themePath" "$out/share/vscode/extensions/$vscodeExtUniqueId/themes/stylix.json"
'';
settings = import ./templates/settings.nix args;
profile = {
extensions = [ extension ];
userSettings = settings;
};
cfg = config.stylix.targets.vscode;
in
{
options.stylix.targets.vscode = {
enable = config.lib.stylix.mkEnableTarget "VSCode" true;
profileNames = lib.mkOption {
description = "The VSCode profile names to apply styling on.";
type = lib.types.listOf lib.types.str;
default = [ "default" ];
};
};
config = lib.mkIf (config.stylix.enable && cfg.enable) {
programs.vscode.profiles = lib.genAttrs cfg.profileNames (_name: profile);
warnings =
lib.optional (config.programs.vscode.enable && cfg.profileNames == [ ])
''stylix: vscode: `config.stylix.targets.vscode.profileNames` is empty. No theming will be applied. Add a profile or disable this warning by setting `stylix.targets.vscode.enable = false`.'';
};
)
(
{ cfg, colors }:
{
programs.vscode.profiles = lib.genAttrs cfg.profileNames (_: {
extensions = lib.singleton (
pkgs.runCommandLocal "stylix-vscode"
{
vscodeExtUniqueId = "stylix.stylix";
vscodeExtPublisher = "stylix";
version = "0.0.0";
theme = builtins.toJSON (import ./templates/theme.nix colors);
passAsFile = [ "theme" ];
}
''
mkdir -p "$out/share/vscode/extensions/$vscodeExtUniqueId/themes"
ln -s ${./package.json} "$out/share/vscode/extensions/$vscodeExtUniqueId/package.json"
cp "$themePath" "$out/share/vscode/extensions/$vscodeExtUniqueId/themes/stylix.json"
''
);
});
}
)
(
{ cfg, fonts }:
{
programs.vscode.profiles = lib.genAttrs cfg.profileNames (_: {
userSettings = import ./templates/settings.nix fonts;
});
}
)
];
}

View file

@ -1,6 +1,6 @@
{ config, ... }:
fonts:
with config.stylix.fonts;
with fonts;
{
"workbench.colorTheme" = "Stylix";

View file

@ -1,6 +1,5 @@
{ config, ... }:
with config.lib.stylix.colors.withHashtag;
colors:
with colors.withHashtag;
{
"$schema" = "vscode://schemas/color-theme";