From 2c51a5b33c6aa87308e36ba1a0f499c6c1edf7db Mon Sep 17 00:00:00 2001 From: Ivan Trubach Date: Thu, 22 Jun 2023 17:44:15 +0300 Subject: [PATCH] yandex-cloud: init at 0.129.0 --- pkgs/by-name/ya/yandex-cloud/package.nix | 99 ++++++++++++++++++++ pkgs/by-name/ya/yandex-cloud/sources.json | 25 +++++ pkgs/by-name/ya/yandex-cloud/update.py | 107 ++++++++++++++++++++++ 3 files changed, 231 insertions(+) create mode 100644 pkgs/by-name/ya/yandex-cloud/package.nix create mode 100644 pkgs/by-name/ya/yandex-cloud/sources.json create mode 100644 pkgs/by-name/ya/yandex-cloud/update.py diff --git a/pkgs/by-name/ya/yandex-cloud/package.nix b/pkgs/by-name/ya/yandex-cloud/package.nix new file mode 100644 index 000000000000..d93adcae1ab5 --- /dev/null +++ b/pkgs/by-name/ya/yandex-cloud/package.nix @@ -0,0 +1,99 @@ +{ + lib, + stdenv, + fetchurl, + makeBinaryWrapper, + installShellFiles, + buildPackages, + withShellCompletions ? stdenv.hostPlatform.emulatorAvailable buildPackages, + # update script + writers, + python3Packages, + nix, + # tests + testers, + yandex-cloud, +}: +let + pname = "yandex-cloud"; + sources = lib.importJSON ./sources.json; + inherit (sources) version binaries; +in +stdenv.mkDerivation { + inherit pname version; + + src = fetchurl binaries.${stdenv.hostPlatform.system}; + + dontUnpack = true; + + strictDeps = true; + + nativeBuildInputs = [ + installShellFiles + makeBinaryWrapper + ]; + + emulator = lib.optionalString ( + withShellCompletions && !stdenv.buildPlatform.canExecute stdenv.hostPlatform + ) (stdenv.hostPlatform.emulator buildPackages); + + installPhase = + '' + runHook preInstall + mkdir -p -- "$out/bin" + cp -- "$src" "$out/bin/yc" + chmod +x -- "$out/bin/yc" + '' + + lib.optionalString withShellCompletions '' + for shell in bash zsh; do + ''${emulator:+"$emulator"} "$out/bin/yc" completion $shell >yc.$shell + installShellCompletion yc.$shell + done + '' + + '' + makeWrapper "$out/bin/yc" "$out/bin/docker-credential-yc" \ + --add-flags --no-user-output \ + --add-flags container \ + --add-flags docker-credential + runHook postInstall + ''; + + passthru = { + updateScript = writers.writePython3 "${pname}-updater" { + libraries = with python3Packages; [ requests ]; + makeWrapperArgs = [ + "--prefix" + "PATH" + ":" + (lib.makeBinPath [ nix ]) + ]; + } ./update.py; + tests.version = testers.testVersion { package = yandex-cloud; }; + }; + + meta = { + description = "Command line interface that helps you interact with Yandex Cloud services"; + homepage = "https://cloud.yandex/docs/cli"; + changelog = "https://cloud.yandex/docs/cli/release-notes#version${version}"; + sourceProvenance = [ lib.sourceTypes.binaryNativeCode ]; + license = lib.licenses.unfree; + maintainers = [ lib.maintainers.tie ]; + platforms = [ + "aarch64-darwin" + "x86_64-darwin" + "aarch64-linux" + "x86_64-linux" + # Built with GO386=sse2. + # + # Unfortunately, we don’t have anything about SSE2 support in lib.systems, + # so we can’t mark this a broken or bad platform if host platform does not + # support SSE2. See also https://github.com/NixOS/nixpkgs/issues/132217 + # + # Perhaps it would be possible to mark it as broken if platform declares + # GO386=softfloat once https://github.com/NixOS/nixpkgs/pull/256761 is + # ready and merged. + "i686-linux" + ]; + mainProgram = "yc"; + }; +} diff --git a/pkgs/by-name/ya/yandex-cloud/sources.json b/pkgs/by-name/ya/yandex-cloud/sources.json new file mode 100644 index 000000000000..0164377af732 --- /dev/null +++ b/pkgs/by-name/ya/yandex-cloud/sources.json @@ -0,0 +1,25 @@ +{ + "version": "0.129.0", + "binaries": { + "aarch64-darwin": { + "url": "https://storage.yandexcloud.net/yandexcloud-yc/release/0.129.0/darwin/arm64/yc", + "hash": "sha256-ULd/fmWDBPPALf6Rb95n6zXsSuDBAkeWNH11f5PLIpE=" + }, + "aarch64-linux": { + "url": "https://storage.yandexcloud.net/yandexcloud-yc/release/0.129.0/linux/arm64/yc", + "hash": "sha256-Tvy9hTpp37EUrEIDglNFqrH0laD0O+wwVWlCIBh6Jag=" + }, + "i686-linux": { + "url": "https://storage.yandexcloud.net/yandexcloud-yc/release/0.129.0/linux/386/yc", + "hash": "sha256-rmcXdz7z1iXOUQTq0sFNNcZ1jG/Dypxfl2oyeJiwkjs=" + }, + "x86_64-darwin": { + "url": "https://storage.yandexcloud.net/yandexcloud-yc/release/0.129.0/darwin/amd64/yc", + "hash": "sha256-DjAifjGBiRvJDx3j4iMR/t7zOITaz/iulfeDUZCvIhE=" + }, + "x86_64-linux": { + "url": "https://storage.yandexcloud.net/yandexcloud-yc/release/0.129.0/linux/amd64/yc", + "hash": "sha256-igj1iwznsL1OG3V8hOQVCbticzOtDH8dF8jLzMxO5Fg=" + } + } +} diff --git a/pkgs/by-name/ya/yandex-cloud/update.py b/pkgs/by-name/ya/yandex-cloud/update.py new file mode 100644 index 000000000000..d1b95ca50ec6 --- /dev/null +++ b/pkgs/by-name/ya/yandex-cloud/update.py @@ -0,0 +1,107 @@ +import json +import os +import requests +import shutil +import subprocess +import sys +import tempfile + +# See YC_SDK_STORAGE_URL in +# https://storage.yandexcloud.net/yandexcloud-yc/install.sh +storage_url = "https://storage.yandexcloud.net/yandexcloud-yc" + +systems = [ + ("aarch64", "darwin"), + ("aarch64", "linux"), + ("i686", "linux"), + ("x86_64", "darwin"), + ("x86_64", "linux"), +] + + +def to_goarch(cpu): + return { + "aarch64": "arm64", + "i686": "386", + "x86_64": "amd64", + }.get(cpu, cpu) + + +nixpkgs_path = "." +attr_path = os.getenv("UPDATE_NIX_ATTR_PATH", "yandex-cloud") + +package_attrs = json.loads(subprocess.run( + [ + "nix", + "--extra-experimental-features", "nix-command", + "eval", + "--json", + "--file", nixpkgs_path, + "--apply", """p: { + dir = builtins.dirOf p.meta.position; + version = p.version; + }""", + "--", + attr_path, + ], + stdout=subprocess.PIPE, + text=True, + check=True, +).stdout) + +old_version = package_attrs["version"] +new_version = requests.get(f"{storage_url}/release/stable").text.rstrip() + +if new_version == old_version: + sys.exit() + +binaries = {} +for cpu, kernel in systems: + goos = kernel + goarch = to_goarch(cpu) + system = f"{cpu}-{kernel}" + + url = f"{storage_url}/release/{new_version}/{goos}/{goarch}/yc" + + nix_hash = subprocess.run( + [ + "nix-prefetch-url", + "--type", "sha256", + url, + ], + stdout=subprocess.PIPE, + text=True, + check=True, + ).stdout.rstrip() + + sri_hash = subprocess.run( + [ + "nix", + "--extra-experimental-features", "nix-command", + "hash", + "to-sri", + "--type", "sha256", + "--", + nix_hash, + ], + stdout=subprocess.PIPE, + text=True, + check=True, + ).stdout.rstrip() + + binaries[system] = { + "url": url, + "hash": sri_hash, + } + +package_dir = package_attrs["dir"] +file_path = os.path.join(package_dir, "sources.json") +file_content = json.dumps({ + "version": new_version, + "binaries": binaries, +}, indent=2) + "\n" + +with tempfile.NamedTemporaryFile(mode="w") as t: + t.write(file_content) + t.flush() + shutil.copyfile(t.name, file_path)