diff --git a/docs/src/reference/options.md b/docs/src/reference/options.md index 3cb3f615db..69ed5dbfd0 100644 --- a/docs/src/reference/options.md +++ b/docs/src/reference/options.md @@ -3040,6 +3040,122 @@ null or YAML 1.1 value +## git.conflictStyle + + + +Git conflict style (e.g., ‘merge’, ‘diff3’, ‘zdiff3’). + + + +*Type:* +null or string + + + +*Default:* +` null ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/git.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/git.nix) + + + +## git.diffTool + + + +Git diff tool to use (e.g., ‘difftastic’, ‘vimdiff’). + + + +*Type:* +null or string + + + +*Default:* +` null ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/git.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/git.nix) + + + +## git.mergeDriver + + + +Custom git merge drivers (e.g., mergiraf). + + + +*Type:* +attribute set of (submodule) + + + +*Default:* +` { } ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/git.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/git.nix) + + + +## git.mergeDriver.\.driver + + + +Driver command to run. + + + +*Type:* +string + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/git.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/git.nix) + + + +## git.mergeDriver.\.name + + + +Name of the merge driver. + + + +*Type:* +string + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/git.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/git.nix) + + + +## git.mergeTool + + + +Git merge tool to use (e.g., ‘vimdiff’, ‘meld’). + + + +*Type:* +null or string + + + +*Default:* +` null ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/git.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/git.nix) + + + ## git.root @@ -18468,6 +18584,27 @@ package +## mergiraf.enable + + + +Integrate mergiraf as git merge driver: https://mergiraf.org/ + + + +*Type:* +boolean + + + +*Default:* +` false ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/mergiraf.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/mergiraf.nix) + + + ## name diff --git a/src/modules/integrations/difftastic.nix b/src/modules/integrations/difftastic.nix index b8389fa70f..4a9f99cc37 100644 --- a/src/modules/integrations/difftastic.nix +++ b/src/modules/integrations/difftastic.nix @@ -10,6 +10,6 @@ config = lib.mkIf config.difftastic.enable { packages = [ pkgs.difftastic ]; - env.GIT_EXTERNAL_DIFF = "difft"; + git.diffTool = "difftastic"; }; } diff --git a/src/modules/integrations/git.nix b/src/modules/integrations/git.nix index ddc75ba116..755d23af2d 100644 --- a/src/modules/integrations/git.nix +++ b/src/modules/integrations/git.nix @@ -7,5 +7,65 @@ description = "Git repository root path. This field is populated automatically in devenv 1.10 and newer."; default = null; }; + + diffTool = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = "Git diff tool to use (e.g., 'difftastic', 'vimdiff')."; + default = null; + }; + + mergeTool = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = "Git merge tool to use (e.g., 'vimdiff', 'meld')."; + default = null; + }; + + mergeDriver = lib.mkOption { + type = lib.types.attrsOf (lib.types.submodule { + options = { + name = lib.mkOption { + type = lib.types.str; + description = "Name of the merge driver."; + }; + driver = lib.mkOption { + type = lib.types.str; + description = "Driver command to run."; + }; + }; + }); + description = "Custom git merge drivers (e.g., mergiraf)."; + default = { }; + }; + + conflictStyle = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = "Git conflict style (e.g., 'merge', 'diff3', 'zdiff3')."; + default = null; + }; + }; + + config = lib.mkIf (config.git.diffTool != null || config.git.mergeTool != null || config.git.mergeDriver != { } || config.git.conflictStyle != null) { + env.GIT_CONFIG_GLOBAL = lib.concatStringsSep "\n" ( + [ "[include]" " path = ~/.gitconfig" ] ++ + lib.optionals (config.git.diffTool != null) [ + "[diff]" + " tool = ${config.git.diffTool}" + ] ++ + lib.optionals (config.git.conflictStyle != null) [ + "[diff]" + " conflictStyle = ${config.git.conflictStyle}" + ] ++ + lib.optionals (config.git.mergeTool != null) [ + "[merge]" + " tool = ${config.git.mergeTool}" + ] ++ + lib.concatMap + (driverName: [ + "[merge \"${driverName}\"]" + " name = ${config.git.mergeDriver.${driverName}.name}" + " driver = ${config.git.mergeDriver.${driverName}.driver}" + ]) + (lib.attrNames config.git.mergeDriver) + ); }; } diff --git a/src/modules/integrations/mergiraf.nix b/src/modules/integrations/mergiraf.nix new file mode 100644 index 0000000000..72be4e4b30 --- /dev/null +++ b/src/modules/integrations/mergiraf.nix @@ -0,0 +1,23 @@ +{ pkgs, lib, config, ... }: + +{ + options.mergiraf.enable = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Integrate mergiraf as git merge driver: https://mergiraf.org/"; + }; + + config = lib.mkIf config.mergiraf.enable { + packages = [ pkgs.mergiraf ]; + + git = { + mergeTool = "mergiraf"; + mergeDriver.mergiraf = { + name = "mergiraf"; + driver = "mergiraf merge --git %O %A %B -s %S -x %X -y %Y -p %P -l %L"; + }; + # mergiraf requires diff3 conflict style to reconstruct the base revision + conflictStyle = "diff3"; + }; + }; +}