fork/home-manager

git clone https://git.julia.blue/fork/home-manager

NotAShelfxplr: add moduleb84767a1

master
1.9 KiB72 linesraw
1{ config, lib, pkgs, ... }:
2let
3  inherit (lib)
4    concatStringsSep types mkIf mkOption mkEnableOption mkPackageOption
5    literalExpression;
6
7  cfg = config.programs.xplr;
8
9  initialConfig = ''
10    version = '${cfg.package.version}'
11  '';
12
13  # We provide a default version line within the configuration file, which is
14  # obtained from the package's attributes. Merge the initial configFile, a
15  # mapped list of plugins and then the user defined configuration to obtain the
16  # final configuration.
17  pluginPath = if cfg.plugins != [ ] then
18    (''
19      package.path=
20    '' + (concatStringsSep " ..\n"
21      (map (p: ''"${p}/init.lua;${p}/?.lua;"'') cfg.plugins)) + ''
22         ..
23        package.path
24      '')
25  else
26    "\n";
27
28  configFile = initialConfig + pluginPath + cfg.extraConfig;
29in {
30  meta.maintainers = [ lib.maintainers.NotAShelf ];
31
32  options.programs.xplr = {
33    enable = mkEnableOption "xplr, terminal UI based file explorer";
34
35    package = mkPackageOption pkgs "xplr" { };
36
37    plugins = mkOption {
38      type = with types; nullOr (listOf (either package str));
39      default = [ ];
40      defaultText = literalExpression "[]";
41      description = ''
42        Plugins to be added to your configuration file.
43
44        Must be a package, an absolute plugin path, or string to be recognized
45        by xplr. Paths will be relative to
46        {file}`$XDG_CONFIG_HOME/xplr/init.lua` unless they are absolute.
47      '';
48    };
49
50    extraConfig = mkOption {
51      type = types.lines;
52      default = "";
53      example = literalExpression ''
54        require("wl-clipboard").setup {
55          copy_command = "wl-copy -t text/uri-list",
56          paste_command = "wl-paste",
57          keep_selection = true,
58        }
59      '';
60      description = ''
61        Extra xplr configuration.
62      '';
63    };
64  };
65
66  config = mkIf cfg.enable {
67    home.packages = [ cfg.package ];
68
69    xdg.configFile."xplr/init.lua".source =
70      pkgs.writeText "init.lua" configFile;
71  };
72}