diff --git a/modules/programs/diff-so-fancy.nix b/modules/programs/diff-so-fancy.nix index 53f8dc21c..68e2a23d4 100644 --- a/modules/programs/diff-so-fancy.nix +++ b/modules/programs/diff-so-fancy.nix @@ -18,36 +18,43 @@ in { meta.maintainers = with lib.maintainers; [ khaneliman ]; - imports = [ - (lib.mkRenamedOptionModule - [ "programs" "git" "diff-so-fancy" "enable" ] - [ "programs" "diff-so-fancy" "enable" ] - ) - (lib.mkRenamedOptionModule - [ "programs" "git" "diff-so-fancy" "pagerOpts" ] - [ "programs" "diff-so-fancy" "pagerOpts" ] - ) - (lib.mkRenamedOptionModule - [ "programs" "git" "diff-so-fancy" "markEmptyLines" ] - [ "programs" "diff-so-fancy" "markEmptyLines" ] - ) - (lib.mkRenamedOptionModule - [ "programs" "git" "diff-so-fancy" "changeHunkIndicators" ] - [ "programs" "diff-so-fancy" "changeHunkIndicators" ] - ) - (lib.mkRenamedOptionModule - [ "programs" "git" "diff-so-fancy" "stripLeadingSymbols" ] - [ "programs" "diff-so-fancy" "stripLeadingSymbols" ] - ) - (lib.mkRenamedOptionModule - [ "programs" "git" "diff-so-fancy" "useUnicodeRuler" ] - [ "programs" "diff-so-fancy" "useUnicodeRuler" ] - ) - (lib.mkRenamedOptionModule - [ "programs" "git" "diff-so-fancy" "rulerWidth" ] - [ "programs" "diff-so-fancy" "rulerWidth" ] - ) - ]; + imports = + let + oldPrefix = [ + "programs" + "diff-so-fancy" + ]; + newPrefix = [ + "programs" + "diff-so-fancy" + "settings" + ]; + renamedOptions = [ + "markEmptyLines" + "changeHunkIndicators" + "stripLeadingSymbols" + "useUnicodeRuler" + "rulerWidth" + ]; + in + [ + (lib.mkRenamedOptionModule + [ "programs" "git" "diff-so-fancy" "enable" ] + [ "programs" "diff-so-fancy" "enable" ] + ) + (lib.mkRenamedOptionModule + [ "programs" "git" "diff-so-fancy" "pagerOpts" ] + [ "programs" "diff-so-fancy" "pagerOpts" ] + ) + ] + ++ (lib.hm.deprecations.mkSettingsRenamedOptionModules oldPrefix newPrefix { + transform = x: x; + } renamedOptions) + ++ (lib.hm.deprecations.mkSettingsRenamedOptionModules [ + "programs" + "git" + "diff-so-fancy" + ] newPrefix { transform = x: x; } renamedOptions); options.programs.diff-so-fancy = { enable = mkEnableOption "diff-so-fancy, a diff colorizer"; @@ -63,53 +70,28 @@ in ''; }; - markEmptyLines = mkOption { - type = types.bool; - default = true; - example = false; + settings = mkOption { + type = + with types; + let + primitiveType = oneOf [ + str + bool + int + ]; + in + attrsOf primitiveType; + default = { }; + example = { + markEmptyLines = true; + changeHunkIndicators = true; + stripLeadingSymbols = true; + useUnicodeRuler = true; + rulerWidth = 80; + }; description = '' - Whether the first block of an empty line should be colored. - ''; - }; - - changeHunkIndicators = mkOption { - type = types.bool; - default = true; - example = false; - description = '' - Simplify git header chunks to a more human readable format. - ''; - }; - - stripLeadingSymbols = mkOption { - type = types.bool; - default = true; - example = false; - description = '' - Whether the `+` or `-` at - line-start should be removed. - ''; - }; - - useUnicodeRuler = mkOption { - type = types.bool; - default = true; - example = false; - description = '' - By default, the separator for the file header uses Unicode - line-drawing characters. If this is causing output errors on - your terminal, set this to false to use ASCII characters instead. - ''; - }; - - rulerWidth = mkOption { - type = types.nullOr types.int; - default = null; - example = false; - description = '' - By default, the separator for the file header spans the full - width of the terminal. Use this setting to set the width of - the file header manually. + Options to configure diff-so-fancy. See + for available options. ''; }; @@ -155,13 +137,7 @@ in { core.pager = "${dsfCommand} | ${pkgs.less}/bin/less ${lib.escapeShellArgs cfg.pagerOpts}"; interactive.diffFilter = "${dsfCommand} --patch"; - diff-so-fancy = { - markEmptyLines = cfg.markEmptyLines; - changeHunkIndicators = cfg.changeHunkIndicators; - stripLeadingSymbols = cfg.stripLeadingSymbols; - useUnicodeRuler = cfg.useUnicodeRuler; - rulerWidth = mkIf (cfg.rulerWidth != null) cfg.rulerWidth; - }; + diff-so-fancy = cfg.settings; }; }; }) diff --git a/tests/modules/programs/diff-so-fancy/diff-so-fancy-basic.nix b/tests/modules/programs/diff-so-fancy/diff-so-fancy-basic.nix index fac80a4ab..c0b749e0f 100644 --- a/tests/modules/programs/diff-so-fancy/diff-so-fancy-basic.nix +++ b/tests/modules/programs/diff-so-fancy/diff-so-fancy-basic.nix @@ -1,8 +1,10 @@ { programs.diff-so-fancy = { enable = true; - markEmptyLines = false; - changeHunkIndicators = true; + settings = { + markEmptyLines = false; + changeHunkIndicators = true; + }; }; programs.git.enable = true; diff --git a/tests/modules/programs/diff-so-fancy/diff-so-fancy-migration.nix b/tests/modules/programs/diff-so-fancy/diff-so-fancy-migration.nix index f65f08eb0..0449d3b8f 100644 --- a/tests/modules/programs/diff-so-fancy/diff-so-fancy-migration.nix +++ b/tests/modules/programs/diff-so-fancy/diff-so-fancy-migration.nix @@ -15,8 +15,8 @@ }; test.asserts.warnings.expected = [ - "The option `programs.git.diff-so-fancy.changeHunkIndicators' defined in ${lib.showFiles options.programs.git.diff-so-fancy.changeHunkIndicators.files} has been renamed to `programs.diff-so-fancy.changeHunkIndicators'." - "The option `programs.git.diff-so-fancy.markEmptyLines' defined in ${lib.showFiles options.programs.git.diff-so-fancy.markEmptyLines.files} has been renamed to `programs.diff-so-fancy.markEmptyLines'." + "The option `programs.git.diff-so-fancy.changeHunkIndicators' defined in ${lib.showFiles options.programs.git.diff-so-fancy.changeHunkIndicators.files} has been renamed to `programs.diff-so-fancy.settings.changeHunkIndicators'." + "The option `programs.git.diff-so-fancy.markEmptyLines' defined in ${lib.showFiles options.programs.git.diff-so-fancy.markEmptyLines.files} has been renamed to `programs.diff-so-fancy.settings.markEmptyLines'." "The option `programs.git.diff-so-fancy.enable' defined in ${lib.showFiles options.programs.git.diff-so-fancy.enable.files} has been renamed to `programs.diff-so-fancy.enable'." "`programs.diff-so-fancy.enableGitIntegration` automatic enablement is deprecated. Please explicitly set `programs.diff-so-fancy.enableGitIntegration = true`." ]; diff --git a/tests/modules/programs/diff-so-fancy/diff-so-fancy-with-git-integration.nix b/tests/modules/programs/diff-so-fancy/diff-so-fancy-with-git-integration.nix index 48127f195..c51f942ad 100644 --- a/tests/modules/programs/diff-so-fancy/diff-so-fancy-with-git-integration.nix +++ b/tests/modules/programs/diff-so-fancy/diff-so-fancy-with-git-integration.nix @@ -2,9 +2,11 @@ programs.diff-so-fancy = { enable = true; enableGitIntegration = true; - markEmptyLines = false; - changeHunkIndicators = true; - stripLeadingSymbols = false; + settings = { + markEmptyLines = false; + changeHunkIndicators = true; + stripLeadingSymbols = false; + }; }; programs.git.enable = true;