From 6dc4f31ba13215823c4641907b48825971a516e1 Mon Sep 17 00:00:00 2001 From: Tad Fisher Date: Wed, 18 Apr 2018 14:41:20 -0700 Subject: [PATCH] git: add 'includes' option --- modules/misc/news.nix | 22 +++++++++++++++++++ modules/programs/git.nix | 47 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 04669b13e..af122a23d 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 ed43e53e4..e8018dc18 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); + }) ] ); }