2017-01-07 19:16:26 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.git;
|
|
|
|
|
2019-03-13 00:06:36 +01:00
|
|
|
# create [section "subsection"] keys from "section.subsection" attrset names
|
|
|
|
mkSectionName = name:
|
|
|
|
let
|
|
|
|
containsQuote = strings.hasInfix ''"'' name;
|
|
|
|
sections = splitString "." name;
|
|
|
|
section = head sections;
|
|
|
|
subsections = tail sections;
|
|
|
|
subsection = concatStringsSep "." subsections;
|
|
|
|
in
|
|
|
|
if containsQuote || subsections == []
|
|
|
|
then name
|
|
|
|
else "${section} \"${subsection}\"";
|
|
|
|
|
2019-03-12 09:35:55 +01:00
|
|
|
# generation for multiple ini values
|
|
|
|
mkKeyValue = k: v:
|
|
|
|
let
|
|
|
|
mkKeyValue = generators.mkKeyValueDefault {} "=" k;
|
|
|
|
in
|
|
|
|
concatStringsSep "\n" (map mkKeyValue (toList v));
|
|
|
|
|
2019-03-13 00:06:36 +01:00
|
|
|
# converts { a.b.c = 5; } to { "a.b".c = 5; } for toINI
|
|
|
|
gitFlattenAttrs =
|
|
|
|
let
|
|
|
|
recurse = path: value:
|
|
|
|
if isAttrs value then
|
|
|
|
mapAttrsToList (name: value: recurse ([name] ++ path) value) value
|
|
|
|
else if length path > 1 then
|
|
|
|
{ ${concatStringsSep "." (reverseList (tail path))}.${head path} = value; }
|
|
|
|
else
|
|
|
|
{ ${head path} = value; };
|
|
|
|
in
|
|
|
|
attrs: foldl recursiveUpdate {} (flatten (recurse [] attrs));
|
|
|
|
|
|
|
|
gitToIni = attrs:
|
|
|
|
let
|
|
|
|
toIni = generators.toINI { inherit mkKeyValue mkSectionName; };
|
|
|
|
in
|
|
|
|
toIni (gitFlattenAttrs attrs);
|
2019-03-12 09:35:55 +01:00
|
|
|
|
2019-02-01 01:06:18 +01:00
|
|
|
gitIniType = with types;
|
|
|
|
let
|
2019-03-12 09:35:55 +01:00
|
|
|
primitiveType = either str (either bool int);
|
|
|
|
multipleType = either primitiveType (listOf primitiveType);
|
|
|
|
sectionType = attrsOf multipleType;
|
2019-03-13 00:06:36 +01:00
|
|
|
supersectionType = attrsOf (either multipleType sectionType);
|
2019-02-01 01:06:18 +01:00
|
|
|
in
|
2019-03-13 00:06:36 +01:00
|
|
|
attrsOf supersectionType;
|
2019-02-01 01:06:18 +01:00
|
|
|
|
2017-08-24 01:03:01 +02: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 19:16:26 +01:00
|
|
|
};
|
2017-08-24 01:03:01 +02:00
|
|
|
};
|
|
|
|
};
|
2017-01-07 19:16:26 +01:00
|
|
|
|
2019-01-29 12:33:10 +01:00
|
|
|
includeModule = types.submodule ({ config, ... }: {
|
2018-04-18 23:41:20 +02:00
|
|
|
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 {
|
2019-01-29 12:33:10 +01:00
|
|
|
type = with types; either str path;
|
2018-04-18 23:41:20 +02:00
|
|
|
description = "Path of the configuration file to include.";
|
|
|
|
};
|
2019-01-29 12:33:10 +01:00
|
|
|
|
|
|
|
contents = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
Configuration to include. If empty then a path must be given.
|
|
|
|
'';
|
|
|
|
};
|
2018-04-18 23:41:20 +02:00
|
|
|
};
|
2019-01-29 12:33:10 +01:00
|
|
|
|
|
|
|
config.path = mkIf (config.contents != {}) (
|
2019-03-12 09:35:55 +01:00
|
|
|
mkDefault (pkgs.writeText "contents" (gitToIni config.contents))
|
2019-01-29 12:33:10 +01:00
|
|
|
);
|
|
|
|
});
|
2018-04-18 23:41:20 +02:00
|
|
|
|
2017-01-07 19:16:26 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2017-09-26 23:40:31 +02:00
|
|
|
meta.maintainers = [ maintainers.rycee ];
|
|
|
|
|
2017-01-07 19:16:26 +01:00
|
|
|
options = {
|
|
|
|
programs.git = {
|
|
|
|
enable = mkEnableOption "Git";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.git;
|
2019-08-28 00:12:28 +02:00
|
|
|
defaultText = literalExample "pkgs.git";
|
2019-01-21 09:14:22 +01:00
|
|
|
description = ''
|
|
|
|
Git package to install. Use <varname>pkgs.gitAndTools.gitFull</varname>
|
|
|
|
to gain access to <command>git send-email</command> for instance.
|
|
|
|
'';
|
2017-01-07 19:16:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
userName = mkOption {
|
2019-03-12 09:36:17 +01:00
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2017-01-07 19:16:26 +01:00
|
|
|
description = "Default user name to use.";
|
|
|
|
};
|
|
|
|
|
|
|
|
userEmail = mkOption {
|
2019-03-12 09:36:17 +01:00
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2017-01-07 19:16:26 +01:00
|
|
|
description = "Default user email to use.";
|
|
|
|
};
|
|
|
|
|
|
|
|
aliases = mkOption {
|
2019-02-01 01:06:18 +01:00
|
|
|
type = types.attrsOf types.str;
|
2017-01-07 19:16:26 +01:00
|
|
|
default = {};
|
2019-02-01 01:06:18 +01:00
|
|
|
example = { co = "checkout"; };
|
2017-01-07 19:16:26 +01:00
|
|
|
description = "Git aliases to define.";
|
|
|
|
};
|
|
|
|
|
|
|
|
signing = mkOption {
|
|
|
|
type = types.nullOr signModule;
|
|
|
|
default = null;
|
|
|
|
description = "Options related to signing commits using GnuPG.";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2019-02-01 01:06:18 +01:00
|
|
|
type = types.either types.lines gitIniType;
|
2017-09-21 14:45:20 +02:00
|
|
|
default = {};
|
2019-02-01 01:06:18 +01:00
|
|
|
example = {
|
|
|
|
core = { whitespace = "trailing-space,space-before-tab"; };
|
2019-03-13 00:06:36 +01:00
|
|
|
url."ssh://git@host".insteadOf = "otherhost";
|
2019-02-01 01:06:18 +01:00
|
|
|
};
|
2019-08-30 14:50:10 +02:00
|
|
|
description = ''
|
|
|
|
Additional configuration to add. The use of string values is
|
|
|
|
deprecated and will be removed in the future.
|
|
|
|
'';
|
2017-01-07 19:16:26 +01:00
|
|
|
};
|
2017-09-21 14:45:20 +02:00
|
|
|
|
|
|
|
iniContent = mkOption {
|
2019-02-01 01:06:18 +01:00
|
|
|
type = gitIniType;
|
2017-09-21 14:45:20 +02:00
|
|
|
internal = true;
|
|
|
|
};
|
2017-11-12 13:28:12 +01:00
|
|
|
|
|
|
|
ignores = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "*~" "*.swp" ];
|
|
|
|
description = "List of paths that should be globally ignored.";
|
|
|
|
};
|
2018-04-18 23:41:20 +02: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.";
|
|
|
|
};
|
2019-02-03 23:54:29 +01:00
|
|
|
|
|
|
|
lfs = {
|
|
|
|
enable = mkEnableOption "Git Large File Storage";
|
|
|
|
|
|
|
|
skipSmudge = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Skip automatic downloading of objects on clone or pull.
|
|
|
|
This requires a manual <command>git lfs pull</command>
|
|
|
|
every time a new commit is checked out on your repository.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2017-01-07 19:16:26 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (
|
2017-09-21 14:45:20 +02:00
|
|
|
mkMerge [
|
|
|
|
{
|
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
|
|
|
|
programs.git.iniContent.user = {
|
2019-03-12 09:36:17 +01:00
|
|
|
name = mkIf (cfg.userName != null) cfg.userName;
|
|
|
|
email = mkIf (cfg.userEmail != null) cfg.userEmail;
|
2017-01-07 19:16:26 +01:00
|
|
|
};
|
|
|
|
|
2017-11-12 13:28:12 +01:00
|
|
|
xdg.configFile = {
|
2019-03-12 09:35:55 +01:00
|
|
|
"git/config".text = gitToIni cfg.iniContent;
|
2017-11-12 13:28:12 +01:00
|
|
|
|
|
|
|
"git/ignore" = mkIf (cfg.ignores != []) {
|
|
|
|
text = concatStringsSep "\n" cfg.ignores + "\n";
|
|
|
|
};
|
|
|
|
};
|
2017-01-07 19:16:26 +01:00
|
|
|
}
|
2017-09-21 14:45:20 +02:00
|
|
|
|
2019-01-21 09:14:22 +01:00
|
|
|
{
|
|
|
|
programs.git.iniContent =
|
|
|
|
let
|
|
|
|
hasSmtp = name: account: account.smtp != null;
|
|
|
|
|
|
|
|
genIdentity = name: account: with account;
|
2019-03-13 00:06:36 +01:00
|
|
|
nameValuePair "sendemail.${name}" ({
|
2019-01-21 09:14:22 +01:00
|
|
|
smtpEncryption = if smtp.tls.enable then "tls" else "";
|
|
|
|
smtpServer = smtp.host;
|
|
|
|
smtpUser = userName;
|
|
|
|
from = address;
|
|
|
|
}
|
|
|
|
// optionalAttrs (smtp.port != null) {
|
|
|
|
smtpServerPort = smtp.port;
|
|
|
|
});
|
|
|
|
in
|
|
|
|
mapAttrs' genIdentity
|
|
|
|
(filterAttrs hasSmtp config.accounts.email.accounts);
|
|
|
|
}
|
|
|
|
|
2017-09-21 14:45:20 +02: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) {
|
2019-08-30 14:50:10 +02:00
|
|
|
warnings = [
|
|
|
|
''
|
|
|
|
Using programs.git.extraConfig as a string option is
|
|
|
|
deprecated and will be removed in the future. Please
|
|
|
|
change to using it as an attribute set instead.
|
|
|
|
''
|
|
|
|
];
|
|
|
|
|
2017-11-12 12:53:10 +01:00
|
|
|
xdg.configFile."git/config".text = cfg.extraConfig;
|
2017-09-21 14:45:20 +02:00
|
|
|
})
|
2018-04-18 23:41:20 +02:00
|
|
|
|
|
|
|
(mkIf (cfg.includes != []) {
|
2019-03-13 00:06:36 +01:00
|
|
|
xdg.configFile."git/config".text =
|
|
|
|
let
|
|
|
|
include = i: with i;
|
|
|
|
if condition != null
|
|
|
|
then { includeIf.${condition}.path = "${path}"; }
|
|
|
|
else { include.path = "${path}"; };
|
|
|
|
in
|
|
|
|
mkAfter
|
|
|
|
(concatStringsSep "\n"
|
|
|
|
(map gitToIni
|
|
|
|
(map include cfg.includes)));
|
2018-04-18 23:41:20 +02:00
|
|
|
})
|
2019-02-03 23:54:29 +01:00
|
|
|
|
|
|
|
(mkIf cfg.lfs.enable {
|
|
|
|
home.packages = [ pkgs.git-lfs ];
|
|
|
|
|
2019-03-13 00:06:36 +01:00
|
|
|
programs.git.iniContent.filter.lfs =
|
2019-02-03 23:54:29 +01:00
|
|
|
let
|
|
|
|
skipArg = optional cfg.lfs.skipSmudge "--skip";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
clean = "git-lfs clean -- %f";
|
|
|
|
process = concatStringsSep " " (
|
|
|
|
[ "git-lfs" "filter-process" ] ++ skipArg
|
|
|
|
);
|
|
|
|
required = true;
|
|
|
|
smudge = concatStringsSep " " (
|
|
|
|
[ "git-lfs" "smudge" ] ++ skipArg ++ [ "--" "%f" ]
|
|
|
|
);
|
|
|
|
};
|
|
|
|
})
|
2017-09-21 14:45:20 +02:00
|
|
|
]
|
2017-01-07 19:16:26 +01:00
|
|
|
);
|
|
|
|
}
|