mirror of
https://github.com/nix-community/home-manager.git
synced 2025-03-31 04:04:32 +00:00
ripgrep-all: Add module (#5459)
This commit is contained in:
parent
338b2eabdf
commit
2321c6889b
6 changed files with 172 additions and 0 deletions
|
@ -226,6 +226,7 @@ let
|
|||
./programs/readline.nix
|
||||
./programs/rio.nix
|
||||
./programs/ripgrep.nix
|
||||
./programs/ripgrep-all.nix
|
||||
./programs/rofi-pass.nix
|
||||
./programs/rofi.nix
|
||||
./programs/rtorrent.nix
|
||||
|
|
102
modules/programs/ripgrep-all.nix
Normal file
102
modules/programs/ripgrep-all.nix
Normal file
|
@ -0,0 +1,102 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
cfg = config.programs.ripgrep-all;
|
||||
configPath = if pkgs.stdenv.hostPlatform.isDarwin then
|
||||
"Library/Application Support/ripgrep-all/config.jsonc"
|
||||
else
|
||||
"${config.xdg.configHome}/ripgrep-all/config.jsonc";
|
||||
customAdapter = lib.types.submodule {
|
||||
# Descriptions are largely copied from https://github.com/phiresky/ripgrep-all/blob/v1.0.0-alpha.5/src/adapters/custom.rs
|
||||
options = {
|
||||
name = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description =
|
||||
"The unique identifier and name of this adapter; must only include a-z, 0-9, _";
|
||||
};
|
||||
version = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 1;
|
||||
description =
|
||||
"The version identifier used to key cache entries; change if the configuration or program changes";
|
||||
};
|
||||
description = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "A description of this adapter; shown in rga's help";
|
||||
};
|
||||
extensions = lib.mkOption {
|
||||
type = with lib.types; listOf str;
|
||||
description = "The file extensions this adapter supports";
|
||||
example = [ "pdf" ];
|
||||
};
|
||||
mimetypes = lib.mkOption {
|
||||
type = with lib.types; nullOr (listOf str);
|
||||
default = null;
|
||||
description =
|
||||
"If not null and --rga-accurate is enabled, mime type matching is used instead of file name matching";
|
||||
example = [ "application/pdf" ];
|
||||
};
|
||||
binary = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
description = "The path of the binary to run";
|
||||
};
|
||||
args = lib.mkOption {
|
||||
type = with lib.types; listOf str;
|
||||
default = [ ];
|
||||
description =
|
||||
"The output path hint; the placeholders are the same as for rga's `args`";
|
||||
};
|
||||
disabled_by_default = lib.mkOption {
|
||||
type = with lib.types; nullOr bool;
|
||||
default = null;
|
||||
description = "If true, the adapter will be disabled by default";
|
||||
};
|
||||
match_only_by_mime = lib.mkOption {
|
||||
type = with lib.types; nullOr bool;
|
||||
default = null;
|
||||
description =
|
||||
"if --rga-accurate, only match by mime types, ignore extensions completely";
|
||||
};
|
||||
output_path_hint = lib.mkOption {
|
||||
type = with lib.types; nullOr str;
|
||||
default = null;
|
||||
description =
|
||||
"Setting this is useful if the output format is not plain text (.txt) but instead some other format that should be passed to another adapter";
|
||||
example = "$${input_virtual_path}.txt.asciipagebreaks";
|
||||
};
|
||||
};
|
||||
};
|
||||
in {
|
||||
meta.maintainers = with lib.maintainers; [ lafrenierejm ];
|
||||
|
||||
options = {
|
||||
programs.ripgrep-all = {
|
||||
enable = lib.mkEnableOption "ripgrep-all (rga)";
|
||||
|
||||
package = lib.mkPackageOption pkgs "ripgrep-all" { nullable = true; };
|
||||
|
||||
custom_adapters = lib.mkOption {
|
||||
type = lib.types.listOf customAdapter;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Custom adapters that invoke external preprocessing scripts.
|
||||
See <link xlink:href="https://github.com/phiresky/ripgrep-all/wiki#custom-adapters"/>.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
home = {
|
||||
packages = lib.mkIf (cfg.package != null) [ cfg.package ];
|
||||
|
||||
file."${configPath}" = lib.mkIf (cfg.custom_adapters != [ ]) {
|
||||
source = (pkgs.formats.json { }).generate "ripgrep-all" {
|
||||
"$schema" = "./config.schema.json";
|
||||
custom_adapters =
|
||||
map (lib.filterAttrs (n: v: v != null)) cfg.custom_adapters;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
|
@ -379,6 +379,7 @@ in import nmtSrc {
|
|||
./modules/programs/readline
|
||||
./modules/programs/rio
|
||||
./modules/programs/ripgrep
|
||||
./modules/programs/ripgrep-all
|
||||
./modules/programs/ruff
|
||||
./modules/programs/sagemath
|
||||
./modules/programs/sapling
|
||||
|
|
51
tests/modules/programs/ripgrep-all/custom-arguments.nix
Normal file
51
tests/modules/programs/ripgrep-all/custom-arguments.nix
Normal file
|
@ -0,0 +1,51 @@
|
|||
{ pkgs, config, ... }: {
|
||||
config = {
|
||||
programs.ripgrep-all = {
|
||||
enable = true;
|
||||
package = config.lib.test.mkStubPackage { name = "ripgrep-all"; };
|
||||
custom_adapters = [{
|
||||
name = "gron";
|
||||
version = 1;
|
||||
description = "Transform JSON into discrete JS assignments";
|
||||
extensions = [ "json" ];
|
||||
mimetypes = [ "application/json" ];
|
||||
binary = "/bin/gron";
|
||||
disabled_by_default = false;
|
||||
match_only_by_mime = false;
|
||||
}];
|
||||
};
|
||||
|
||||
nmt.script = let
|
||||
configPath = if pkgs.stdenv.hostPlatform.isDarwin then
|
||||
"Library/Application Support/ripgrep-all/config.jsonc"
|
||||
else
|
||||
".config/ripgrep-all/config.jsonc";
|
||||
in ''
|
||||
assertFileExists "home-files/${configPath}"
|
||||
assertFileContent "home-files/${configPath}" ${
|
||||
pkgs.writeText "ripgrep-all.expected" ''
|
||||
{
|
||||
"$schema": "./config.schema.json",
|
||||
"custom_adapters": [
|
||||
{
|
||||
"args": [],
|
||||
"binary": "/bin/gron",
|
||||
"description": "Transform JSON into discrete JS assignments",
|
||||
"disabled_by_default": false,
|
||||
"extensions": [
|
||||
"json"
|
||||
],
|
||||
"match_only_by_mime": false,
|
||||
"mimetypes": [
|
||||
"application/json"
|
||||
],
|
||||
"name": "gron",
|
||||
"version": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
''
|
||||
}
|
||||
'';
|
||||
};
|
||||
}
|
13
tests/modules/programs/ripgrep-all/default-arguments.nix
Normal file
13
tests/modules/programs/ripgrep-all/default-arguments.nix
Normal file
|
@ -0,0 +1,13 @@
|
|||
{ config, ... }: {
|
||||
config = {
|
||||
programs.ripgrep-all = {
|
||||
enable = true;
|
||||
package = config.lib.test.mkStubPackage { name = "ripgrep-all"; };
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertPathNotExists home-files/.config/ripgrep-all/config.jsonc
|
||||
assertPathNotExists 'home-files/Library/Application Support/ripgrep-all/config.jsonc'
|
||||
'';
|
||||
};
|
||||
}
|
4
tests/modules/programs/ripgrep-all/default.nix
Normal file
4
tests/modules/programs/ripgrep-all/default.nix
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
ripgrep-all-default-arguments = ./default-arguments.nix;
|
||||
ripgrep-all-custom-arguments = ./custom-arguments.nix;
|
||||
}
|
Loading…
Add table
Reference in a new issue