git: add 'includes' option

This commit is contained in:
Tad Fisher 2018-04-18 14:41:20 -07:00 committed by Robert Helgesson
parent d294aa4356
commit 6dc4f31ba1
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
2 changed files with 69 additions and 0 deletions

View file

@ -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.
'';
}
];
};
}

View file

@ -28,6 +28,28 @@ let
};
};
includeModule = types.submodule {
options = {
condition = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Include this configuration only when <varname>condition</varname>
matches. Allowed conditions are described in
<citerefentry>
<refentrytitle>git-config</refentrytitle>
<manvolnum>1</manvolnum>
</citerefentry>.
'';
};
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);
})
]
);
}