1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-23 03:29:45 +01:00

zed-editor: add module

Add a simple module for zed-editor, a simple editor written in Rust.
This commit is contained in:
libewa 2024-05-26 11:41:16 +02:00 committed by Robert Helgesson
parent 9c1a1c7df4
commit e78cbb2027
No known key found for this signature in database
GPG key ID: 96E745BD17AA17ED
9 changed files with 210 additions and 0 deletions

View file

@ -349,6 +349,11 @@
githubId = 12465195;
name = "Bruno BELANYI";
};
libewa = {
email = "libewa-git@icloud.com";
github = "libewa";
githubId = 67926131;
};
malvo = {
email = "malte@malvo.org";
github = "malte-v";

View file

@ -1770,6 +1770,16 @@ in {
ideas from mutt.
'';
}
{
time = "2024-10-17T13:07:55+00:00";
message = ''
A new module is available: 'programs.zed-editor'.
Zed is a fast text editor for macOS and Linux.
See https://zed.dev for more.
'';
}
];
};
}

View file

@ -262,6 +262,7 @@ let
./programs/yt-dlp.nix
./programs/z-lua.nix
./programs/zathura.nix
./programs/zed-editor.nix
./programs/zellij.nix
./programs/zk.nix
./programs/zoxide.nix

View file

@ -0,0 +1,89 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.zed-editor;
jsonFormat = pkgs.formats.json { };
mergedSettings = cfg.userSettings // {
# this part by @cmacrae
auto_install_extensions = lib.genAttrs cfg.extensions (_: true);
};
in {
meta.maintainers = [ hm.maintainers.libewa ];
options = {
# 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";
package = mkPackageOption pkgs "zed-editor" { };
userSettings = mkOption {
type = jsonFormat.type;
default = { };
example = literalExpression ''
{
features = {
copilot = false;
};
telemetry = {
metrics = false;
};
vim_mode = false;
ui_font_size = 16;
buffer_font_size = 16;
}
'';
description = ''
Configuration written to Zed's {file}`settings.json`.
'';
};
userKeymaps = mkOption {
type = jsonFormat.type;
default = { };
example = literalExpression ''
[
{
context = "Workspace";
bindings = {
ctrl-shift-t = "workspace::NewTerminal";
};
};
]
'';
description = ''
Configuration written to Zed's {file}`keymap.json`.
'';
};
extensions = mkOption {
type = types.listOf types.str;
default = [ ];
example = literalExpression ''
[ "swift" "nix" "xy-zed" ]
'';
description = ''
A list of the extensions Zed should install on startup.
Use the name of a repository in the [extension list](https://github.com/zed-industries/extensions/tree/main/extensions).
'';
};
};
};
config = mkIf cfg.enable {
home.packages = [ cfg.package ];
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;
});
};
}

View file

@ -161,6 +161,7 @@ in import nmtSrc {
./modules/programs/watson
./modules/programs/wezterm
./modules/programs/yazi
./modules/programs/zed-editor
./modules/programs/zellij
./modules/programs/zk
./modules/programs/zplug

View file

@ -0,0 +1,5 @@
{
zed-extensions = ./extensions.nix;
zed-keymap = ./keymap.nix;
zed-settings = ./settings.nix;
}

View file

@ -0,0 +1,24 @@
{ config, ... }:
{
programs.zed-editor = {
enable = true;
package = config.lib.test.mkStubPackage { };
extensions = [ "swift" "html" "xy-zed" ];
};
nmt.script = let
expectedContent = builtins.toFile "expected.json" ''
{
"auto_install_extensions": {
"html": true,
"swift": true,
"xy-zed": true
}
}
'';
in ''
assertFileExists "home-files/.config/zed/settings.json"
assertFileContent "home-files/.config/zed/settings.json" "${expectedContent}"
'';
}

View file

@ -0,0 +1,39 @@
# Test custom keymap functionality
{ config, ... }:
{
programs.zed-editor = {
enable = true;
package = config.lib.test.mkStubPackage { };
userKeymaps = [
{ bindings = { up = "menu::SelectPrev"; }; }
{
context = "Editor";
bindings = { escape = "editor::Cancel"; };
}
];
};
nmt.script = let
expectedContent = builtins.toFile "expected.json" ''
[
{
"bindings": {
"up": "menu::SelectPrev"
}
},
{
"bindings": {
"escape": "editor::Cancel"
},
"context": "Editor"
}
]
'';
keymapPath = ".config/zed/keymap.json";
in ''
assertFileExists "home-files/${keymapPath}"
assertFileContent "home-files/${keymapPath}" "${expectedContent}"
'';
}

View file

@ -0,0 +1,36 @@
# Test custom keymap functionality
{ config, ... }:
{
programs.zed-editor = {
enable = true;
package = config.lib.test.mkStubPackage { };
userSettings = {
theme = "XY-Zed";
features = { copilot = false; };
vim_mode = false;
ui_font_size = 16;
buffer_font_size = 16;
};
};
nmt.script = let
expectedContent = builtins.toFile "expected.json" ''
{
"auto_install_extensions": {},
"buffer_font_size": 16,
"features": {
"copilot": false
},
"theme": "XY-Zed",
"ui_font_size": 16,
"vim_mode": false
}
'';
settingsPath = ".config/zed/settings.json";
in ''
assertFileExists "home-files/${settingsPath}"
assertFileContent "home-files/${settingsPath}" "${expectedContent}"
'';
}