From 29519461834c08395b35f840811faf8c23e3b61c Mon Sep 17 00:00:00 2001 From: Nikita Pedorich Date: Fri, 2 Jun 2023 17:59:12 +0200 Subject: [PATCH] ripgrep: add module (#4017) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ripgrep: add module * ripgrep: Apply suggestions from code review Co-authored-by: Naïm Favier * ripgrep: fix maintainers Co-authored-by: Naïm Favier * ripgrep: rename config into arguments --------- Co-authored-by: Naïm Favier --- modules/lib/maintainers.nix | 6 +++ modules/modules.nix | 1 + modules/programs/ripgrep.nix | 51 +++++++++++++++++++ tests/default.nix | 1 + .../programs/ripgrep/custom-arguments.nix | 24 +++++++++ .../programs/ripgrep/default-arguments.nix | 12 +++++ tests/modules/programs/ripgrep/default.nix | 4 ++ 7 files changed, 99 insertions(+) create mode 100644 modules/programs/ripgrep.nix create mode 100644 tests/modules/programs/ripgrep/custom-arguments.nix create mode 100644 tests/modules/programs/ripgrep/default-arguments.nix create mode 100644 tests/modules/programs/ripgrep/default.nix diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 5b1d35d4b..2d2f551d9 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -394,4 +394,10 @@ github = "natecox"; githubId = 2782695; }; + pedorich-n = { + name = "Mykyta Pedorich"; + email = "pedorich.n@gmail.com"; + github = "pedorich-n"; + githubId = 15573098; + }; } diff --git a/modules/modules.nix b/modules/modules.nix index e219817d7..b79ca19a7 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -163,6 +163,7 @@ let ./programs/qutebrowser.nix ./programs/rbw.nix ./programs/readline.nix + ./programs/ripgrep.nix ./programs/rofi-pass.nix ./programs/rofi.nix ./programs/rtorrent.nix diff --git a/modules/programs/ripgrep.nix b/modules/programs/ripgrep.nix new file mode 100644 index 000000000..0adfccc8e --- /dev/null +++ b/modules/programs/ripgrep.nix @@ -0,0 +1,51 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let cfg = config.programs.ripgrep; +in { + meta.maintainers = [ hm.maintainers.pedorich-n ]; + + options = { + programs.ripgrep = { + enable = mkEnableOption "Ripgrep"; + + package = mkPackageOption pkgs "ripgrep" { }; + + configDir = mkOption { + type = types.str; + default = "${config.xdg.configHome}/ripgrep"; + defaultText = + literalExpression ''"''${config.xdg.configHome}/ripgrep"''; + description = '' + Directory where the ripgreprc file will be stored. + ''; + }; + + arguments = mkOption { + type = with types; listOf str; + default = [ ]; + example = [ "--max-columns-preview" "--colors=line:style:bold" ]; + description = '' + List of arguments to pass to ripgrep. Each item is given to ripgrep as a single command line argument verbatim. + + See + for an example configuration. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + home = { + packages = [ cfg.package ]; + + file."${cfg.configDir}/ripgreprc" = + mkIf (cfg.arguments != [ ]) { text = lib.concatLines cfg.arguments; }; + + sessionVariables = { + "RIPGREP_CONFIG_PATH" = "${cfg.configDir}/ripgreprc"; + }; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 272ecb4dc..c9a7d7458 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -115,6 +115,7 @@ import nmt { ./modules/programs/pubs ./modules/programs/qutebrowser ./modules/programs/readline + ./modules/programs/ripgrep ./modules/programs/sagemath ./modules/programs/sbt ./modules/programs/scmpuff diff --git a/tests/modules/programs/ripgrep/custom-arguments.nix b/tests/modules/programs/ripgrep/custom-arguments.nix new file mode 100644 index 000000000..e18efe827 --- /dev/null +++ b/tests/modules/programs/ripgrep/custom-arguments.nix @@ -0,0 +1,24 @@ +{ pkgs, config, ... }: { + config = { + programs.ripgrep = { + enable = true; + package = config.lib.test.mkStubPackage { name = "ripgrep"; }; + arguments = [ + "--max-columns-preview" + "--colors=line:style:bold" + "--no-require-git" + ]; + }; + + nmt.script = '' + assertFileExists home-files/.config/ripgrep/ripgreprc + assertFileContent home-files/.config/ripgrep/ripgreprc ${ + pkgs.writeText "ripgrep.expected" '' + --max-columns-preview + --colors=line:style:bold + --no-require-git + '' + } + ''; + }; +} diff --git a/tests/modules/programs/ripgrep/default-arguments.nix b/tests/modules/programs/ripgrep/default-arguments.nix new file mode 100644 index 000000000..43525316e --- /dev/null +++ b/tests/modules/programs/ripgrep/default-arguments.nix @@ -0,0 +1,12 @@ +{ config, ... }: { + config = { + programs.ripgrep = { + enable = true; + package = config.lib.test.mkStubPackage { name = "ripgrep"; }; + }; + + nmt.script = '' + assertPathNotExists home-files/.config/ripgrep/ripgreprc + ''; + }; +} diff --git a/tests/modules/programs/ripgrep/default.nix b/tests/modules/programs/ripgrep/default.nix new file mode 100644 index 000000000..6146a0bde --- /dev/null +++ b/tests/modules/programs/ripgrep/default.nix @@ -0,0 +1,4 @@ +{ + ripgrep-default-arguments = ./default-arguments.nix; + ripgrep-custom-arguments = ./custom-arguments.nix; +}