nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 138 lines 4.4 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchzip, 5 coreutils, 6 installShellFiles, 7 makeWrapper, 8 gitMinimal, 9 writeShellScript, 10 curl, 11 jq, 12 common-updater-scripts, 13}: 14 15stdenv.mkDerivation (finalAttrs: { 16 pname = "gk-cli"; 17 version = "3.0.9"; 18 19 src = ( 20 finalAttrs.passthru.sources.${stdenv.system} 21 or (throw "gk-cli ${finalAttrs.version} unsupported system: ${stdenv.system}") 22 ); 23 24 nativeBuildInputs = [ 25 installShellFiles 26 makeWrapper 27 ]; 28 29 installPhase = '' 30 runHook preInstall 31 32 install -Dm555 gk*/gk -t $out/bin/ 33 34 wrapProgram $out/bin/gk \ 35 --prefix PATH : "${lib.makeBinPath [ gitMinimal ]}" 36 37 runHook postInstall 38 ''; 39 40 postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' 41 # Use timeout because gk hangs instead of closing in the sandbox 42 installShellCompletion --cmd gk \ 43 --bash <(HOME="$(mktemp --directory)" timeout 3 $out/bin/gk completion bash) \ 44 --fish <(HOME="$(mktemp --directory)" timeout 3 $out/bin/gk completion fish) \ 45 --zsh <(HOME="$(mktemp --directory)" timeout 3 $out/bin/gk completion zsh) 46 ''; 47 48 doInstallCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform; 49 installCheckPhase = '' 50 OUTPUT="$( 51 HOME="$(mktemp --directory)" \ 52 timeout 3 `# Use timeout because gk hangs instead of closing in the sandbox` \ 53 $out/bin/gk setup \ 54 2>/dev/null \ 55 || true # Command fails because not logged in 56 )" 57 58 echo "$OUTPUT" | grep --quiet '^Git binary found: $' 59 echo "$OUTPUT" | grep --quiet '^CLI version: ${finalAttrs.version}$' 60 ''; 61 62 passthru = { 63 sources = 64 let 65 base_url = "https://github.com/gitkraken/gk-cli/releases/download/v${finalAttrs.version}/gk_${finalAttrs.version}_"; 66 in 67 { 68 aarch64-linux = fetchzip { 69 url = "${base_url}linux_arm64.zip"; 70 hash = "sha256-aYgHLpG4nX3Op0+j733jYbK4ZwVKkctMkDPweNTJWso="; 71 stripRoot = false; 72 }; 73 x86_32-linux = fetchzip { 74 url = "${base_url}linux_386.zip"; 75 hash = "sha256-lVu25S7e6a/kHmiD5dxGAlHMQ5yN46+SdFpt8lghejM="; 76 stripRoot = false; 77 }; 78 x86_64-linux = fetchzip { 79 url = "${base_url}linux_amd64.zip"; 80 hash = "sha256-/z2G//Zh8lTHkeJPahyld1EEXXhd/cgIvCojUmzFX8E="; 81 stripRoot = false; 82 }; 83 aarch64-darwin = fetchzip { 84 url = "${base_url}darwin_arm64.zip"; 85 hash = "sha256-nDVehD0TTNTvhuDU8RB4lZiVcEJpB+l6EGkzckC7JuU="; 86 stripRoot = false; 87 }; 88 x86_64-darwin = fetchzip { 89 url = "${base_url}darwin_amd64.zip"; 90 hash = "sha256-Lhuqb5592T6VcTMVmAdIDfGMXaS4dSu0wbQeHheXXk4="; 91 stripRoot = false; 92 }; 93 aarch64-windows = fetchzip { 94 url = "${base_url}windows_arm64.zip"; 95 hash = "sha256-sXHeqR4AW/sRPp74PieXI1n4VGV94CnrcMF1ovAek8E="; 96 stripRoot = false; 97 }; 98 i686-windows = fetchzip { 99 url = "${base_url}windows_386.zip"; 100 hash = "sha256-u6DyHoYIaExS2CHu20odDVJxzI4k9PpdFQf6UDPAzz0="; 101 stripRoot = false; 102 }; 103 x86_64-windows = fetchzip { 104 url = "${base_url}windows_amd64.zip"; 105 hash = "sha256-nh+JPR95IWLm7CTrS8qK2dP3c4SH/zm1oIS5GNgxcyo="; 106 stripRoot = false; 107 }; 108 }; 109 updateScript = writeShellScript "update-gk-cli" '' 110 set -o errexit 111 export PATH="${ 112 lib.makeBinPath [ 113 curl 114 jq 115 common-updater-scripts 116 ] 117 }" 118 NEW_VERSION=$(curl --silent https://api.github.com/repos/gitkraken/gk-cli/releases/latest | jq '.tag_name | ltrimstr("v")' --raw-output) 119 if [[ "${finalAttrs.version}" = "$NEW_VERSION" ]]; then 120 echo "The new version same as the old version." 121 exit 0 122 fi 123 for platform in ${lib.escapeShellArgs finalAttrs.meta.platforms}; do 124 update-source-version "gk-cli" "$NEW_VERSION" --ignore-same-version --source-key="passthru.sources.$platform" 125 done 126 ''; 127 }; 128 129 meta = { 130 description = "CLI for Git collaboration across multiple repos and services"; 131 homepage = "https://www.gitkraken.com"; 132 license = lib.licenses.unfree; 133 sourceProvenance = [ lib.sourceTypes.binaryNativeCode ]; 134 maintainers = [ lib.maintainers.pinage404 ]; 135 mainProgram = "gk"; 136 platforms = builtins.attrNames finalAttrs.passthru.sources; 137 }; 138})