2017-01-07 18:16:26 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.git;
|
|
|
|
|
2017-08-23 23:03:01 +00:00
|
|
|
signModule = types.submodule {
|
|
|
|
options = {
|
|
|
|
key = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "The default GPG signing key fingerprint.";
|
|
|
|
};
|
|
|
|
|
|
|
|
signByDefault = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Whether commits should be signed by default.";
|
|
|
|
};
|
|
|
|
|
|
|
|
gpgPath = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "${pkgs.gnupg}/bin/gpg2";
|
|
|
|
defaultText = "\${pkgs.gnupg}/bin/gpg2";
|
|
|
|
description = "Path to GnuPG binary to use.";
|
2017-01-07 18:16:26 +00:00
|
|
|
};
|
2017-08-23 23:03:01 +00:00
|
|
|
};
|
|
|
|
};
|
2017-01-07 18:16:26 +00:00
|
|
|
|
2018-04-18 21:41:20 +00:00
|
|
|
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.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-01-07 18:16:26 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2017-09-26 21:40:31 +00:00
|
|
|
meta.maintainers = [ maintainers.rycee ];
|
|
|
|
|
2017-01-07 18:16:26 +00:00
|
|
|
options = {
|
|
|
|
programs.git = {
|
|
|
|
enable = mkEnableOption "Git";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.git;
|
|
|
|
defaultText = "pkgs.git";
|
|
|
|
description = "Git package to install.";
|
|
|
|
};
|
|
|
|
|
|
|
|
userName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "Default user name to use.";
|
|
|
|
};
|
|
|
|
|
|
|
|
userEmail = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "Default user email to use.";
|
|
|
|
};
|
|
|
|
|
|
|
|
aliases = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = {};
|
|
|
|
description = "Git aliases to define.";
|
|
|
|
};
|
|
|
|
|
|
|
|
signing = mkOption {
|
|
|
|
type = types.nullOr signModule;
|
|
|
|
default = null;
|
|
|
|
description = "Options related to signing commits using GnuPG.";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2017-09-21 12:45:20 +00:00
|
|
|
type = types.either types.attrs types.lines;
|
|
|
|
default = {};
|
2017-01-07 18:16:26 +00:00
|
|
|
description = "Additional configuration to add.";
|
|
|
|
};
|
2017-09-21 12:45:20 +00:00
|
|
|
|
|
|
|
iniContent = mkOption {
|
|
|
|
type = types.attrsOf types.attrs;
|
|
|
|
internal = true;
|
|
|
|
};
|
2017-11-12 12:28:12 +00:00
|
|
|
|
|
|
|
ignores = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "*~" "*.swp" ];
|
|
|
|
description = "List of paths that should be globally ignored.";
|
|
|
|
};
|
2018-04-18 21:41:20 +00:00
|
|
|
|
|
|
|
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.";
|
|
|
|
};
|
2017-01-07 18:16:26 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (
|
2017-09-21 12:45:20 +00:00
|
|
|
mkMerge [
|
|
|
|
{
|
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
|
|
|
|
programs.git.iniContent.user = {
|
2017-01-07 18:16:26 +00:00
|
|
|
name = cfg.userName;
|
|
|
|
email = cfg.userEmail;
|
|
|
|
};
|
|
|
|
|
2017-11-12 12:28:12 +00:00
|
|
|
xdg.configFile = {
|
|
|
|
"git/config".text = generators.toINI {} cfg.iniContent;
|
|
|
|
|
|
|
|
"git/ignore" = mkIf (cfg.ignores != []) {
|
|
|
|
text = concatStringsSep "\n" cfg.ignores + "\n";
|
|
|
|
};
|
|
|
|
};
|
2017-01-07 18:16:26 +00:00
|
|
|
}
|
2017-09-21 12:45:20 +00:00
|
|
|
|
|
|
|
(mkIf (cfg.signing != null) {
|
|
|
|
programs.git.iniContent = {
|
|
|
|
user.signingKey = cfg.signing.key;
|
|
|
|
commit.gpgSign = cfg.signing.signByDefault;
|
|
|
|
gpg.program = cfg.signing.gpgPath;
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf (cfg.aliases != {}) {
|
|
|
|
programs.git.iniContent.alias = cfg.aliases;
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf (lib.isAttrs cfg.extraConfig) {
|
|
|
|
programs.git.iniContent = cfg.extraConfig;
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf (lib.isString cfg.extraConfig) {
|
2017-11-12 11:53:10 +00:00
|
|
|
xdg.configFile."git/config".text = cfg.extraConfig;
|
2017-09-21 12:45:20 +00:00
|
|
|
})
|
2018-04-18 21:41:20 +00:00
|
|
|
|
|
|
|
(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);
|
|
|
|
})
|
2017-09-21 12:45:20 +00:00
|
|
|
]
|
2017-01-07 18:16:26 +00:00
|
|
|
);
|
|
|
|
}
|