{ lib, stdenvNoCC, fetchurl, nodejs, sysctl, writableTmpDirAsHomeHook, nix-update-script, ripgrep, }: stdenvNoCC.mkDerivation (finalAttrs: { pname = "gemini-cli-bin"; version = "0.25.0"; src = fetchurl { url = "https://github.com/google-gemini/gemini-cli/releases/download/v${finalAttrs.version}/gemini.js"; hash = "sha256-7Co3DPZs/ZtdLfhZnOcpdFFQPnyeLkvxTZG+tv+FbBQ="; }; dontUnpack = true; strictDeps = true; buildInputs = [ nodejs ripgrep ]; installPhase = '' runHook preInstall install -D "$src" "$out/bin/gemini" # ideal method to disable auto-update sed -i '/disableautoupdate: {/,/}/ s/default: false/default: true/' "$out/bin/gemini" # disable auto-update for real because the default value in settingsschema isn't cleanly applied # https://github.com/google-gemini/gemini-cli/issues/13569 substituteInPlace $out/bin/gemini \ --replace-fail "settings.merged.general?.disableUpdateNag" "(settings.merged.general?.disableUpdateNag ?? true)" \ --replace-fail "settings.merged.general?.disableAutoUpdate ?? false" "settings.merged.general?.disableAutoUpdate ?? true" \ --replace-fail "settings.merged.general?.disableAutoUpdate" "(settings.merged.general?.disableAutoUpdate ?? true)" # use `ripgrep` from `nixpkgs`, more dependencies but prevent downloading incompatible binary on NixOS # this workaround can be removed once the following upstream issue is resolved: # https://github.com/google-gemini/gemini-cli/issues/11438 substituteInPlace $out/bin/gemini \ --replace-fail 'const existingPath = await resolveExistingRgPath();' 'const existingPath = "${lib.getExe ripgrep}";' runHook postInstall ''; doInstallCheck = true; nativeInstallCheckInputs = [ writableTmpDirAsHomeHook ] ++ lib.optionals (with stdenvNoCC.hostPlatform; isDarwin && isx86_64) [ sysctl ]; # versionCheckHook cannot be used because the reported version might be incorrect (e.g., 0.6.1 returns 0.6.0). installCheckPhase = '' runHook preInstallCheck "$out/bin/gemini" -v runHook postInstallCheck ''; passthru.updateScript = nix-update-script { # Ignore `preview` and `nightly` tags extraArgs = [ "--version-regex=^v([0-9.]+)$" ]; }; meta = { description = "AI agent that brings the power of Gemini directly into your terminal"; homepage = "https://github.com/google-gemini/gemini-cli"; license = lib.licenses.asl20; maintainers = with lib.maintainers; [ ljxfstorm ]; mainProgram = "gemini"; platforms = lib.platforms.linux ++ lib.platforms.darwin; sourceProvenance = [ lib.sourceTypes.binaryBytecode ]; priority = 10; }; })