mirror of
https://github.com/nix-community/home-manager.git
synced 2026-10-31 17:20:03 +00:00
Turning off mutableUserSettings, mutableUserKeymaps, mutableUserTasks, or mutableUserDebug left the previously merged regular file in place. When it matched the declared config it was never replaced by a link, so it stayed writable and collided once the settings changed. Run mkImpureConfigCleanup for each of the four files whose toggle is off. The conditions that link those files now live in one binding that both the file entries and the cleanup use, so they cannot drift apart. The test checks zed's wiring: which files get a cleanup, where it runs, and that a file disabled through home.file or xdg.configFile gets none. The removal itself is covered by the helper's tests. Merging behavior is unchanged.
82 lines
2.0 KiB
Nix
82 lines
2.0 KiB
Nix
mode:
|
|
|
|
{ config, lib, ... }:
|
|
|
|
let
|
|
mutable = mode == "mutable";
|
|
disabled = mode == "disabled";
|
|
cleanup = config.home.activation.zedImmutableConfig or null;
|
|
files = [
|
|
"settings"
|
|
"keymap"
|
|
"tasks"
|
|
"debug"
|
|
];
|
|
# The disabled mode turns off one file through each option path and keeps
|
|
# the others, so only the enabled entries get a cleanup.
|
|
disabledFiles = lib.optionals disabled [
|
|
"settings"
|
|
"keymap"
|
|
];
|
|
linkedFiles = lib.subtractLists disabledFiles files;
|
|
cleansUp = name: cleanup != null && lib.hasInfix ".config/zed/${name}.json" cleanup.data;
|
|
in
|
|
{
|
|
programs.zed-editor = {
|
|
enable = true;
|
|
mutableUserSettings = mutable;
|
|
mutableUserKeymaps = mutable;
|
|
mutableUserTasks = mutable;
|
|
mutableUserDebug = mutable;
|
|
userSettings = {
|
|
theme = "XY-Zed";
|
|
vim_mode = false;
|
|
};
|
|
userKeymaps = [
|
|
{
|
|
context = "Editor";
|
|
bindings.ctrl-s = "workspace::Save";
|
|
}
|
|
];
|
|
userTasks = [
|
|
{
|
|
label = "Build";
|
|
command = "nix build";
|
|
}
|
|
];
|
|
userDebug = [
|
|
{
|
|
label = "Debug";
|
|
adapter = "CodeLLDB";
|
|
}
|
|
];
|
|
};
|
|
|
|
home.file = lib.mkIf disabled {
|
|
"${config.xdg.configHome}/zed/settings.json".enable = lib.mkForce false;
|
|
};
|
|
xdg.configFile = lib.mkIf disabled {
|
|
"zed/keymap.json".enable = false;
|
|
};
|
|
|
|
# Which files get a cleanup and where it runs; the removal itself is covered
|
|
# by the mkImpureConfigCleanup tests.
|
|
nmt.script =
|
|
assert (cleanup != null) == !mutable;
|
|
assert
|
|
cleanup == null || (cleanup.after == [ "writeBoundary" ] && cleanup.before == [ "linkGeneration" ]);
|
|
assert lib.all cleansUp (lib.optionals (!mutable) linkedFiles);
|
|
assert !lib.any cleansUp disabledFiles;
|
|
lib.concatMapStrings (
|
|
name:
|
|
if mutable || lib.elem name disabledFiles then
|
|
''
|
|
assertPathNotExists "home-files/.config/zed/${name}.json"
|
|
''
|
|
else
|
|
''
|
|
assertFileExists "home-files/.config/zed/${name}.json"
|
|
''
|
|
) files;
|
|
}
|