mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
zed-editor: option to generate immutable settings
This commit is contained in:
parent
80437a57ca
commit
5c54b182ab
6 changed files with 220 additions and 15 deletions
|
|
@ -54,6 +54,33 @@ in
|
|||
description = "Extra packages available to Zed.";
|
||||
};
|
||||
|
||||
mutableUserSettings = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
example = false;
|
||||
description = ''
|
||||
Whether user settings (settings.json) can be updated by zed.
|
||||
'';
|
||||
};
|
||||
|
||||
mutableUserKeymaps = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
example = false;
|
||||
description = ''
|
||||
Whether user keymaps (keymap.json) can be updated by zed.
|
||||
'';
|
||||
};
|
||||
|
||||
mutableUserTasks = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
example = false;
|
||||
description = ''
|
||||
Whether user tasks (tasks.json) can be updated by zed.
|
||||
'';
|
||||
};
|
||||
|
||||
userSettings = mkOption {
|
||||
type = jsonFormat.type;
|
||||
default = { };
|
||||
|
|
@ -191,14 +218,14 @@ in
|
|||
);
|
||||
|
||||
home.activation = mkMerge [
|
||||
(mkIf (mergedSettings != { }) {
|
||||
(mkIf (cfg.mutableUserSettings && mergedSettings != { }) {
|
||||
zedSettingsActivation = lib.hm.dag.entryAfter [ "linkGeneration" ] (
|
||||
impureConfigMerger "{}" "$dynamic * $static" "${config.xdg.configHome}/zed/settings.json" (
|
||||
jsonFormat.generate "zed-user-settings" mergedSettings
|
||||
)
|
||||
);
|
||||
})
|
||||
(mkIf (cfg.userKeymaps != [ ]) {
|
||||
(mkIf (cfg.mutableUserKeymaps && cfg.userKeymaps != [ ]) {
|
||||
zedKeymapActivation = lib.hm.dag.entryAfter [ "linkGeneration" ] (
|
||||
impureConfigMerger "[]"
|
||||
"$dynamic + $static | group_by(.context) | map(reduce .[] as $item ({}; . * $item))"
|
||||
|
|
@ -206,7 +233,7 @@ in
|
|||
(jsonFormat.generate "zed-user-keymaps" cfg.userKeymaps)
|
||||
);
|
||||
})
|
||||
(mkIf (cfg.userTasks != [ ]) {
|
||||
(mkIf (cfg.mutableUserTasks && cfg.userTasks != [ ]) {
|
||||
zedTasksActivation = lib.hm.dag.entryAfter [ "linkGeneration" ] (
|
||||
impureConfigMerger "[]"
|
||||
"$dynamic + $static | group_by(.label) | map(reduce .[] as $item ({}; . * $item))"
|
||||
|
|
@ -216,18 +243,29 @@ in
|
|||
})
|
||||
];
|
||||
|
||||
xdg.configFile = lib.mapAttrs' (
|
||||
n: v:
|
||||
lib.nameValuePair "zed/themes/${n}.json" {
|
||||
source =
|
||||
if lib.isString v then
|
||||
pkgs.writeText "zed-theme-${n}" v
|
||||
else if builtins.isPath v || lib.isStorePath v then
|
||||
v
|
||||
else
|
||||
jsonFormat.generate "zed-theme-${n}" v;
|
||||
}
|
||||
) cfg.themes;
|
||||
xdg.configFile = mkMerge [
|
||||
(lib.mapAttrs' (
|
||||
n: v:
|
||||
lib.nameValuePair "zed/themes/${n}.json" {
|
||||
source =
|
||||
if lib.isString v then
|
||||
pkgs.writeText "zed-theme-${n}" v
|
||||
else if builtins.isPath v || lib.isStorePath v then
|
||||
v
|
||||
else
|
||||
jsonFormat.generate "zed-theme-${n}" v;
|
||||
}
|
||||
) cfg.themes)
|
||||
(mkIf (!cfg.mutableUserSettings && mergedSettings != { }) {
|
||||
"zed/settings.json".source = jsonFormat.generate "zed-user-settings" mergedSettings;
|
||||
})
|
||||
(mkIf (!cfg.mutableUserKeymaps && cfg.userKeymaps != { }) {
|
||||
"zed/keymap.json".source = jsonFormat.generate "zed-user-keymaps" cfg.userKeymaps;
|
||||
})
|
||||
(mkIf (!cfg.mutableUserTasks && cfg.userTasks != [ ]) {
|
||||
"zed/tasks.json".source = jsonFormat.generate "zed-user-tasks" cfg.userTasks;
|
||||
})
|
||||
];
|
||||
|
||||
assertions = [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
{
|
||||
zed-extensions = ./extensions.nix;
|
||||
zed-extensions-immutable = ./extensions-immutable.nix;
|
||||
zed-install-remote-server = ./install-remote-server.nix;
|
||||
zed-keymap = ./keymap.nix;
|
||||
zed-keymap-immutable = ./keymap-immutable.nix;
|
||||
zed-keymap-empty = ./keymap-empty.nix;
|
||||
zed-settings = ./settings.nix;
|
||||
zed-settings-immutable = ./settings-immutable.nix;
|
||||
zed-settings-empty = ./settings-empty.nix;
|
||||
zed-tasks = ./tasks.nix;
|
||||
zed-tasks-immutable = ./tasks-immutable.nix;
|
||||
zed-tasks-empty = ./tasks-empty.nix;
|
||||
zed-themes = ./themes;
|
||||
}
|
||||
|
|
|
|||
31
tests/modules/programs/zed-editor/extensions-immutable.nix
Normal file
31
tests/modules/programs/zed-editor/extensions-immutable.nix
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
{ config, ... }:
|
||||
|
||||
{
|
||||
programs.zed-editor = {
|
||||
enable = true;
|
||||
package = config.lib.test.mkStubPackage { };
|
||||
mutableUserSettings = false;
|
||||
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}"
|
||||
'';
|
||||
}
|
||||
48
tests/modules/programs/zed-editor/keymap-immutable.nix
Normal file
48
tests/modules/programs/zed-editor/keymap-immutable.nix
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# Test custom keymap functionality
|
||||
{ config, ... }:
|
||||
|
||||
{
|
||||
programs.zed-editor = {
|
||||
enable = true;
|
||||
package = config.lib.test.mkStubPackage { };
|
||||
mutableUserKeymaps = false;
|
||||
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}"
|
||||
'';
|
||||
}
|
||||
40
tests/modules/programs/zed-editor/settings-immutable.nix
Normal file
40
tests/modules/programs/zed-editor/settings-immutable.nix
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# Test custom keymap functionality
|
||||
{ config, ... }:
|
||||
|
||||
{
|
||||
programs.zed-editor = {
|
||||
enable = true;
|
||||
package = config.lib.test.mkStubPackage { };
|
||||
mutableUserSettings = false;
|
||||
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" ''
|
||||
{
|
||||
"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}"
|
||||
'';
|
||||
}
|
||||
44
tests/modules/programs/zed-editor/tasks-immutable.nix
Normal file
44
tests/modules/programs/zed-editor/tasks-immutable.nix
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# Test custom keymap functionality
|
||||
{ config, ... }:
|
||||
|
||||
{
|
||||
programs.zed-editor = {
|
||||
enable = true;
|
||||
package = config.lib.test.mkStubPackage { };
|
||||
mutableUserTasks = false;
|
||||
userTasks = [
|
||||
{
|
||||
label = "Format Code";
|
||||
command = "nix";
|
||||
args = [
|
||||
"fmt"
|
||||
"$ZED_WORKTREE_ROOT"
|
||||
];
|
||||
allow_concurrent_runs = false;
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
nmt.script =
|
||||
let
|
||||
expectedContent = builtins.toFile "expected.json" ''
|
||||
[
|
||||
{
|
||||
"allow_concurrent_runs": false,
|
||||
"args": [
|
||||
"fmt",
|
||||
"$ZED_WORKTREE_ROOT"
|
||||
],
|
||||
"command": "nix",
|
||||
"label": "Format Code"
|
||||
}
|
||||
]
|
||||
'';
|
||||
|
||||
settingsPath = ".config/zed/tasks.json";
|
||||
in
|
||||
''
|
||||
assertFileExists "home-files/${settingsPath}"
|
||||
assertFileContent "home-files/${settingsPath}" "${expectedContent}"
|
||||
'';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue