From 4bd0ca2cd793b3f057d114bd6a3183419f52ca49 Mon Sep 17 00:00:00 2001
From: Mario Rodas <marsam@users.noreply.github.com>
Date: Mon, 20 Jul 2020 10:03:40 -0500
Subject: [PATCH] git: configure delta through [delta] git section (#1371)

this breaks backwards compatibility (now accepts a dict instead of a list) so please update
programs.git.delta.options accordingly.
---
 modules/programs/git.nix                     | 35 +++++++++++++-------
 tests/modules/programs/git/git-expected.conf | 13 ++++++--
 tests/modules/programs/git/git.nix           | 10 +++++-
 3 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/modules/programs/git.nix b/modules/programs/git.nix
index ec2402f11..a174fa0c4 100644
--- a/modules/programs/git.nix
+++ b/modules/programs/git.nix
@@ -225,11 +225,23 @@ in {
         };
 
         options = mkOption {
-          type = types.listOf types.str;
-          default = [ ];
-          example = [ "--dark" ];
+          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 = ''
-            Extra command line options given to delta.
+            Options to configure delta.
           '';
         };
       };
@@ -329,14 +341,13 @@ in {
     })
 
     (mkIf cfg.delta.enable {
-      programs.git.iniContent = let
-        deltaArgs = [ "${pkgs.gitAndTools.delta}/bin/delta" ]
-          ++ cfg.delta.options;
-      in {
-        core.pager = concatStringsSep " " deltaArgs;
-        interactive.diffFilter =
-          concatStringsSep " " (deltaArgs ++ [ "--color-only" ]);
-      };
+      programs.git.iniContent =
+        let deltaCommand = "${pkgs.gitAndTools.delta}/bin/delta";
+        in {
+          core.pager = deltaCommand;
+          interactive.diffFilter = "${deltaCommand} --color-only";
+          delta = cfg.delta.options;
+        };
     })
   ]);
 }
diff --git a/tests/modules/programs/git/git-expected.conf b/tests/modules/programs/git/git-expected.conf
index a4457adfa..c3e534af0 100644
--- a/tests/modules/programs/git/git-expected.conf
+++ b/tests/modules/programs/git/git-expected.conf
@@ -7,7 +7,16 @@
 	gpgSign = true
 
 [core]
-	pager = "@deltaCommand@ --dark"
+	pager = "@deltaCommand@"
+
+[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]
 	boolean = true
@@ -32,7 +41,7 @@
 	program = "path-to-gpg"
 
 [interactive]
-	diffFilter = "@deltaCommand@ --dark --color-only"
+	diffFilter = "@deltaCommand@ --color-only"
 
 [user]
 	email = "user@example.org"
diff --git a/tests/modules/programs/git/git.nix b/tests/modules/programs/git/git.nix
index 54e3c79b4..feefff54b 100644
--- a/tests/modules/programs/git/git.nix
+++ b/tests/modules/programs/git/git.nix
@@ -60,7 +60,15 @@ in {
         lfs.enable = true;
         delta = {
           enable = true;
-          options = [ "--dark" ];
+          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";
+            };
+          };
         };
       }