Skip to content

Commit

Permalink
Install gh
Browse files Browse the repository at this point in the history
Using patch to make access to Keychain more secure, see
cli/cli#7743
  • Loading branch information
YorikSar committed Jul 24, 2023
1 parent 89a2ddd commit 4b5ac20
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
12 changes: 12 additions & 0 deletions nix/gh.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{pkgs, ...}: {
programs.gh = {
enable = true;
package = pkgs.callPackage ./pkgs/gh.nix {};
settings = {
aliases.co = "pr checkout";
};
};
xdg.configFile."gh/hosts.yml".source = (pkgs.formats.yaml {}).generate "gh-hosts.yml" {
"github.com".user = "YorikSar";
};
}
70 changes: 70 additions & 0 deletions nix/pkgs/gh.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
lib,
fetchFromGitHub,
fetchpatch,
buildGoModule,
installShellFiles,
stdenv,
testers,
gh,
}:
buildGoModule rec {
pname = "gh";
version = "2.32.0";

src = fetchFromGitHub {
owner = "cli";
repo = "cli";
rev = "v${version}";
hash = "sha256-YnIwrx/NEOH3yXkkCq30i9Jt2IXKX5IX8BuM6+u9tvs=";
};

patches = [
(fetchpatch {
url = "https://github.com/yoriksar/cli/commit/43dfa0fdd4f8ecd72d36eb755b05e9b416efaee5.patch";
sha256 = "sha256-ozGP50Z/B6FcUYNYZV8/znRCmDElNOicB+WPPXFmmm4=";
})
];

vendorHash = "sha256-G6fdROuwpFncO5FL7DRwRQAiHRgtc3IFsvx0HfmWqxU=";

nativeBuildInputs = [installShellFiles];

buildPhase = ''
runHook preBuild
make GO_LDFLAGS="-s -w" GH_VERSION=${version} bin/gh ${lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) "manpages"}
runHook postBuild
'';

installPhase =
''
runHook preInstall
install -Dm755 bin/gh -t $out/bin
''
+ lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
installManPage share/man/*/*.[1-9]
installShellCompletion --cmd gh \
--bash <($out/bin/gh completion -s bash) \
--fish <($out/bin/gh completion -s fish) \
--zsh <($out/bin/gh completion -s zsh)
''
+ ''
runHook postInstall
'';

# most tests require network access
doCheck = false;

passthru.tests.version = testers.testVersion {
package = gh;
};

meta = with lib; {
description = "GitHub CLI tool";
homepage = "https://cli.github.com/";
changelog = "https://github.com/cli/cli/releases/tag/v${version}";
license = licenses.mit;
maintainers = with maintainers; [zowoq];
};
}
1 change: 1 addition & 0 deletions nix/profiles/base.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{pkgs, ...}: {
imports = [
../git.nix
../gh.nix
../htop.nix
../neovim.nix
../tmux.nix
Expand Down

0 comments on commit 4b5ac20

Please sign in to comment.