Skip to content

Commit

Permalink
zellij: Add extraConfig
Browse files Browse the repository at this point in the history
This allows working around [nix-community#4659](nix-community#4659)

While fixing `toKDL` might be fun, I just don't think it's a good use of
anyone's time.

---

This is still untested.
  • Loading branch information
Dietr1ch committed Nov 14, 2024
1 parent 35b0550 commit 26284b5
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 4 deletions.
43 changes: 40 additions & 3 deletions modules/programs/zellij.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,44 @@ in {
'';
description = ''
Configuration written to
{file}`$XDG_CONFIG_HOME/zellij/config.yaml`.
{file}`$XDG_CONFIG_HOME/zellij/config.kdl`.
See <https://zellij.dev/documentation> for the full
list of options.
'';
};
extraConfig = lib.mkOption {
description = ''
Extra configuration lines to add to `$XDG_CONFIG_HOME/zellij/config.kdl`.
This does not support zellij.yaml and it's mostly a workaround for https://github.com/nix-community/home-manager/issues/4659.
'';
type = lib.types.lines;
default = "";
example = ''
keybinds {
// keybinds are divided into modes
normal {
// bind instructions can include one or more keys (both keys will be bound separately)
// bind keys can include one or more actions (all actions will be performed with no sequential guarantees)
bind "Ctrl g" { SwitchToMode "locked"; }
bind "Ctrl p" { SwitchToMode "pane"; }
bind "Alt n" { NewPane; }
bind "Alt h" "Alt Left" { MoveFocusOrTab "Left"; }
}
pane {
bind "h" "Left" { MoveFocus "Left"; }
bind "l" "Right" { MoveFocus "Right"; }
bind "j" "Down" { MoveFocus "Down"; }
bind "k" "Up" { MoveFocus "Up"; }
bind "p" { SwitchFocus; }
}
locked {
bind "Ctrl g" { SwitchToMode "normal"; }
}
}
'';
};

enableBashIntegration = mkEnableOption "Bash integration" // {
default = false;
Expand All @@ -61,12 +93,17 @@ in {
# https://github.com/zellij-org/zellij/releases/tag/v0.32.0
xdg.configFile."zellij/config.yaml" = mkIf
(cfg.settings != { } && (versionOlder cfg.package.version "0.32.0")) {
source = yamlFormat.generate "zellij.yaml" cfg.settings;
source = (yamlFormat.generate "zellij.yaml" cfg.settings);
};

xdg.configFile."zellij/config.kdl" = mkIf
(cfg.settings != { } && (versionAtLeast cfg.package.version "0.32.0")) {
text = lib.hm.generators.toKDL { } cfg.settings;
text = (lib.hm.generators.toKDL { } cfg.settings)
+ lib.optionalString (cfg.extraConfig != "") (''
// extraConfig
'' + cfg.extraConfig);
};

programs.bash.initExtra = mkIf cfg.enableBashIntegration (mkOrder 200 ''
Expand Down
37 changes: 37 additions & 0 deletions tests/modules/programs/zellij/config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{ lib, ... }:

{
programs = {
zellij = {
enable = true;

settings = {
default_layout = "welcome";
};
extraConfig = ''
This_could_have_been_json {
}
'';
};
};

test.stubs = {
zellij = { };
};

nmt.script = ''
assertFileExists home-files/.config/zellij/config.kdl
assertFileContains \
home-files/.config/zellij/config.kdl \
'default_layout "welcome"'
assertFileContains \
home-files/.config/zellij/config.kdl \
'// extraConfig'
assertFileContains \
home-files/.config/zellij/config.kdl \
'This_could_have_been_json'
'';
}
5 changes: 4 additions & 1 deletion tests/modules/programs/zellij/default.nix
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{ zellij-enable-shells = ./enable-shells.nix; }
{
zellij-config = ./config.nix;
zellij-enable-shells = ./enable-shells.nix;
}

0 comments on commit 26284b5

Please sign in to comment.