diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 04669b13..af122a23 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -612,6 +612,28 @@ in A new module is available: 'programs.autorandr'. ''; } + + { + time = "2018-04-19T15:44:55+00:00"; + condition = config.programs.git.enable; + message = '' + A new option 'programs.git.includes' is available. Additional + Git configuration files may be included via + + programs.git.includes = [ + { path = "~/path/to/config.inc"; } + ]; + + or conditionally via + + programs.git.includes = [ + { path = "~/path/to/config.inc"; condition = "gitdir:~/src/"; } + ]; + + and the corresponding '[include]' or '[includeIf]' sections will be + appended to the main Git configuration file. + ''; + } ]; }; } diff --git a/modules/programs/git.nix b/modules/programs/git.nix index ed43e53e..e8018dc1 100644 --- a/modules/programs/git.nix +++ b/modules/programs/git.nix @@ -28,6 +28,28 @@ let }; }; + includeModule = types.submodule { + options = { + condition = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + Include this configuration only when condition + matches. Allowed conditions are described in + + git-config + 1 + . + ''; + }; + + path = mkOption { + type = types.str; + description = "Path of the configuration file to include."; + }; + }; + }; + in { @@ -83,6 +105,21 @@ in example = [ "*~" "*.swp" ]; description = "List of paths that should be globally ignored."; }; + + includes = mkOption { + type = types.listOf includeModule; + default = []; + example = literalExample '' + [ + { path = "~/path/to/config.inc"; } + { + path = "~/path/to/conditional.inc"; + condition = "gitdir:~/src/dir"; + } + ] + ''; + description = "List of configuration files to include."; + }; }; }; @@ -124,6 +161,16 @@ in (mkIf (lib.isString cfg.extraConfig) { xdg.configFile."git/config".text = cfg.extraConfig; }) + + (mkIf (cfg.includes != []) { + xdg.configFile."git/config".text = mkAfter + (concatMapStringsSep "\n" + (i: with i; '' + [${if (condition == null) then "include" else "includeIf \"${condition}\""}] + path = ${path} + '') + cfg.includes); + }) ] ); }