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

programs.git: make signing key id be optional (#1886)

* Git: Make signing key id be optional

Thus by default the signing key is selected by commit’s author.

* Git: Add tests for config with and without signing key id
* Git: Format tests for signing key
* Git: Remove default value (null) for signing key
* Git: Update description for signing key
This commit is contained in:
Viacheslav Lotsmanov 2021-04-05 15:28:36 +03:00 committed by GitHub
parent 25a6a6d298
commit cc60c22c69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 73 additions and 3 deletions

View file

@ -61,8 +61,13 @@ let
signModule = types.submodule {
options = {
key = mkOption {
type = types.str;
description = "The default GPG signing key fingerprint.";
type = types.nullOr types.str;
description = ''
The default GPG signing key fingerprint.
</para><para>
Set to <literal>null</literal> to let GnuPG decide what signing key
to use depending on commits author.
'';
};
signByDefault = mkOption {
@ -303,7 +308,7 @@ in {
(mkIf (cfg.signing != null) {
programs.git.iniContent = {
user.signingKey = cfg.signing.key;
user.signingKey = mkIf (cfg.signing.key != null) cfg.signing.key;
commit.gpgSign = cfg.signing.signByDefault;
gpg.program = cfg.signing.gpgPath;
};

View file

@ -3,4 +3,6 @@
git-with-most-options = ./git.nix;
git-with-msmtp = ./git-with-msmtp.nix;
git-with-str-extra-config = ./git-with-str-extra-config.nix;
git-with-signing-key-id = ./git-with-signing-key-id.nix;
git-without-signing-key-id = ./git-without-signing-key-id.nix;
}

View file

@ -0,0 +1,10 @@
[commit]
gpgSign = true
[gpg]
program = "path-to-gpg"
[user]
email = "user@example.org"
name = "John Doe"
signingKey = "00112233445566778899AABBCCDDEEFF"

View file

@ -0,0 +1,22 @@
{ pkgs, ... }: {
config = {
programs.git = {
enable = true;
userName = "John Doe";
userEmail = "user@example.org";
signing = {
gpgPath = "path-to-gpg";
key = "00112233445566778899AABBCCDDEEFF";
signByDefault = true;
};
};
nmt.script = ''
assertFileExists home-files/.config/git/config
assertFileContent home-files/.config/git/config ${
./git-with-signing-key-id-expected.conf
}
'';
};
}

View file

@ -0,0 +1,9 @@
[commit]
gpgSign = true
[gpg]
program = "path-to-gpg"
[user]
email = "user@example.org"
name = "John Doe"

View file

@ -0,0 +1,22 @@
{ pkgs, ... }: {
config = {
programs.git = {
enable = true;
userName = "John Doe";
userEmail = "user@example.org";
signing = {
gpgPath = "path-to-gpg";
key = null;
signByDefault = true;
};
};
nmt.script = ''
assertFileExists home-files/.config/git/config
assertFileContent home-files/.config/git/config ${
./git-without-signing-key-id-expected.conf
}
'';
};
}