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; }