1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-20 10:09:45 +01:00

gh: option to enable helper for additional hosts (#4288)

* gh: option to enable helper for additional hosts

`gh` can also be used with github enterprise
hosts, for which there exists no easy option
to enable the credential helper except for
directly working with `programs.git.extraConfig`.
Not sure if this is a needed addition since it's
somewhat niche, at the same time it's not very
complex and makes the life of github enterprise
a little easier.

* gh: update credential-helper tests

* gh: refactor credential helper option

this moves from `enableGitCredentialHelper` to
`gitCredentialHelper.enable` and
`gitCredentialHelper.hosts`.

* gh: lib.mkIf -> mkIf
This commit is contained in:
satoqz 2023-07-31 16:40:37 -07:00 committed by GitHub
parent 3db43afcb4
commit 4fd794d3df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 6 deletions

View file

@ -60,6 +60,12 @@ in {
"settings" "settings"
"git_protocol" "git_protocol"
]) ])
(mkRenamedOptionModule [ "programs" "gh" "enableGitCredentialHelper" ] [
"programs"
"gh"
"gitCredentialHelper"
"enable"
])
]; ];
options.programs.gh = { options.programs.gh = {
@ -91,11 +97,21 @@ in {
''; '';
}; };
enableGitCredentialHelper = gitCredentialHelper = {
mkEnableOption "the gh git credential helper for github.com" // { enable = mkEnableOption "the gh git credential helper" // {
default = true; default = true;
}; };
hosts = mkOption {
type = types.listOf types.str;
default = [ "https://github.com" ];
description = "GitHub hosts to enable the gh git credential helper for";
example = literalExpression ''
[ "https://github.com" "https://github.example.com" ]
'';
};
};
extensions = mkOption { extensions = mkOption {
type = types.listOf types.package; type = types.listOf types.package;
default = [ ]; default = [ ];
@ -112,9 +128,11 @@ in {
xdg.configFile."gh/config.yml".source = xdg.configFile."gh/config.yml".source =
yamlFormat.generate "gh-config.yml" cfg.settings; yamlFormat.generate "gh-config.yml" cfg.settings;
programs.git.extraConfig.credential."https://github.com".helper = programs.git.extraConfig.credential = mkIf cfg.gitCredentialHelper.enable
mkIf cfg.enableGitCredentialHelper (builtins.listToAttrs (map (host:
"${cfg.package}/bin/gh auth git-credential"; lib.nameValuePair host {
helper = "${cfg.package}/bin/gh auth git-credential";
}) cfg.gitCredentialHelper.hosts));
xdg.dataFile."gh/extensions" = mkIf (cfg.extensions != [ ]) { xdg.dataFile."gh/extensions" = mkIf (cfg.extensions != [ ]) {
source = pkgs.linkFarm "gh-extensions" (builtins.map (p: { source = pkgs.linkFarm "gh-extensions" (builtins.map (p: {

View file

@ -1,2 +1,5 @@
[credential "https://github.com"] [credential "https://github.com"]
helper = "@gh@/bin/gh auth git-credential" helper = "@gh@/bin/gh auth git-credential"
[credential "https://github.example.com"]
helper = "@gh@/bin/gh auth git-credential"

View file

@ -3,7 +3,10 @@
{ {
programs.gh = { programs.gh = {
enable = true; enable = true;
enableGitCredentialHelper = true; gitCredentialHelper = {
enable = true;
hosts = [ "https://github.com" "https://github.example.com" ];
};
}; };
programs.git.enable = true; programs.git.enable = true;