From b84767a145e04d07ef699d266161cda605f48b11 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Thu, 13 Jul 2023 22:34:47 +0300 Subject: [PATCH] xplr: add module --- modules/misc/news.nix | 7 ++++ modules/programs/xplr.nix | 72 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 modules/programs/xplr.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 0538d767b..fea907858 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1179,6 +1179,13 @@ in A new module is available: 'services.git-sync'. ''; } + + { + time = "2023-08-15T15:45:45+00:00"; + message = '' + A new module is available: 'programs.xplr'. + ''; + } ]; }; } diff --git a/modules/programs/xplr.nix b/modules/programs/xplr.nix new file mode 100644 index 000000000..22aca027d --- /dev/null +++ b/modules/programs/xplr.nix @@ -0,0 +1,72 @@ +{ config, lib, pkgs, ... }: +let + inherit (lib) + concatStringsSep types mkIf mkOption mkEnableOption mkPackageOption + literalExpression; + + cfg = config.programs.xplr; + + initialConfig = '' + version = '${cfg.package.version}' + ''; + + # We provide a default version line within the configuration file, which is + # obtained from the package's attributes. Merge the initial configFile, a + # mapped list of plugins and then the user defined configuration to obtain the + # final configuration. + pluginPath = if cfg.plugins != [ ] then + ('' + package.path= + '' + (concatStringsSep " ..\n" + (map (p: ''"${p}/init.lua;${p}/?.lua;"'') cfg.plugins)) + '' + .. + package.path + '') + else + "\n"; + + configFile = initialConfig + pluginPath + cfg.extraConfig; +in { + meta.maintainers = [ lib.maintainers.NotAShelf ]; + + options.programs.xplr = { + enable = mkEnableOption "xplr, terminal UI based file explorer"; + + package = mkPackageOption pkgs "xplr" { }; + + plugins = mkOption { + type = with types; nullOr (listOf (either package str)); + default = [ ]; + defaultText = literalExpression "[]"; + description = '' + Plugins to be added to your configuration file. + + Must be a package, an absolute plugin path, or string to be recognized + by xplr. Paths will be relative to + {file}`$XDG_CONFIG_HOME/xplr/init.lua` unless they are absolute. + ''; + }; + + extraConfig = mkOption { + type = types.lines; + default = ""; + example = literalExpression '' + require("wl-clipboard").setup { + copy_command = "wl-copy -t text/uri-list", + paste_command = "wl-paste", + keep_selection = true, + } + ''; + description = '' + Extra xplr configuration. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + xdg.configFile."xplr/init.lua".source = + pkgs.writeText "init.lua" configFile; + }; +}