Files
Austin Horstman 351257a814 difftastic: remove deprecated programs.git.difftastic aliases
The `programs.git.difftastic` options moved to `programs.difftastic` in
25.11, including `background`, `color`, `context`, and `display`, which
moved under `programs.difftastic.options`, and `enableAsDifftool`, which
became a Git mode. Setting the old `enable` option also turned on Git
integration automatically, with a warning asking users to set it
explicitly.

Remove those aliases and that automatic enablement ahead of the 26.11
release. Set `programs.difftastic.git.enable = true` to keep the Git
integration, and `programs.difftastic.git.mode = "both"` in place of
`enableAsDifftool = true`. The `programs.difftastic.git.diffToolMode`
conversion, deprecated after 26.05, stays.

Each old option, including the earlier `extraArgs` stub, now fails with
a removed-option error that names its replacement.
2026-10-15 12:32:55 -05:00

169 lines
4.3 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
cfg = config.programs.difftastic;
inherit (lib)
mkEnableOption
mkIf
mkMerge
mkOption
mkPackageOption
types
;
in
{
meta.maintainers = with lib.maintainers; [ khaneliman ];
imports = [
(lib.mkChangedOptionModule
[ "programs" "difftastic" "git" "diffToolMode" ]
[ "programs" "difftastic" "git" "mode" ]
(config: if config.programs.difftastic.git.diffToolMode then "both" else "external")
)
]
++ (lib.mapAttrsToList
(name: message: lib.mkRemovedOptionModule [ "programs" "git" "difftastic" name ] message)
{
enable = "Use `programs.difftastic.enable` and `programs.difftastic.git.enable` instead.";
package = "Use `programs.difftastic.package` instead.";
options = "Use `programs.difftastic.options` instead.";
background = "Use `programs.difftastic.options.background` instead.";
color = "Use `programs.difftastic.options.color` instead.";
context = "Use `programs.difftastic.options.context` instead.";
display = "Use `programs.difftastic.options.display` instead.";
enableAsDifftool = "Set `programs.difftastic.git.mode = \"both\"` instead.";
extraArgs = "Use `programs.difftastic.options` instead.";
}
);
options.programs.difftastic = {
enable = mkEnableOption "difftastic, a structural diff tool";
package = mkPackageOption pkgs "difftastic" { };
options = mkOption {
type =
with types;
let
atom = oneOf [
str
int
bool
];
in
attrsOf (either atom (listOf atom));
default = { };
example = {
color = "always";
sort-paths = 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
command, as a git difftool, or both, depending on the value of
{option}`programs.difftastic.git.mode`.
'';
};
mode = mkOption {
type = types.enum [
"external"
"difftool"
"both"
];
default = "external";
example = "difftool";
description = ''
How difftastic integrates with git.
- `"external"`: set `diff.external` so {command}`git diff` uses
difftastic by default.
- `"difftool"`: only configure difftastic as a git difftool
(`diff.tool` and `difftool.difftastic.cmd`), leaving
{command}`git diff` untouched.
- `"both"`: configure both `diff.external` and the difftool.
'';
};
};
jujutsu = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Whether to enable jujutsu integration for difftastic.
'';
};
};
};
config = mkMerge [
(mkIf cfg.enable {
home.packages = [ cfg.package ];
})
(mkIf (cfg.enable && cfg.git.enable) {
programs.git = {
enable = lib.mkDefault true;
iniContent =
let
difftCommand = "${lib.getExe cfg.package} ${lib.cli.toCommandLineShellGNU { } cfg.options}";
in
mkMerge [
(mkIf
(lib.elem cfg.git.mode [
"external"
"both"
])
{
diff.external = difftCommand;
}
)
(mkIf
(lib.elem cfg.git.mode [
"difftool"
"both"
])
{
diff.tool = lib.mkDefault "difftastic";
difftool.difftastic.cmd = "${difftCommand} $LOCAL $REMOTE";
}
)
];
};
})
(mkIf (cfg.enable && cfg.jujutsu.enable) {
programs.jujutsu.settings.ui.diff-formatter = [
(lib.getExe cfg.package)
]
++ (lib.cli.toCommandLineGNU { } (
cfg.options
// {
color = "always";
sort-paths = true;
width = "$width";
}
))
++ [
"$left"
"$right"
];
})
];
}