about summary refs log tree commit diff
path: root/modules/user/aszlig/programs
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2021-07-22 02:06:39 +0200
committeraszlig <aszlig@nix.build>2021-07-22 02:14:15 +0200
commit5de32f4fed13bebb23a958ffb501e782a77dd321 (patch)
tree2164407bc9c5fa6e861d0a73b77b36f16db7d034 /modules/user/aszlig/programs
parenta3a921c0acea92ea0a0a3afc5ead5bf1a5cdaee5 (diff)
workstation: Switch Git diff viewer to delta
I'm already using this config since a few months and since I'm slowly
getting used to it, let's try to make it the default for my workstation
profile.

Unfortunately, libgit2 uses the Git configuration from /etc, but our
configuration is directly patched into Git and not in /etc but in
"${pkgs.git}/etc", so we need to patch libgit2 to use the right
configuration file.

Another goof is that we can't use ${pkgs.delta} directly in our Git
configuration because it would introduce a circular dependency between
Git itself and delta (which uses libgit2 which in turn refers to
"${pkgs.git}/etc"), so for the time being I'm relying on $PATH for
delta.

Signed-off-by: aszlig <aszlig@nix.build>
Diffstat (limited to 'modules/user/aszlig/programs')
-rw-r--r--modules/user/aszlig/programs/git/default.nix24
1 files changed, 22 insertions, 2 deletions
diff --git a/modules/user/aszlig/programs/git/default.nix b/modules/user/aszlig/programs/git/default.nix
index b4c1d9a4..8a497bd7 100644
--- a/modules/user/aszlig/programs/git/default.nix
+++ b/modules/user/aszlig/programs/git/default.nix
@@ -4,7 +4,6 @@ let
   inherit (lib) types;
   cfg = config.vuizvui.user.aszlig.programs.git;
 
-
   gitPatched = pkgs.gitFull.overrideAttrs (git: {
     makeFlags = let
       oldFlags = git.makeFlags or [];
@@ -13,6 +12,18 @@ let
        then oldFlags ++ [ newVal ]
        else "${oldFlags} ${newVal}";
   });
+
+  libgit2Patched = pkgs.libgit2.overrideAttrs (drv: {
+    postPatch = (drv.postPatch or "") + ''
+      substituteInPlace src/sysdir.c \
+        --replace '"/etc"' ${lib.escapeShellArg "\"${cfg.configFile}\""}
+    '';
+  });
+
+  deltaPatched = pkgs.delta.overrideAttrs (drv: {
+    buildInputs = (drv.buildInputs or []) ++ lib.singleton libgit2Patched;
+  });
+
 in {
   options.vuizvui.user.aszlig.programs.git = {
     enable = lib.mkEnableOption "Git";
@@ -25,6 +36,8 @@ in {
       '';
     };
 
+    delta.enable = lib.mkEnableOption "using delta for Git diff";
+
     settings = lib.mkOption {
       type = let
         scalar = types.oneOf [ types.bool types.int types.str ];
@@ -73,10 +86,17 @@ in {
       lines = lib.flatten (lib.mapAttrsToList mkConf cfg.settings);
     in pkgs.writeText "gitconfig" (joinLines lines);
 
+    vuizvui.user.aszlig.programs.git.settings = lib.mkIf cfg.delta.enable {
+      interactive.diffFilter = "delta --color-only";
+      pager = lib.flip lib.genAttrs (lib.const "delta") [
+        "diff" "log" "reflog" "show"
+      ];
+    };
+
     environment.systemPackages = [
       gitPatched
       pkgs.gitAndTools.git-remote-hg
       pkgs.gitAndTools.hub
-    ];
+    ] ++ lib.optional cfg.delta.enable deltaPatched;
   };
 }