Optionalize mkTarget's 'humanName' and 'name' arguments by inferring 'humanName' from the 'name' attribute in the /modules/<MODULE>/meta.nix file, and 'name' from the /modules/<NAME>/ directory name. Inferring the 'humanName' and 'name' arguments ensures consistency and reduces boilerplate. The 'humanName' and 'name' arguments are optionalized instead of removed because complex modules generating target derivations need to distinguish between them. Closes: https://github.com/nix-community/stylix/issues/1661
55 lines
1.6 KiB
Nix
55 lines
1.6 KiB
Nix
{
|
|
mkTarget,
|
|
pkgs,
|
|
config,
|
|
lib,
|
|
...
|
|
}:
|
|
mkTarget {
|
|
options.profileNames = lib.mkOption {
|
|
description = "The VSCode profile names to apply styling on.";
|
|
type = lib.types.listOf lib.types.str;
|
|
default = [ "default" ];
|
|
};
|
|
|
|
config = [
|
|
(
|
|
{ cfg }:
|
|
{
|
|
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;
|
|
});
|
|
}
|
|
)
|
|
];
|
|
}
|