about summary refs log tree commit diff
path: root/pkgs/by-name/ya/yandex-cloud/package.nix
blob: e45cf8ab738aadd50a99d7755d7bb5859ff440c2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{
  lib,
  stdenv,
  fetchurl,
  makeBinaryWrapper,
  installShellFiles,
  buildPackages,
  withShellCompletions ? stdenv.hostPlatform.emulatorAvailable buildPackages,
  # update script
  writers,
  python3Packages,
  nix,
  # tests
  testers,
}:
let
  pname = "yandex-cloud";
  sources = lib.importJSON ./sources.json;
  inherit (sources) version binaries;
in
stdenv.mkDerivation (finalAttrs: {
  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 = finalAttrs.finalPackage; };
  };

  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";
  };
})