mirror of
https://github.com/nix-community/home-manager.git
synced 2025-03-31 04:04:32 +00:00
zed-editor: add userThemes option
Adding support for custom local themes
This commit is contained in:
parent
5031c6d297
commit
5738fa02ec
5 changed files with 121 additions and 18 deletions
|
@ -1,22 +1,25 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.programs.zed-editor;
|
||||
jsonFormat = pkgs.formats.json { };
|
||||
|
||||
mergedSettings = cfg.userSettings
|
||||
// (lib.optionalAttrs (builtins.length cfg.extensions > 0) {
|
||||
# this part by @cmacrae
|
||||
# by @cmacrae
|
||||
auto_install_extensions = lib.genAttrs cfg.extensions (_: true);
|
||||
});
|
||||
|
||||
buildThemes = themes:
|
||||
lib.listToAttrs (map (theme: {
|
||||
name = "zed/themes/${theme.name}.json";
|
||||
value = { source = jsonFormat.generate "zed-theme-${theme.name}" theme; };
|
||||
}) themes);
|
||||
in {
|
||||
meta.maintainers = [ hm.maintainers.libewa ];
|
||||
|
||||
options = {
|
||||
# TODO: add vscode option parity (installing extensions, configuring
|
||||
# keybinds with nix etc.)
|
||||
# TODO: add vscode option parity (installing extensions, configuring, keybinds with nix etc.)
|
||||
programs.zed-editor = {
|
||||
enable = mkEnableOption
|
||||
"Zed, the high performance, multiplayer code editor from the creators of Atom and Tree-sitter";
|
||||
|
@ -61,7 +64,7 @@ in {
|
|||
bindings = {
|
||||
ctrl-shift-t = "workspace::NewTerminal";
|
||||
};
|
||||
};
|
||||
}
|
||||
]
|
||||
'';
|
||||
description = ''
|
||||
|
@ -69,6 +72,32 @@ in {
|
|||
'';
|
||||
};
|
||||
|
||||
userThemes = mkOption {
|
||||
type = types.listOf jsonFormat.type;
|
||||
default = [ ];
|
||||
example = literalExpression ''
|
||||
[
|
||||
{
|
||||
name = "example 1";
|
||||
author = "user";
|
||||
themes = [
|
||||
{
|
||||
name = "example 1";
|
||||
appearance = "dark";
|
||||
style = {
|
||||
background = "#000000";
|
||||
};
|
||||
}
|
||||
];
|
||||
}
|
||||
];
|
||||
'';
|
||||
description = ''
|
||||
Local themes written to {file}`$XDG_CONFIG_HOME/zed/themes`.
|
||||
See <https://zed.dev/docs/extensions/themes> for more information.
|
||||
'';
|
||||
};
|
||||
|
||||
extensions = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
|
@ -122,15 +151,19 @@ in {
|
|||
binaryName = "zed-remote-server-stable-${version}";
|
||||
in {
|
||||
".zed_server/${binaryName}".source =
|
||||
lib.getExe' remote_server binaryName;
|
||||
lib.getExe' remote_server binaryName;
|
||||
});
|
||||
|
||||
xdg.configFile."zed/settings.json" = (mkIf (mergedSettings != { }) {
|
||||
source = jsonFormat.generate "zed-user-settings" mergedSettings;
|
||||
});
|
||||
|
||||
xdg.configFile."zed/keymap.json" = (mkIf (cfg.userKeymaps != { }) {
|
||||
source = jsonFormat.generate "zed-user-keymaps" cfg.userKeymaps;
|
||||
});
|
||||
xdg.configFile = mkMerge [
|
||||
{
|
||||
"zed/settings.json" = mkIf (mergedSettings != { }) {
|
||||
source = jsonFormat.generate "zed-user-settings" mergedSettings;
|
||||
};
|
||||
"zed/keymap.json" = mkIf (cfg.userKeymaps != { }) {
|
||||
source = jsonFormat.generate "zed-user-keymaps" cfg.userKeymaps;
|
||||
};
|
||||
}
|
||||
(lib.mkIf (cfg.userThemes != [ ]) (buildThemes cfg.userThemes))
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
0
tests/flake.lock
generated
Normal file
0
tests/flake.lock
generated
Normal file
|
@ -3,4 +3,5 @@
|
|||
zed-install-remote-server = ./install-remote-server.nix;
|
||||
zed-keymap = ./keymap.nix;
|
||||
zed-settings = ./settings.nix;
|
||||
zed-themes = ./themes.nix;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
# Test custom keymap functionality
|
||||
{ config, ... }:
|
||||
|
||||
{
|
||||
# Test custom settings functionality
|
||||
{ config, ... }: {
|
||||
programs.zed-editor = {
|
||||
enable = true;
|
||||
package = config.lib.test.mkStubPackage { };
|
||||
|
|
71
tests/modules/programs/zed-editor/themes.nix
Normal file
71
tests/modules/programs/zed-editor/themes.nix
Normal file
|
@ -0,0 +1,71 @@
|
|||
# Test custom theme functionality
|
||||
{ config, ... }: {
|
||||
programs.zed-editor = {
|
||||
enable = true;
|
||||
package = config.lib.test.mkStubPackage { };
|
||||
userThemes = [{
|
||||
name = "Test";
|
||||
author = "user";
|
||||
themes = [{
|
||||
name = "Test Catppuccin";
|
||||
appearance = "light";
|
||||
style = {
|
||||
editor = {
|
||||
foreground = "#4c4f69";
|
||||
background = "#eff1f5";
|
||||
gutter.background = "#eff1f5";
|
||||
subheader.background = "#e6e9ef";
|
||||
active_line.background = "#4c4f690d";
|
||||
highlighted_line.background = null;
|
||||
line_number = "#8c8fa1";
|
||||
active_line_number = "#8839ef";
|
||||
invisible = "#7c7f9366";
|
||||
wrap_guide = "#acb0be";
|
||||
};
|
||||
};
|
||||
}];
|
||||
}];
|
||||
};
|
||||
|
||||
nmt.script = let
|
||||
expectedContent = builtins.toFile "expected.json" ''
|
||||
{
|
||||
"author": "user",
|
||||
"name": "test",
|
||||
"themes": [
|
||||
{
|
||||
"appearance": "light",
|
||||
"name": "Test Catppuccin",
|
||||
"style": {
|
||||
"editor": {
|
||||
"active_line": {
|
||||
"background": "#4c4f690d"
|
||||
},
|
||||
"active_line_number": "#8839ef",
|
||||
"background": "#eff1f5",
|
||||
"foreground": "#4c4f69",
|
||||
"gutter": {
|
||||
"background": "#eff1f5"
|
||||
},
|
||||
"highlighted_line": {
|
||||
"background": null
|
||||
},
|
||||
"invisible": "#7c7f9366",
|
||||
"line_number": "#8c8fa1",
|
||||
"subheader": {
|
||||
"background": "#e6e9ef"
|
||||
},
|
||||
"wrap_guide": "#acb0be"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
'';
|
||||
|
||||
testPath = ".config/zed/themes/test.json";
|
||||
in ''
|
||||
assertFileExists "home-files/${testPath}"
|
||||
assertFileContent "home-files/${testPath}" "${expectedContent}"
|
||||
'';
|
||||
}
|
Loading…
Add table
Reference in a new issue