From 5de32f4fed13bebb23a958ffb501e782a77dd321 Mon Sep 17 00:00:00 2001 From: aszlig Date: Thu, 22 Jul 2021 02:06:39 +0200 Subject: 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 --- .../user/aszlig/profiles/workstation/default.nix | 13 ++++++++++++ modules/user/aszlig/programs/git/default.nix | 24 ++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/user/aszlig/profiles/workstation/default.nix b/modules/user/aszlig/profiles/workstation/default.nix index 5e1976a8..a2958f36 100644 --- a/modules/user/aszlig/profiles/workstation/default.nix +++ b/modules/user/aszlig/profiles/workstation/default.nix @@ -78,6 +78,7 @@ in { vuizvui.user.aszlig.programs.mpv.enable = true; vuizvui.user.aszlig.programs.git.enable = true; + vuizvui.user.aszlig.programs.git.delta.enable = true; vuizvui.user.aszlig.programs.git.settings = { color.ui = "auto"; user.email = "aszlig@nix.build"; @@ -94,6 +95,18 @@ in { merge.tool = "vimdiff3"; merge.conflictstyle = "diff3"; + + delta = { + commit-decoration-style = "bold yellow box"; + file-decoration-style = "blue ul"; + file-style = "bold blue ul"; + hunk-header-style = "line-number dim italic syntax"; + hunk-header-decoration-style = "blue"; + hunk-header-line-number-style = "cyan"; + plus-style = "syntax auto"; + minus-style = "syntax auto"; + line-numbers = true; + }; }; vuizvui.hardware.gameController."03000000ff1100004133000010010000" = { 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; }; } -- cgit 1.4.1