gh: opt out of telemetry collection by default

Starting with release 2.91.0 gh sends pseudonymized telemetry data to
GitHub. Disabling it requires and explicit opt-out.

Context: https://github.blog/changelog/2026-04-22-github-cli-opt-out-usage-telemetry/

This changes makes telemetry collection opt in. If users really want to
share data with GitHub, they can `overrideAttrs` and explicitly set the
new `enableTelemetry` parameter to `true`.
This commit is contained in:
Benedikt Ritter
2026-04-30 14:31:33 +02:00
parent 7d12338ee7
commit ec7f8fa480

View File

@@ -5,7 +5,8 @@
installShellFiles,
stdenv,
testers,
gh,
makeWrapper,
enableTelemetry ? false,
}:
buildGoModule (finalAttrs: {
@@ -21,7 +22,10 @@ buildGoModule (finalAttrs: {
vendorHash = "sha256-4xZAcwn9/vUTkahIlqwyGb/2SYYGusdXY4nye8ldp/g=";
nativeBuildInputs = [ installShellFiles ];
nativeBuildInputs = [
installShellFiles
makeWrapper
];
# N.B.: using the Makefile is intentional.
# We pass "nixpkgs" for build.Date to avoid `gh --version` reporting a very old date.
@@ -35,6 +39,10 @@ buildGoModule (finalAttrs: {
runHook preInstall
install -Dm755 bin/gh -t $out/bin
''
+ lib.optionalString (!enableTelemetry) ''
wrapProgram $out/bin/gh \
--set GH_TELEMETRY false
''
+ lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
installManPage share/man/*/*.[1-9]
@@ -51,7 +59,7 @@ buildGoModule (finalAttrs: {
doCheck = false;
passthru.tests.version = testers.testVersion {
package = gh;
package = finalAttrs.finalPackage;
};
meta = {