mirror of
https://github.com/nix-community/home-manager
synced 2024-11-16 08:09:45 +01:00
4fd794d3df
* 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
144 lines
3.6 KiB
Nix
144 lines
3.6 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.programs.gh;
|
|
|
|
yamlFormat = pkgs.formats.yaml { };
|
|
|
|
settingsType = types.submodule {
|
|
freeformType = yamlFormat.type;
|
|
# These options are only here for the mkRenamedOptionModule support
|
|
options = {
|
|
aliases = mkOption {
|
|
type = with types; attrsOf str;
|
|
default = { };
|
|
example = literalExpression ''
|
|
{
|
|
co = "pr checkout";
|
|
pv = "pr view";
|
|
}
|
|
'';
|
|
description = ''
|
|
Aliases that allow you to create nicknames for gh commands.
|
|
'';
|
|
};
|
|
editor = mkOption {
|
|
type = types.str;
|
|
default = "";
|
|
description = ''
|
|
The editor that gh should run when creating issues, pull requests, etc.
|
|
If blank, will refer to environment.
|
|
'';
|
|
};
|
|
git_protocol = mkOption {
|
|
type = types.str;
|
|
default = "https";
|
|
example = "ssh";
|
|
description = ''
|
|
The protocol to use when performing Git operations.
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
|
|
in {
|
|
meta.maintainers = [ maintainers.gerschtli maintainers.berbiche ];
|
|
|
|
imports = (map (x:
|
|
mkRenamedOptionModule [ "programs" "gh" x ] [
|
|
"programs"
|
|
"gh"
|
|
"settings"
|
|
x
|
|
]) [ "aliases" "editor" ]) ++ [
|
|
(mkRenamedOptionModule [ "programs" "gh" "gitProtocol" ] [
|
|
"programs"
|
|
"gh"
|
|
"settings"
|
|
"git_protocol"
|
|
])
|
|
(mkRenamedOptionModule [ "programs" "gh" "enableGitCredentialHelper" ] [
|
|
"programs"
|
|
"gh"
|
|
"gitCredentialHelper"
|
|
"enable"
|
|
])
|
|
];
|
|
|
|
options.programs.gh = {
|
|
enable = mkEnableOption "GitHub CLI tool";
|
|
|
|
package = mkOption {
|
|
type = types.package;
|
|
default = pkgs.gh;
|
|
defaultText = literalExpression "pkgs.gh";
|
|
description = "Package providing {command}`gh`.";
|
|
};
|
|
|
|
settings = mkOption {
|
|
type = settingsType;
|
|
default = { };
|
|
description =
|
|
"Configuration written to {file}`$XDG_CONFIG_HOME/gh/config.yml`.";
|
|
example = literalExpression ''
|
|
{
|
|
git_protocol = "ssh";
|
|
|
|
prompt = "enabled";
|
|
|
|
aliases = {
|
|
co = "pr checkout";
|
|
pv = "pr view";
|
|
};
|
|
};
|
|
'';
|
|
};
|
|
|
|
gitCredentialHelper = {
|
|
enable = mkEnableOption "the gh git credential helper" // {
|
|
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 {
|
|
type = types.listOf types.package;
|
|
default = [ ];
|
|
description = ''
|
|
gh extensions, see <https://cli.github.com/manual/gh_extension>.
|
|
'';
|
|
example = literalExpression "[ pkgs.gh-eco ]";
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
home.packages = [ cfg.package ];
|
|
|
|
xdg.configFile."gh/config.yml".source =
|
|
yamlFormat.generate "gh-config.yml" cfg.settings;
|
|
|
|
programs.git.extraConfig.credential = mkIf cfg.gitCredentialHelper.enable
|
|
(builtins.listToAttrs (map (host:
|
|
lib.nameValuePair host {
|
|
helper = "${cfg.package}/bin/gh auth git-credential";
|
|
}) cfg.gitCredentialHelper.hosts));
|
|
|
|
xdg.dataFile."gh/extensions" = mkIf (cfg.extensions != [ ]) {
|
|
source = pkgs.linkFarm "gh-extensions" (builtins.map (p: {
|
|
name = p.pname;
|
|
path = "${p}/bin";
|
|
}) cfg.extensions);
|
|
};
|
|
};
|
|
}
|