From 2ede089d11b68d7abfcb022c60cf71249504c3b0 Mon Sep 17 00:00:00 2001 From: Plume Date: Thu, 8 May 2025 15:15:51 +0200 Subject: [PATCH] git: configure patdiff through [patdiff] git section (#6978) This adds the ability to enable the patdiff program as git differ. Website of the project: https://opensource.janestreet.com/patdiff/ --- modules/programs/git.nix | 28 ++++++++++++++++++- tests/darwinScrublist.nix | 1 + tests/modules/programs/git/default.nix | 1 + .../programs/git/git-patdiff-expected.conf | 19 +++++++++++++ tests/modules/programs/git/git-patdiff.nix | 20 +++++++++++++ 5 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tests/modules/programs/git/git-patdiff-expected.conf create mode 100644 tests/modules/programs/git/git-patdiff.nix diff --git a/modules/programs/git.nix b/modules/programs/git.nix index 6862888d..8781178d 100644 --- a/modules/programs/git.nix +++ b/modules/programs/git.nix @@ -496,6 +496,17 @@ in ''; }; }; + + patdiff = { + enable = mkEnableOption "" // { + description = '' + Whether to enable the {command}`patdiff` differ. + See + ''; + }; + + package = mkPackageOption pkgs "patdiff" { }; + }; }; }; @@ -526,10 +537,11 @@ in cfg.difftastic.enable cfg.diff-highlight.enable cfg.riff.enable + cfg.patdiff.enable ]; in lib.count lib.id enabled <= 1; - message = "Only one of 'programs.git.delta.enable' or 'programs.git.difftastic.enable' or 'programs.git.diff-so-fancy.enable' or 'programs.git.diff-highlight' can be set to true at the same time."; + message = "Only one of 'programs.git.delta.enable' or 'programs.git.difftastic.enable' or 'programs.git.diff-so-fancy.enable' or 'programs.git.diff-highlight' or 'programs.git.patdiff' can be set to true at the same time."; } ]; @@ -902,6 +914,20 @@ in } ) + ( + let + patdiffPackage = cfg.patdiff.package; + patdiffCommand = "${lib.getExe' patdiffPackage "patdiff-git-wrapper"}"; + in + mkIf cfg.patdiff.enable { + home.packages = [ patdiffPackage ]; + + programs.git.iniContent = { + diff.external = patdiffCommand; + }; + } + ) + (mkIf (cfg.riff.enable && cfg.riff.commandLineOptions != "") { home.sessionVariables.RIFF = cfg.riff.commandLineOptions; }) diff --git a/tests/darwinScrublist.nix b/tests/darwinScrublist.nix index 943365cf..4dbc0335 100644 --- a/tests/darwinScrublist.nix +++ b/tests/darwinScrublist.nix @@ -45,6 +45,7 @@ let "gh-dash" "ghostty" "git" + "patdiff" "gitMinimal" "git-cliff" "git-credential-oauth" diff --git a/tests/modules/programs/git/default.nix b/tests/modules/programs/git/default.nix index 631b7f13..5f2330dd 100644 --- a/tests/modules/programs/git/default.nix +++ b/tests/modules/programs/git/default.nix @@ -9,4 +9,5 @@ git-without-signing = ./git-without-signing.nix; git-with-hooks = ./git-with-hooks.nix; git-with-maintenance = ./git-with-maintenance.nix; + git-patdiff = ./git-patdiff.nix; } diff --git a/tests/modules/programs/git/git-patdiff-expected.conf b/tests/modules/programs/git/git-patdiff-expected.conf new file mode 100644 index 00000000..e9965dc2 --- /dev/null +++ b/tests/modules/programs/git/git-patdiff-expected.conf @@ -0,0 +1,19 @@ +[commit] + gpgSign = true + +[diff] + external = "@patdiff@/bin/patdiff-git-wrapper" + +[gpg] + format = "openpgp" + +[gpg "openpgp"] + program = "path-to-gpg" + +[tag] + gpgSign = true + +[user] + email = "user@example.org" + name = "John Doe" + signingKey = "00112233445566778899AABBCCDDEEFF" diff --git a/tests/modules/programs/git/git-patdiff.nix b/tests/modules/programs/git/git-patdiff.nix new file mode 100644 index 00000000..82e5e02f --- /dev/null +++ b/tests/modules/programs/git/git-patdiff.nix @@ -0,0 +1,20 @@ +{ + programs.git = { + enable = true; + signing = { + signer = "path-to-gpg"; + format = "openpgp"; + key = "00112233445566778899AABBCCDDEEFF"; + signByDefault = true; + }; + userEmail = "user@example.org"; + userName = "John Doe"; + + patdiff.enable = true; + }; + + nmt.script = '' + assertFileExists home-files/.config/git/config + assertFileContent home-files/.config/git/config ${./git-patdiff-expected.conf} + ''; +}