| 
4 | 4 |   pkgs,  | 
5 | 5 |   ...  | 
6 | 6 | }: let  | 
 | 7 | +  inherit (builtins) isPath;  | 
 | 8 | + | 
7 | 9 |   inherit (lib.modules) mkIf;  | 
8 |  | -  inherit (lib.options) mkOption mkEnableOption mkPackageOption;  | 
 | 10 | +  inherit (lib.attrsets) mapAttrs' nameValuePair;  | 
 | 11 | +  inherit (lib.options) mkOption mkEnableOption mkPackageOption literalExpression;  | 
 | 12 | +  inherit (lib.types) attrsOf nullOr either path lines package;  | 
9 | 13 | 
 
  | 
10 | 14 |   toml = pkgs.formats.toml {};  | 
11 | 15 | 
 
  | 
 | 
68 | 72 |         [yazi's theming configuration documentation]: https://yazi-rs.github.io/docs/configuration/theme  | 
69 | 73 |       '';  | 
70 | 74 |     };  | 
 | 75 | + | 
 | 76 | +    initLua = mkOption {  | 
 | 77 | +      type = nullOr (either lines path);  | 
 | 78 | +      default = null;  | 
 | 79 | +      example = literalExpression "./init.lua";  | 
 | 80 | +      description = ''  | 
 | 81 | +        The `init.lua` file written to {file}`$XDG_CONFIG_HOME/yazi/init.lua`.  | 
 | 82 | +        Please reference [yazi's plugins documentation] to get a better understanding the the file's usage.  | 
 | 83 | +
  | 
 | 84 | +        [yazi's plugins documentation]: https://yazi-rs.github.io/docs/plugins/overview/  | 
 | 85 | +      '';  | 
 | 86 | +    };  | 
 | 87 | + | 
 | 88 | +    plugins = mkOption {  | 
 | 89 | +      type = attrsOf (either path package);  | 
 | 90 | +      default = {};  | 
 | 91 | +      example = literalExpression ''  | 
 | 92 | +        {  | 
 | 93 | +          foo = ./foo;  | 
 | 94 | +          git = pkgs.yaziPlugins.git;  | 
 | 95 | +        };  | 
 | 96 | +      '';  | 
 | 97 | +      description = ''  | 
 | 98 | +        A list of plugins for Yazi, which is placed in the {file}`$XDG_CONFIG_HOME/yazi/plugins/` folder.  | 
 | 99 | +        Please reference [yazi's plugins documentation] to get a better understanding of plugins.  | 
 | 100 | +
  | 
 | 101 | +        [yazi's plugins documentation]: https://yazi-rs.github.io/docs/plugins/overview/  | 
 | 102 | +      '';  | 
 | 103 | +    };  | 
 | 104 | + | 
 | 105 | +    flavors = mkOption {  | 
 | 106 | +      type = attrsOf (either path package);  | 
 | 107 | +      default = {};  | 
 | 108 | +      example = literalExpression ''  | 
 | 109 | +        {  | 
 | 110 | +          foo = ./foo;  | 
 | 111 | +          bar = fetchFromGitHub { ... };  | 
 | 112 | +        };  | 
 | 113 | +      '';  | 
 | 114 | +      description = ''  | 
 | 115 | +        A list of "flavors", or pre-made themes for Yazi, which is placed in the {file}`$XDG_CONFIG_HOME/yazi/flavors` folder.  | 
 | 116 | +        Please reference [yazi's flavors documentation] to get a better understanding of flavors.  | 
 | 117 | +
  | 
 | 118 | +        [yazi's flavors documentation]: https://yazi-rs.github.io/docs/flavors/overview  | 
 | 119 | +      '';  | 
 | 120 | +    };  | 
71 | 121 |   };  | 
72 | 122 | 
 
  | 
73 | 123 |   config = mkIf cfg.enable {  | 
74 | 124 |     packages = mkIf (cfg.package != null) [cfg.package];  | 
75 | 125 | 
 
  | 
76 |  | -    xdg.config.files = {  | 
77 |  | -      "yazi/yazi.toml" = mkIf (cfg.settings != {}) {  | 
78 |  | -        source = toml.generate "yazi-config.toml" cfg.settings;  | 
79 |  | -      };  | 
80 |  | -      "yazi/keymap.toml" = mkIf (cfg.keymap != {}) {  | 
81 |  | -        source = toml.generate "yazi-keymap-config.toml" cfg.keymap;  | 
82 |  | -      };  | 
83 |  | -      "yazi/theme.toml" = mkIf (cfg.theme != {}) {  | 
84 |  | -        source = toml.generate "yazi-theme-config.toml" cfg.theme;  | 
85 |  | -      };  | 
86 |  | -    };  | 
 | 126 | +    xdg.config.files =  | 
 | 127 | +      {  | 
 | 128 | +        "yazi/yazi.toml" = mkIf (cfg.settings != {}) {  | 
 | 129 | +          source = toml.generate "yazi-config.toml" cfg.settings;  | 
 | 130 | +        };  | 
 | 131 | +        "yazi/keymap.toml" = mkIf (cfg.keymap != {}) {  | 
 | 132 | +          source = toml.generate "yazi-keymap-config.toml" cfg.keymap;  | 
 | 133 | +        };  | 
 | 134 | +        "yazi/theme.toml" = mkIf (cfg.theme != {}) {  | 
 | 135 | +          source = toml.generate "yazi-theme-config.toml" cfg.theme;  | 
 | 136 | +        };  | 
 | 137 | +        "yazi/init.lua" = mkIf (cfg.luaInit != null) (  | 
 | 138 | +          if isPath cfg.initLua  | 
 | 139 | +          then {source = cfg.initLua;}  | 
 | 140 | +          else {text = cfg.initLua;}  | 
 | 141 | +        );  | 
 | 142 | +      }  | 
 | 143 | +      // (mapAttrs' (name: plugin: nameValuePair "yazi/plugins/${name}.yazi" {source = plugin;}) cfg.plugins)  | 
 | 144 | +      // (mapAttrs' (name: flavor: nameValuePair "yazi/flavors/${name}.yazi" {source = flavor;}) cfg.flavors);  | 
87 | 145 |   };  | 
88 | 146 | }  | 
0 commit comments