Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zellij: add support for layouts #4612

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 47 additions & 8 deletions modules/programs/zellij.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ let

cfg = config.programs.zellij;
yamlFormat = pkgs.formats.yaml { };

in {
meta.maintainers = [ hm.maintainers.mainrs ];

Expand Down Expand Up @@ -40,6 +39,33 @@ in {
'';
};

layouts = mkOption {
type = types.attrsOf types.lines;
default = { };
example = literalExpression ''
{
# redefining the default layout
default = '''
layout {
pane size=1 borderless=true {
plugin location=\"zellij:tab-bar\"
}
pane
pane size=2 borderless=true {
plugin location=\"zellij:status-bar\"
}
}
'''
}
'';
description = ''
A set of zellij layouts written to {file}`$XDG_CONFIG_HOME/zellij/layouts/`.
Each key corresponds to one layout with the key being its name.

See <https://zellij.dev/documentation/layouts> for the full list of options.
'';
};

enableBashIntegration = mkEnableOption "Bash integration" // {
default = false;
};
Expand All @@ -58,15 +84,27 @@ 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;
xdg.configFile = let
config = {
"zellij/config.yaml" = mkIf
(cfg.settings != { } && (versionOlder cfg.package.version "0.32.0")) {
source = yamlFormat.generate "zellij.yaml" cfg.settings;
};
"zellij/config.kdl" = mkIf (cfg.settings != { }
&& (versionAtLeast cfg.package.version "0.32.0")) {
text = lib.hm.generators.toKDL { } cfg.settings;
};
};

xdg.configFile."zellij/config.kdl" = mkIf
(cfg.settings != { } && (versionAtLeast cfg.package.version "0.32.0")) {
text = lib.hm.generators.toKDL { } cfg.settings;
};
extension =
if (versionOlder cfg.package.version "0.32.0") then "yaml" else "kdl";
layouts = lib.mapAttrs' (name: layout: {
name = "zellij/layouts/${name}.${extension}";
value = {
source = pkgs.writeText "zellij-layout-${name}.${extension}" layout;
};
}) cfg.layouts;
in config // layouts;

programs.bash.initExtra = mkIf cfg.enableBashIntegration (mkOrder 200 ''
eval "$(zellij setup --generate-auto-start bash)"
Expand All @@ -82,3 +120,4 @@ in {
'');
};
}