From 4dda6397d80800844b46e19bec648cdd6de98b25 Mon Sep 17 00:00:00 2001 From: Voreck Lukas Date: Sat, 16 Sep 2023 13:11:31 +0200 Subject: [PATCH] zellij: Add extraConfig option Mostly useful as a bridge to set keybinds until an idiomatic way has been implemented --- modules/programs/zellij.nix | 59 +++++++++++++++++-- tests/modules/programs/zellij/default.nix | 5 +- .../modules/programs/zellij/extra-config.nix | 41 +++++++++++++ 3 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 tests/modules/programs/zellij/extra-config.nix diff --git a/modules/programs/zellij.nix b/modules/programs/zellij.nix index 44a3d69f4..d0e2adc77 100644 --- a/modules/programs/zellij.nix +++ b/modules/programs/zellij.nix @@ -51,6 +51,39 @@ in { enableFishIntegration = mkEnableOption "Fish integration" // { default = false; }; + + extraConfig = mkOption { + 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"; } + } + } + ''; + description = '' + Extra configuration lines + Versions prior to 0.32.0 use Yaml + Versions after 0.32.0 use KDL + ''; + }; }; config = mkIf cfg.enable { @@ -59,14 +92,28 @@ in { # Zellij switched from yaml to KDL in version 0.32.0: # 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; - }; + ((cfg.settings != { } || cfg.extraConfig != "") + && (versionOlder cfg.package.version "0.32.0")) { + source = + let settings = yamlFormat.generate "zellij.yaml" cfg.settings; + in '' + ${settings} + + ${cfg.extraConfig} + ''; + }; xdg.configFile."zellij/config.kdl" = mkIf - (cfg.settings != { } && (versionAtLeast cfg.package.version "0.32.0")) { - text = lib.hm.generators.toKDL { } cfg.settings; - }; + ((cfg.settings != { } || cfg.extraConfig != "") + && (versionAtLeast cfg.package.version "0.32.0")) { + text = let settings = lib.hm.generators.toKDL { } cfg.settings; + in '' + ${settings} + + ${cfg.extraConfig} + ''; + + }; programs.bash.initExtra = mkIf cfg.enableBashIntegration (mkOrder 200 '' eval "$(zellij setup --generate-auto-start bash)" diff --git a/tests/modules/programs/zellij/default.nix b/tests/modules/programs/zellij/default.nix index f4b521386..2bdb3107a 100644 --- a/tests/modules/programs/zellij/default.nix +++ b/tests/modules/programs/zellij/default.nix @@ -1 +1,4 @@ -{ zellij-enable-shells = ./enable-shells.nix; } +{ + zellij-enable-shells = ./enable-shells.nix; + zellij-extra-config = ./extra-config.nix; +} diff --git a/tests/modules/programs/zellij/extra-config.nix b/tests/modules/programs/zellij/extra-config.nix new file mode 100644 index 000000000..aa892dbef --- /dev/null +++ b/tests/modules/programs/zellij/extra-config.nix @@ -0,0 +1,41 @@ +{ lib, ... }: + +let + testInput = '' + 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"; } + } + } + ''; +in { + programs = { + zellij = { + enable = true; + extraConfig = testInput; + }; + }; + + nmt.script = '' + assertFileExists home-files/.config/zellij/config.kdl + assertFileContains \ + home-files/.config/zellij/config.kdl \ + "${testInput}" + ''; +}