gh: add `extensions` option

This commit is contained in:
amesgen 2022-07-27 22:39:03 +02:00 committed by Robert Helgesson
parent 78f964347c
commit 8675cfa549
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89
3 changed files with 44 additions and 0 deletions

View File

@ -95,6 +95,15 @@ in {
mkEnableOption "the gh git credential helper for github.com" // {
default = true;
};
extensions = mkOption {
type = types.listOf types.package;
default = [ ];
description = ''
gh extensions, see <link xlink:href="https://cli.github.com/manual/gh_extension"/>.
'';
example = literalExpression "[ pkgs.gh-eco ]";
};
};
config = mkIf cfg.enable {
@ -106,5 +115,12 @@ in {
programs.git.extraConfig.credential."https://github.com".helper =
mkIf cfg.enableGitCredentialHelper
"${cfg.package}/bin/gh auth git-credential";
xdg.dataFile."gh/extensions" = mkIf (cfg.extensions != [ ]) {
source = pkgs.linkFarm "gh-extensions" (builtins.map (p: {
name = p.pname;
path = "${p}/bin";
}) cfg.extensions);
};
};
}

View File

@ -1,5 +1,6 @@
{
gh-config-file = ./config-file.nix;
gh-credential-helper = ./credential-helper.nix;
gh-extensions = ./extensions.nix;
gh-warnings = ./warnings.nix;
}

View File

@ -0,0 +1,27 @@
{ config, lib, pkgs, ... }:
{
programs.gh = {
enable = true;
extensions = [ pkgs.gh-eco ];
};
test.stubs = {
gh = { };
gh-eco = {
name = "gh-eco";
buildScript = ''
mkdir -p $out/bin
touch $out/bin/gh-eco
chmod +x $out/bin/gh-eco
'';
outPath = null;
};
};
nmt.script = ''
gh_eco=home-files/.local/share/gh/extensions/gh-eco/gh-eco
assertFileExists "$gh_eco"
assertFileIsExecutable "$gh_eco"
'';
}