mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
difftastic: new module
Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
parent
16cd8abad6
commit
111329b475
5 changed files with 147 additions and 122 deletions
146
modules/programs/difftastic.nix
Normal file
146
modules/programs/difftastic.nix
Normal file
|
|
@ -0,0 +1,146 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
options,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
cfg = config.programs.difftastic;
|
||||||
|
|
||||||
|
inherit (lib)
|
||||||
|
mkEnableOption
|
||||||
|
mkIf
|
||||||
|
mkMerge
|
||||||
|
mkOption
|
||||||
|
mkPackageOption
|
||||||
|
types
|
||||||
|
;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
meta.maintainers = with lib.maintainers; [ khaneliman ];
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
(lib.mkRenamedOptionModule
|
||||||
|
[ "programs" "git" "difftastic" "enable" ]
|
||||||
|
[ "programs" "difftastic" "enable" ]
|
||||||
|
)
|
||||||
|
(lib.mkRenamedOptionModule
|
||||||
|
[ "programs" "git" "difftastic" "package" ]
|
||||||
|
[ "programs" "difftastic" "package" ]
|
||||||
|
)
|
||||||
|
(lib.mkRenamedOptionModule
|
||||||
|
[ "programs" "git" "difftastic" "enableAsDifftool" ]
|
||||||
|
[ "programs" "difftastic" "git" "diffToolMode" ]
|
||||||
|
)
|
||||||
|
(lib.mkRenamedOptionModule
|
||||||
|
[ "programs" "git" "difftastic" "options" ]
|
||||||
|
[ "programs" "difftastic" "options" ]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
++ (
|
||||||
|
let
|
||||||
|
mkRenamed =
|
||||||
|
opt:
|
||||||
|
lib.mkRenamedOptionModule
|
||||||
|
[ "programs" "git" "difftastic" opt ]
|
||||||
|
[ "programs" "git" "difftastic" "options" opt ];
|
||||||
|
in
|
||||||
|
map mkRenamed [
|
||||||
|
"background"
|
||||||
|
"color"
|
||||||
|
"context"
|
||||||
|
"display"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
++ [
|
||||||
|
(lib.mkRemovedOptionModule [ "programs" "git" "difftastic" "extraArgs" ] ''
|
||||||
|
'programs.git.difftastic.extraArgs' has been replaced by 'programs.git.difftastic.options'
|
||||||
|
'')
|
||||||
|
];
|
||||||
|
|
||||||
|
options.programs.difftastic = {
|
||||||
|
enable = mkEnableOption "difftastic, a structural diff tool";
|
||||||
|
|
||||||
|
package = mkPackageOption pkgs "difftastic" { };
|
||||||
|
|
||||||
|
options = mkOption {
|
||||||
|
type =
|
||||||
|
with types;
|
||||||
|
attrsOf (oneOf [
|
||||||
|
str
|
||||||
|
int
|
||||||
|
bool
|
||||||
|
]);
|
||||||
|
default = { };
|
||||||
|
example = {
|
||||||
|
color = "dark";
|
||||||
|
sort-path = true;
|
||||||
|
tab-width = 8;
|
||||||
|
};
|
||||||
|
description = "Configuration options for {command}`difftastic`. See {command}`difft --help`";
|
||||||
|
};
|
||||||
|
|
||||||
|
git = {
|
||||||
|
enable = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Whether to enable git integration for difftastic.
|
||||||
|
|
||||||
|
When enabled, difftastic will be configured as git's external diff tool or difftool
|
||||||
|
depending on the value of {option}`programs.difftastic.git.diffToolMode`.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
diffToolMode = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Whether to additionally configure difftastic as a git difftool.
|
||||||
|
|
||||||
|
When `false`, only `diff.external` is set (used for `git diff`).
|
||||||
|
When `true`, both `diff.external` and difftool config are set (supporting both `git diff` and `git difftool`).
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config =
|
||||||
|
let
|
||||||
|
oldOption = lib.attrByPath [ "programs" "git" "difftastic" "enable" ] null options;
|
||||||
|
oldOptionEnabled =
|
||||||
|
oldOption != null && oldOption.isDefined && (builtins.length oldOption.files) > 0;
|
||||||
|
in
|
||||||
|
mkMerge [
|
||||||
|
(mkIf cfg.enable {
|
||||||
|
home.packages = [ cfg.package ];
|
||||||
|
|
||||||
|
# Auto-enable git integration if programs.git.difftastic.enable was set to true
|
||||||
|
programs.difftastic.git.enable = lib.mkIf oldOptionEnabled (lib.mkOverride 1490 true);
|
||||||
|
|
||||||
|
warnings =
|
||||||
|
lib.optional (cfg.git.enable && options.programs.difftastic.git.enable.highestPrio == 1490)
|
||||||
|
"`programs.difftastic.git.enable` automatic enablement is deprecated. Please explicitly set `programs.difftastic.git.enable = true`.";
|
||||||
|
})
|
||||||
|
|
||||||
|
(mkIf (cfg.enable && cfg.git.enable) {
|
||||||
|
programs.git = {
|
||||||
|
enable = lib.mkDefault true;
|
||||||
|
iniContent =
|
||||||
|
let
|
||||||
|
difftCommand = "${lib.getExe cfg.package} ${lib.cli.toGNUCommandLineShell { } cfg.options}";
|
||||||
|
in
|
||||||
|
mkMerge [
|
||||||
|
{
|
||||||
|
diff.external = difftCommand;
|
||||||
|
}
|
||||||
|
(mkIf cfg.git.diffToolMode {
|
||||||
|
diff.tool = lib.mkDefault "difftastic";
|
||||||
|
difftool.difftastic.cmd = "${difftCommand} $LOCAL $REMOTE";
|
||||||
|
})
|
||||||
|
];
|
||||||
|
};
|
||||||
|
})
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -90,7 +90,6 @@ let
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
meta.maintainers = with lib.maintainers; [
|
meta.maintainers = with lib.maintainers; [
|
||||||
|
|
@ -292,41 +291,6 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
difftastic = {
|
|
||||||
enable = mkEnableOption "" // {
|
|
||||||
description = ''
|
|
||||||
Enable the {command}`difftastic` syntax highlighter.
|
|
||||||
See <https://github.com/Wilfred/difftastic>.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
package = mkPackageOption pkgs "difftastic" { };
|
|
||||||
|
|
||||||
enableAsDifftool = mkEnableOption "" // {
|
|
||||||
description = ''
|
|
||||||
Enable the {command}`difftastic` syntax highlighter as a git difftool.
|
|
||||||
See <https://github.com/Wilfred/difftastic>.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
options = mkOption {
|
|
||||||
type =
|
|
||||||
with lib.types;
|
|
||||||
attrsOf (oneOf [
|
|
||||||
str
|
|
||||||
number
|
|
||||||
bool
|
|
||||||
]);
|
|
||||||
default = { };
|
|
||||||
example = {
|
|
||||||
color = "dark";
|
|
||||||
sort-path = true;
|
|
||||||
tab-width = 8;
|
|
||||||
};
|
|
||||||
description = "Configuration options for {command}`difftastic`. See {command}`difft --help`";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
riff = {
|
riff = {
|
||||||
enable = mkEnableOption "" // {
|
enable = mkEnableOption "" // {
|
||||||
description = ''
|
description = ''
|
||||||
|
|
@ -373,26 +337,6 @@ in
|
||||||
"signer"
|
"signer"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
]
|
|
||||||
++ (
|
|
||||||
let
|
|
||||||
mkRenamed =
|
|
||||||
opt:
|
|
||||||
lib.mkRenamedOptionModule
|
|
||||||
[ "programs" "git" "difftastic" opt ]
|
|
||||||
[ "programs" "git" "difftastic" "options" opt ];
|
|
||||||
in
|
|
||||||
map mkRenamed [
|
|
||||||
"background"
|
|
||||||
"color"
|
|
||||||
"context"
|
|
||||||
"display"
|
|
||||||
]
|
|
||||||
)
|
|
||||||
++ [
|
|
||||||
(lib.mkRemovedOptionModule [ "programs" "git" "difftastic" "extraArgs" ] ''
|
|
||||||
'programs.git.difftastic.extraArgs' has been replaced by 'programs.git.difftastic.options'
|
|
||||||
'')
|
|
||||||
];
|
];
|
||||||
|
|
||||||
config = mkIf cfg.enable (
|
config = mkIf cfg.enable (
|
||||||
|
|
@ -408,7 +352,7 @@ in
|
||||||
(config.programs.delta.enable && config.programs.delta.enableGitIntegration)
|
(config.programs.delta.enable && config.programs.delta.enableGitIntegration)
|
||||||
(config.programs.diff-highlight.enable && config.programs.diff-highlight.enableGitIntegration)
|
(config.programs.diff-highlight.enable && config.programs.diff-highlight.enableGitIntegration)
|
||||||
(config.programs.diff-so-fancy.enable && config.programs.diff-so-fancy.enableGitIntegration)
|
(config.programs.diff-so-fancy.enable && config.programs.diff-so-fancy.enableGitIntegration)
|
||||||
cfg.difftastic.enable
|
(config.programs.difftastic.enable && config.programs.difftastic.git.enable)
|
||||||
cfg.riff.enable
|
cfg.riff.enable
|
||||||
cfg.patdiff.enable
|
cfg.patdiff.enable
|
||||||
];
|
];
|
||||||
|
|
@ -688,35 +632,6 @@ in
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
(
|
|
||||||
let
|
|
||||||
difftCommand = "${lib.getExe cfg.difftastic.package} ${
|
|
||||||
lib.cli.toGNUCommandLineShell { } cfg.difftastic.options
|
|
||||||
}";
|
|
||||||
in
|
|
||||||
(lib.mkMerge [
|
|
||||||
(mkIf cfg.difftastic.enable {
|
|
||||||
home.packages = [ cfg.difftastic.package ];
|
|
||||||
programs.git.iniContent = {
|
|
||||||
diff.external = difftCommand;
|
|
||||||
};
|
|
||||||
})
|
|
||||||
(mkIf cfg.difftastic.enableAsDifftool {
|
|
||||||
home.packages = [ cfg.difftastic.package ];
|
|
||||||
programs.git.iniContent = {
|
|
||||||
diff = {
|
|
||||||
tool = lib.mkDefault "difftastic";
|
|
||||||
};
|
|
||||||
difftool = {
|
|
||||||
difftastic = {
|
|
||||||
cmd = "${difftCommand} $LOCAL $REMOTE";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
})
|
|
||||||
])
|
|
||||||
)
|
|
||||||
|
|
||||||
(
|
(
|
||||||
let
|
let
|
||||||
riffExe = baseNameOf (lib.getExe cfg.riff.package);
|
riffExe = baseNameOf (lib.getExe cfg.riff.package);
|
||||||
|
|
|
||||||
|
|
@ -10,5 +10,4 @@
|
||||||
git-with-hooks = ./git-with-hooks.nix;
|
git-with-hooks = ./git-with-hooks.nix;
|
||||||
git-with-maintenance = ./git-with-maintenance.nix;
|
git-with-maintenance = ./git-with-maintenance.nix;
|
||||||
git-patdiff = ./git-patdiff.nix;
|
git-patdiff = ./git-patdiff.nix;
|
||||||
git-difftastic = ./git-difftastic.nix;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
[diff]
|
|
||||||
external = "@difftastic@/bin/difft --background dark --color always --context 5 --display inline --sort-paths --tab-width 8"
|
|
||||||
tool = "difftastic"
|
|
||||||
|
|
||||||
[difftool "difftastic"]
|
|
||||||
cmd = "@difftastic@/bin/difft --background dark --color always --context 5 --display inline --sort-paths --tab-width 8 $LOCAL $REMOTE"
|
|
||||||
|
|
||||||
[gpg]
|
|
||||||
format = "openpgp"
|
|
||||||
|
|
||||||
[gpg "openpgp"]
|
|
||||||
program = "path-to-gpg"
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
{
|
|
||||||
programs.git = {
|
|
||||||
enable = true;
|
|
||||||
signing.signer = "path-to-gpg";
|
|
||||||
difftastic = {
|
|
||||||
enable = true;
|
|
||||||
enableAsDifftool = true;
|
|
||||||
options = {
|
|
||||||
background = "dark";
|
|
||||||
color = "always";
|
|
||||||
context = 5;
|
|
||||||
display = "inline";
|
|
||||||
tab-width = 8;
|
|
||||||
sort-paths = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
nmt.script = ''
|
|
||||||
assertFileExists home-files/.config/git/config
|
|
||||||
assertFileContent home-files/.config/git/config ${./git-difftastic-expected.conf}
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue