From 2aa20ae969f2597c4df10a094440a66e9d7f8c86 Mon Sep 17 00:00:00 2001 From: Viacheslav Lotsmanov Date: Wed, 7 Apr 2021 22:46:34 +0300 Subject: [PATCH] =?UTF-8?q?Backport=20=E2=80=9CMake=20Git=20signing=20key?= =?UTF-8?q?=20id=20be=20optional=E2=80=9D=20to=20=E2=80=9Crelease-20.09?= =?UTF-8?q?=E2=80=9D=20(#1903)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/programs/git.nix | 11 +++++++--- tests/modules/programs/git/default.nix | 2 ++ .../git/git-with-signing-key-id-expected.conf | 10 +++++++++ .../programs/git/git-with-signing-key-id.nix | 22 +++++++++++++++++++ .../git-without-signing-key-id-expected.conf | 9 ++++++++ .../git/git-without-signing-key-id.nix | 22 +++++++++++++++++++ 6 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 tests/modules/programs/git/git-with-signing-key-id-expected.conf create mode 100644 tests/modules/programs/git/git-with-signing-key-id.nix create mode 100644 tests/modules/programs/git/git-without-signing-key-id-expected.conf create mode 100644 tests/modules/programs/git/git-without-signing-key-id.nix diff --git a/modules/programs/git.nix b/modules/programs/git.nix index 312269de..bd720b28 100644 --- a/modules/programs/git.nix +++ b/modules/programs/git.nix @@ -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. + + Set to null to let GnuPG decide what signing key + to use depending on commit’s author. + ''; }; signByDefault = mkOption { @@ -297,7 +302,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; }; diff --git a/tests/modules/programs/git/default.nix b/tests/modules/programs/git/default.nix index 45aface8..e57a1898 100644 --- a/tests/modules/programs/git/default.nix +++ b/tests/modules/programs/git/default.nix @@ -2,4 +2,6 @@ git-with-email = ./git-with-email.nix; git-with-most-options = ./git.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; } diff --git a/tests/modules/programs/git/git-with-signing-key-id-expected.conf b/tests/modules/programs/git/git-with-signing-key-id-expected.conf new file mode 100644 index 00000000..4a428990 --- /dev/null +++ b/tests/modules/programs/git/git-with-signing-key-id-expected.conf @@ -0,0 +1,10 @@ +[commit] + gpgSign = true + +[gpg] + program = "path-to-gpg" + +[user] + email = "user@example.org" + name = "John Doe" + signingKey = "00112233445566778899AABBCCDDEEFF" diff --git a/tests/modules/programs/git/git-with-signing-key-id.nix b/tests/modules/programs/git/git-with-signing-key-id.nix new file mode 100644 index 00000000..8d182505 --- /dev/null +++ b/tests/modules/programs/git/git-with-signing-key-id.nix @@ -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 + } + ''; + }; +} diff --git a/tests/modules/programs/git/git-without-signing-key-id-expected.conf b/tests/modules/programs/git/git-without-signing-key-id-expected.conf new file mode 100644 index 00000000..7564b350 --- /dev/null +++ b/tests/modules/programs/git/git-without-signing-key-id-expected.conf @@ -0,0 +1,9 @@ +[commit] + gpgSign = true + +[gpg] + program = "path-to-gpg" + +[user] + email = "user@example.org" + name = "John Doe" diff --git a/tests/modules/programs/git/git-without-signing-key-id.nix b/tests/modules/programs/git/git-without-signing-key-id.nix new file mode 100644 index 00000000..3428c40d --- /dev/null +++ b/tests/modules/programs/git/git-without-signing-key-id.nix @@ -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 + } + ''; + }; +}