1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-24 02:39:48 +01:00

git: change extraConfig from lines to attrs

This commit is contained in:
Nikita Uvarov 2017-09-21 14:45:20 +02:00 committed by Robert Helgesson
parent db55e596d2
commit 0f096f9ad4
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86
2 changed files with 63 additions and 18 deletions

View file

@ -192,6 +192,34 @@ in
A new service is available: 'services.screen-locker'.
'';
}
{
time = "2017-09-22T12:09:01+00:00";
condition = isString config.programs.git.extraConfig;
message = ''
The 'programs.git.extraConfig' parameter now accepts
attributes instead of strings which allows more flexible
configuration.
The string parameter type will be deprecated in the future,
please change your configuration file accordingly.
For example, if your configuration includes
programs.git.extraConfig = '''
[core]
editor = vim
''';
then you can now change it to
programs.git.extraConfig = {
core = {
editor = "vim";
};
};
'';
}
];
};
}

View file

@ -65,34 +65,51 @@ in
};
extraConfig = mkOption {
type = types.lines;
default = "";
type = types.either types.attrs types.lines;
default = {};
description = "Additional configuration to add.";
};
iniContent = mkOption {
type = types.attrsOf types.attrs;
internal = true;
};
};
};
config = mkIf cfg.enable (
let
ini = {
user = {
name = cfg.userName;
email = cfg.userEmail;
} // optionalAttrs (cfg.signing != null) {
signingKey = cfg.signing.key;
};
} // optionalAttrs (cfg.signing != null) {
commit.gpgSign = cfg.signing.signByDefault;
gpg.program = cfg.signing.gpgPath;
} // optionalAttrs (cfg.aliases != {}) {
alias = cfg.aliases;
};
in
mkMerge [
{
home.packages = [ cfg.package ];
programs.git.iniContent.user = {
name = cfg.userName;
email = cfg.userEmail;
};
home.file.".gitconfig".text =
generators.toINI {} ini + "\n" + cfg.extraConfig;
generators.toINI {} cfg.iniContent;
}
(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) {
home.file.".gitconfig".text = cfg.extraConfig;
})
]
);
}