mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
delta: create new module
Pull out of git module and deprecate old usage. Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
parent
90af98a2fc
commit
f436677f5f
4 changed files with 126 additions and 78 deletions
125
modules/programs/delta.nix
Normal file
125
modules/programs/delta.nix
Normal file
|
|
@ -0,0 +1,125 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
options,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
cfg = config.programs.delta;
|
||||||
|
|
||||||
|
inherit (lib)
|
||||||
|
mkOption
|
||||||
|
types
|
||||||
|
;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
meta.maintainers = with lib.maintainers; [ khaneliman ];
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
(lib.mkRenamedOptionModule [ "programs" "git" "delta" "enable" ] [ "programs" "delta" "enable" ])
|
||||||
|
(lib.mkRenamedOptionModule [ "programs" "git" "delta" "package" ] [ "programs" "delta" "package" ])
|
||||||
|
(lib.mkRenamedOptionModule [ "programs" "git" "delta" "options" ] [ "programs" "delta" "options" ])
|
||||||
|
];
|
||||||
|
|
||||||
|
options.programs.delta = {
|
||||||
|
enable = lib.mkEnableOption "delta, a syntax highlighter for git diffs";
|
||||||
|
|
||||||
|
package = lib.mkPackageOption pkgs "delta" { };
|
||||||
|
|
||||||
|
options = mkOption {
|
||||||
|
type =
|
||||||
|
with types;
|
||||||
|
let
|
||||||
|
primitiveType = oneOf [
|
||||||
|
str
|
||||||
|
bool
|
||||||
|
int
|
||||||
|
];
|
||||||
|
sectionType = attrsOf primitiveType;
|
||||||
|
in
|
||||||
|
attrsOf (either primitiveType sectionType);
|
||||||
|
default = { };
|
||||||
|
example = {
|
||||||
|
features = "decorations";
|
||||||
|
whitespace-error-style = "22 reverse";
|
||||||
|
decorations = {
|
||||||
|
commit-decoration-style = "bold yellow box ul";
|
||||||
|
file-style = "bold yellow ul";
|
||||||
|
file-decoration-style = "none";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
description = ''
|
||||||
|
Options to configure delta.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
enableGitIntegration = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Whether to enable git integration for delta.
|
||||||
|
|
||||||
|
When enabled, delta will be configured as git's pager and diff filter.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
finalPackage = mkOption {
|
||||||
|
type = types.package;
|
||||||
|
readOnly = true;
|
||||||
|
visible = false;
|
||||||
|
default =
|
||||||
|
let
|
||||||
|
configFile = pkgs.writeText "delta-config" (lib.generators.toGitINI { delta = cfg.options; });
|
||||||
|
wrappedDelta = pkgs.symlinkJoin {
|
||||||
|
name = "delta-wrapped";
|
||||||
|
paths = [ cfg.package ];
|
||||||
|
nativeBuildInputs = [ pkgs.makeWrapper ];
|
||||||
|
postBuild = ''
|
||||||
|
wrapProgram $out/bin/delta \
|
||||||
|
--add-flags "--config ${configFile}"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
in
|
||||||
|
if !cfg.enableGitIntegration && cfg.options != { } then wrappedDelta else cfg.package;
|
||||||
|
description = ''
|
||||||
|
The delta package with configuration wrapper applied.
|
||||||
|
|
||||||
|
When git integration is disabled and options are configured,
|
||||||
|
this is a wrapped version that passes --config to delta.
|
||||||
|
Otherwise, it's the unwrapped package.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config =
|
||||||
|
let
|
||||||
|
oldOption = lib.attrByPath [ "programs" "git" "delta" "enable" ] null options;
|
||||||
|
oldOptionEnabled =
|
||||||
|
oldOption != null && oldOption.isDefined && (builtins.length oldOption.files) > 0;
|
||||||
|
in
|
||||||
|
lib.mkMerge [
|
||||||
|
(lib.mkIf cfg.enable {
|
||||||
|
home.packages = [ cfg.finalPackage ];
|
||||||
|
|
||||||
|
programs.delta.enableGitIntegration = lib.mkIf oldOptionEnabled (lib.mkOverride 1490 true);
|
||||||
|
|
||||||
|
warnings =
|
||||||
|
lib.optional
|
||||||
|
(cfg.enableGitIntegration && options.programs.delta.enableGitIntegration.highestPrio == 1490)
|
||||||
|
"`programs.delta.enableGitIntegration` automatic enablement is deprecated. Please explicitly set `programs.delta.enableGitIntegration = true`.";
|
||||||
|
})
|
||||||
|
|
||||||
|
(lib.mkIf (cfg.enable && cfg.enableGitIntegration) {
|
||||||
|
programs.git.iniContent =
|
||||||
|
let
|
||||||
|
deltaCommand = lib.getExe cfg.package;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
core.pager = deltaCommand;
|
||||||
|
interactive.diffFilter = "${deltaCommand} --color-only";
|
||||||
|
delta = cfg.options;
|
||||||
|
};
|
||||||
|
})
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -348,40 +348,6 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
delta = {
|
|
||||||
enable = mkEnableOption "" // {
|
|
||||||
description = ''
|
|
||||||
Whether to enable the {command}`delta` syntax highlighter.
|
|
||||||
See <https://github.com/dandavison/delta>.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
package = mkPackageOption pkgs "delta" { };
|
|
||||||
|
|
||||||
options = mkOption {
|
|
||||||
type =
|
|
||||||
with types;
|
|
||||||
let
|
|
||||||
primitiveType = either str (either bool int);
|
|
||||||
sectionType = attrsOf primitiveType;
|
|
||||||
in
|
|
||||||
attrsOf (either primitiveType sectionType);
|
|
||||||
default = { };
|
|
||||||
example = {
|
|
||||||
features = "decorations";
|
|
||||||
whitespace-error-style = "22 reverse";
|
|
||||||
decorations = {
|
|
||||||
commit-decoration-style = "bold yellow box ul";
|
|
||||||
file-style = "bold yellow ul";
|
|
||||||
file-decoration-style = "none";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
description = ''
|
|
||||||
Options to configure delta.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
diff-so-fancy = {
|
diff-so-fancy = {
|
||||||
enable = mkEnableOption "" // {
|
enable = mkEnableOption "" // {
|
||||||
description = ''
|
description = ''
|
||||||
|
|
@ -530,7 +496,7 @@ in
|
||||||
assertion =
|
assertion =
|
||||||
let
|
let
|
||||||
enabled = [
|
enabled = [
|
||||||
cfg.delta.enable
|
(config.programs.delta.enable && config.programs.delta.enableGitIntegration)
|
||||||
cfg.diff-so-fancy.enable
|
cfg.diff-so-fancy.enable
|
||||||
cfg.difftastic.enable
|
cfg.difftastic.enable
|
||||||
cfg.diff-highlight.enable
|
cfg.diff-highlight.enable
|
||||||
|
|
@ -853,22 +819,6 @@ in
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
|
|
||||||
(
|
|
||||||
let
|
|
||||||
deltaPackage = cfg.delta.package;
|
|
||||||
deltaCommand = "${deltaPackage}/bin/delta";
|
|
||||||
in
|
|
||||||
mkIf cfg.delta.enable {
|
|
||||||
home.packages = [ deltaPackage ];
|
|
||||||
|
|
||||||
programs.git.iniContent = {
|
|
||||||
core.pager = deltaCommand;
|
|
||||||
interactive.diffFilter = "${deltaCommand} --color-only";
|
|
||||||
delta = cfg.delta.options;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
(mkIf cfg.diff-so-fancy.enable {
|
(mkIf cfg.diff-so-fancy.enable {
|
||||||
home.packages = [ pkgs.diff-so-fancy ];
|
home.packages = [ pkgs.diff-so-fancy ];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,18 +6,6 @@
|
||||||
[commit]
|
[commit]
|
||||||
gpgSign = true
|
gpgSign = true
|
||||||
|
|
||||||
[core]
|
|
||||||
pager = "@delta@/bin/delta"
|
|
||||||
|
|
||||||
[delta]
|
|
||||||
features = "decorations"
|
|
||||||
whitespace-error-style = "22 reverse"
|
|
||||||
|
|
||||||
[delta "decorations"]
|
|
||||||
commit-decoration-style = "bold yellow box ul"
|
|
||||||
file-decoration-style = "none"
|
|
||||||
file-style = "bold yellow ul"
|
|
||||||
|
|
||||||
[extra]
|
[extra]
|
||||||
boolean = true
|
boolean = true
|
||||||
integer = 38
|
integer = 38
|
||||||
|
|
@ -43,9 +31,6 @@
|
||||||
[gpg "openpgp"]
|
[gpg "openpgp"]
|
||||||
program = "path-to-gpg"
|
program = "path-to-gpg"
|
||||||
|
|
||||||
[interactive]
|
|
||||||
diffFilter = "@delta@/bin/delta --color-only"
|
|
||||||
|
|
||||||
[tag]
|
[tag]
|
||||||
gpgSign = true
|
gpgSign = true
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,18 +69,6 @@ in
|
||||||
userEmail = "user@example.org";
|
userEmail = "user@example.org";
|
||||||
userName = "John Doe";
|
userName = "John Doe";
|
||||||
lfs.enable = true;
|
lfs.enable = true;
|
||||||
delta = {
|
|
||||||
enable = true;
|
|
||||||
options = {
|
|
||||||
features = "decorations";
|
|
||||||
whitespace-error-style = "22 reverse";
|
|
||||||
decorations = {
|
|
||||||
commit-decoration-style = "bold yellow box ul";
|
|
||||||
file-style = "bold yellow ul";
|
|
||||||
file-decoration-style = "none";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue