From cfe82d9f444a1b77f135070f1c1ee63fa061f2fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anselm=20Sch=C3=BCler?= Date: Tue, 19 Oct 2021 06:43:52 +0200 Subject: [PATCH] gh: support gh as git credential manager for github.com Co-authored-by: Sumner Evans --- modules/programs/gh.nix | 9 ++++++++ .../programs/gh/credential-helper.git.conf | 2 ++ .../modules/programs/gh/credential-helper.nix | 21 +++++++++++++++++++ tests/modules/programs/gh/default.nix | 1 + 4 files changed, 33 insertions(+) create mode 100644 tests/modules/programs/gh/credential-helper.git.conf create mode 100644 tests/modules/programs/gh/credential-helper.nix diff --git a/modules/programs/gh.nix b/modules/programs/gh.nix index fd44d22b0..ba457c8cb 100644 --- a/modules/programs/gh.nix +++ b/modules/programs/gh.nix @@ -90,6 +90,11 @@ in { }; ''; }; + + enableGitCredentialHelper = + mkEnableOption "the gh git credential helper for github.com" // { + default = true; + }; }; config = mkIf cfg.enable { @@ -97,5 +102,9 @@ in { xdg.configFile."gh/config.yml".source = yamlFormat.generate "gh-config.yml" cfg.settings; + + programs.git.extraConfig.credential."https://github.com".helper = + mkIf cfg.enableGitCredentialHelper + "${cfg.package}/bin/gh auth git-credential"; }; } diff --git a/tests/modules/programs/gh/credential-helper.git.conf b/tests/modules/programs/gh/credential-helper.git.conf new file mode 100644 index 000000000..ea2c61ee4 --- /dev/null +++ b/tests/modules/programs/gh/credential-helper.git.conf @@ -0,0 +1,2 @@ +[credential "https://github.com"] + helper = "@gh@/bin/gh auth git-credential" diff --git a/tests/modules/programs/gh/credential-helper.nix b/tests/modules/programs/gh/credential-helper.nix new file mode 100644 index 000000000..e7ee8e42b --- /dev/null +++ b/tests/modules/programs/gh/credential-helper.nix @@ -0,0 +1,21 @@ +{ config, lib, pkgs, ... }: + +{ + programs.gh = { + enable = true; + enableGitCredentialHelper = true; + }; + + programs.git.enable = true; + + test.stubs = { + gh = { }; + git = { }; + }; + + nmt.script = '' + assertFileExists home-files/.config/git/config + assertFileContent home-files/.config/git/config \ + ${./credential-helper.git.conf} + ''; +} diff --git a/tests/modules/programs/gh/default.nix b/tests/modules/programs/gh/default.nix index 0a9157448..c683b484e 100644 --- a/tests/modules/programs/gh/default.nix +++ b/tests/modules/programs/gh/default.nix @@ -1,4 +1,5 @@ { gh-config-file = ./config-file.nix; + gh-credential-helper = ./credential-helper.nix; gh-warnings = ./warnings.nix; }