mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
riff: new module
Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
parent
41fd9b197c
commit
b695586f92
2 changed files with 108 additions and 47 deletions
|
|
@ -293,29 +293,6 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
riff = {
|
|
||||||
enable = mkEnableOption "" // {
|
|
||||||
description = ''
|
|
||||||
Enable the <command>riff</command> diff highlighter.
|
|
||||||
See <link xlink:href="https://github.com/walles/riff" />.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
package = mkPackageOption pkgs "riffdiff" { };
|
|
||||||
|
|
||||||
commandLineOptions = mkOption {
|
|
||||||
type = types.listOf types.str;
|
|
||||||
default = [ ];
|
|
||||||
example = literalExpression ''[ "--no-adds-only-special" ]'';
|
|
||||||
apply = lib.concatStringsSep " ";
|
|
||||||
description = ''
|
|
||||||
Command line arguments to include in the <command>RIFF</command> environment variable.
|
|
||||||
|
|
||||||
Run <command>riff --help</command> for a full list of options
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -346,7 +323,7 @@ in
|
||||||
(config.programs.diff-so-fancy.enable && config.programs.diff-so-fancy.enableGitIntegration)
|
(config.programs.diff-so-fancy.enable && config.programs.diff-so-fancy.enableGitIntegration)
|
||||||
(config.programs.difftastic.enable && config.programs.difftastic.git.enable)
|
(config.programs.difftastic.enable && config.programs.difftastic.git.enable)
|
||||||
(config.programs.patdiff.enable && config.programs.patdiff.enableGitIntegration)
|
(config.programs.patdiff.enable && config.programs.patdiff.enableGitIntegration)
|
||||||
cfg.riff.enable
|
(config.programs.riff.enable && config.programs.riff.enableGitIntegration)
|
||||||
];
|
];
|
||||||
in
|
in
|
||||||
lib.count lib.id enabled <= 1;
|
lib.count lib.id enabled <= 1;
|
||||||
|
|
@ -624,29 +601,6 @@ in
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
(
|
|
||||||
let
|
|
||||||
riffExe = baseNameOf (lib.getExe cfg.riff.package);
|
|
||||||
in
|
|
||||||
mkIf cfg.riff.enable {
|
|
||||||
home.packages = [ cfg.riff.package ];
|
|
||||||
|
|
||||||
# https://github.com/walles/riff/blob/b17e6f17ce807c8652bc59cd46758661d23ce358/README.md#usage
|
|
||||||
programs.git.iniContent = {
|
|
||||||
pager = {
|
|
||||||
diff = riffExe;
|
|
||||||
log = riffExe;
|
|
||||||
show = riffExe;
|
|
||||||
};
|
|
||||||
|
|
||||||
interactive.diffFilter = "${riffExe} --color=on";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
(mkIf (cfg.riff.enable && cfg.riff.commandLineOptions != "") {
|
|
||||||
home.sessionVariables.RIFF = cfg.riff.commandLineOptions;
|
|
||||||
})
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
107
modules/programs/riff.nix
Normal file
107
modules/programs/riff.nix
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
options,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
cfg = config.programs.riff;
|
||||||
|
|
||||||
|
inherit (lib)
|
||||||
|
literalExpression
|
||||||
|
mkEnableOption
|
||||||
|
mkIf
|
||||||
|
mkOption
|
||||||
|
mkPackageOption
|
||||||
|
types
|
||||||
|
;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
meta.maintainers = with lib.maintainers; [ khaneliman ];
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
(lib.mkRenamedOptionModule [ "programs" "git" "riff" "enable" ] [ "programs" "riff" "enable" ])
|
||||||
|
(lib.mkRenamedOptionModule [ "programs" "git" "riff" "package" ] [ "programs" "riff" "package" ])
|
||||||
|
(lib.mkRenamedOptionModule
|
||||||
|
[ "programs" "git" "riff" "commandLineOptions" ]
|
||||||
|
[ "programs" "riff" "commandLineOptions" ]
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
options.programs.riff = {
|
||||||
|
enable = mkEnableOption "" // {
|
||||||
|
description = ''
|
||||||
|
Enable the <command>riff</command> diff highlighter.
|
||||||
|
See <link xlink:href="https://github.com/walles/riff" />.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
package = mkPackageOption pkgs "riffdiff" { };
|
||||||
|
|
||||||
|
commandLineOptions = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [ ];
|
||||||
|
example = literalExpression ''[ "--no-adds-only-special" ]'';
|
||||||
|
apply = lib.concatStringsSep " ";
|
||||||
|
description = ''
|
||||||
|
Command line arguments to include in the <command>RIFF</command> environment variable.
|
||||||
|
|
||||||
|
Run <command>riff --help</command> for a full list of options
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
enableGitIntegration = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Whether to enable git integration for riff.
|
||||||
|
|
||||||
|
When enabled, riff will be configured as git's pager for diff, log, and show commands.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config =
|
||||||
|
let
|
||||||
|
oldOption = lib.attrByPath [ "programs" "git" "riff" "enable" ] null options;
|
||||||
|
oldOptionEnabled =
|
||||||
|
oldOption != null && oldOption.isDefined && (builtins.length oldOption.files) > 0;
|
||||||
|
in
|
||||||
|
lib.mkMerge [
|
||||||
|
(mkIf cfg.enable {
|
||||||
|
home.packages = [ cfg.package ];
|
||||||
|
|
||||||
|
home.sessionVariables = mkIf (cfg.commandLineOptions != "") {
|
||||||
|
RIFF = cfg.commandLineOptions;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Auto-enable git integration if programs.git.riff.enable was set to true
|
||||||
|
programs.riff.enableGitIntegration = lib.mkIf oldOptionEnabled (lib.mkOverride 1490 true);
|
||||||
|
|
||||||
|
warnings =
|
||||||
|
lib.optional
|
||||||
|
(cfg.enableGitIntegration && options.programs.riff.enableGitIntegration.highestPrio == 1490)
|
||||||
|
"`programs.riff.enableGitIntegration` automatic enablement is deprecated. Please explicitly set `programs.riff.enableGitIntegration = true`.";
|
||||||
|
})
|
||||||
|
|
||||||
|
(mkIf (cfg.enable && cfg.enableGitIntegration) {
|
||||||
|
programs.git = {
|
||||||
|
enable = lib.mkDefault true;
|
||||||
|
iniContent =
|
||||||
|
let
|
||||||
|
riffExe = baseNameOf (lib.getExe cfg.package);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
pager = {
|
||||||
|
diff = riffExe;
|
||||||
|
log = riffExe;
|
||||||
|
show = riffExe;
|
||||||
|
};
|
||||||
|
|
||||||
|
interactive.diffFilter = "${riffExe} --color=on";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})
|
||||||
|
];
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue