diff --git a/modules/programs/zellij.nix b/modules/programs/zellij.nix index 44a3d69f..d0e2adc7 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 f4b52138..2bdb3107 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 00000000..aa892dbe --- /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}" + ''; +}