about summary refs log tree commit diff
diff options
context:
space:
mode:
authorlinsui <linsui@inbox.lv>2024-03-14 18:40:47 +0800
committerlinsui <linsui555@gmail.com>2024-05-18 01:52:34 +0800
commit4826bc455d57af7cd75049ba3bf2f6a414a277bf (patch)
tree6fde296690f09bebb182fe7700dfb20666f0af4d
parentdf8237fde414c3dda22406be67ca0d4a7b3e2ef4 (diff)
nixos/yazi: support plugins and flavors
-rw-r--r--nixos/modules/programs/yazi.nix61
1 files changed, 56 insertions, 5 deletions
diff --git a/nixos/modules/programs/yazi.nix b/nixos/modules/programs/yazi.nix
index 5905f2afb946d..cfb26c01bfab5 100644
--- a/nixos/modules/programs/yazi.nix
+++ b/nixos/modules/programs/yazi.nix
@@ -5,7 +5,9 @@ let
 
   settingsFormat = pkgs.formats.toml { };
 
-  names = [ "yazi" "theme" "keymap" ];
+  files = [ "yazi" "theme" "keymap" ];
+
+  dirs = [ "plugins" "flavors" ];
 in
 {
   options.programs.yazi = {
@@ -15,7 +17,7 @@ in
 
     settings = lib.mkOption {
       type = with lib.types; submodule {
-        options = lib.listToAttrs (map
+        options = (lib.listToAttrs (map
           (name: lib.nameValuePair name (lib.mkOption {
             inherit (settingsFormat) type;
             default = { };
@@ -25,24 +27,73 @@ in
               See https://yazi-rs.github.io/docs/configuration/${name}/ for documentation.
             '';
           }))
-          names);
+          files));
       };
       default = { };
       description = ''
         Configuration included in `$YAZI_CONFIG_HOME`.
       '';
     };
+
+    initLua = lib.mkOption {
+      type = with lib.types; nullOr path;
+      default = null;
+      description = ''
+        The init.lua for Yazi itself.
+      '';
+    };
+
+  } // (lib.listToAttrs (map
+    (name: lib.nameValuePair name (lib.mkOption {
+      type = with lib.types; attrsOf (oneOf [ path package ]);
+      default = { };
+      description = ''
+        Lua plugins.
+
+        See https://yazi-rs.github.io/docs/${name}/overview/ for documentation.
+      '';
+    }))
+    dirs)
+  );
+
+    flavors = lib.mkOption {
+      type = with lib.types; attrsOf (oneOf [ path package ]);
+      default = { };
+      description = ''
+        Pre-made themes.
+
+        See https://yazi-rs.github.io/docs/flavors/overview/ for documentation.
+      '';
+      example = lib.literalExpression ''
+        {
+          foo = ./foo;
+          bar = pkgs.bar;
+        }
+      '';
+    };
+
   };
 
   config = lib.mkIf cfg.enable {
     environment = {
       systemPackages = [ cfg.package ];
       variables.YAZI_CONFIG_HOME = "/etc/yazi/";
-      etc = lib.attrsets.mergeAttrsList (map
+      etc = (lib.attrsets.mergeAttrsList (map
         (name: lib.optionalAttrs (cfg.settings.${name} != { }) {
           "yazi/${name}.toml".source = settingsFormat.generate "${name}.toml" cfg.settings.${name};
         })
-        names);
+        files)) // (lib.attrsets.mergeAttrsList (map
+        (dir:
+          if cfg.${dir} != { } then
+            (lib.mapAttrs'
+              (name: value: lib.nameValuePair "yazi/${dir}/${name}" { source = value; })
+              cfg.${dir}) else {
+            # Yazi checks the directories. If they don't exist it tries to create them and then crashes.
+            "yazi/${dir}".source = pkgs.emptyDirectory;
+          })
+        dirs)) // lib.optionalAttrs (cfg.initLua != null) {
+        "yazi/init.lua".source = cfg.initLua;
+      };
     };
   };
   meta = {