about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/tools/azure-static-sites-client/default.nix
blob: 5ac8f971cf35adf823c73978f7fbd4e4f88a07fa (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
{ lib
, stdenv
, fetchurl
, autoPatchelfHook
, curl
, icu70
, libkrb5
, lttng-ust
, openssl
, zlib
, azure-static-sites-client
  # "latest", "stable" or "backup"
, versionFlavor ? "stable"
}:
let
  versions = lib.importJSON ./versions.json;
  flavor = with lib; head (filter (x: x.version == versionFlavor) versions);
  fetchBinary = runtimeId: fetchurl {
    url = flavor.files.${runtimeId}.url;
    sha256 = flavor.files.${runtimeId}.sha;
  };
  sources = {
    "x86_64-linux" = fetchBinary "linux-x64";
    "x86_64-darwin" = fetchBinary "macOS";
  };
in
stdenv.mkDerivation {
  pname = "StaticSitesClient-${versionFlavor}";
  version = flavor.buildId;

  src = sources.${stdenv.targetPlatform.system} or (throw "Unsupported platform");

  nativeBuildInputs = [
    autoPatchelfHook
  ];

  buildInputs = [
    curl
    icu70
    libkrb5
    lttng-ust
    openssl
    stdenv.cc.cc.lib
    zlib
  ];

  dontUnpack = true;
  dontBuild = true;

  installPhase = ''
    runHook preInstall

    install -m755 "$src" -D "$out/bin/StaticSitesClient"

    for icu_lib in 'icui18n' 'icuuc' 'icudata'; do
      patchelf --add-needed "lib''${icu_lib}.so.${with lib; head (splitVersion (getVersion icu70.name))}" "$out/bin/StaticSitesClient"
    done

    patchelf --add-needed 'libgssapi_krb5.so' \
             --add-needed 'liblttng-ust.so'   \
             --add-needed 'libssl.so.3'     \
             "$out/bin/StaticSitesClient"

    runHook postInstall
  '';

  # Stripping kills the binary
  dontStrip = true;

  # Just make sure the binary executes successfully
  doInstallCheck = true;
  installCheckPhase = ''
    runHook preInstallCheck

    $out/bin/StaticSitesClient version

    runHook postInstallCheck
  '';

  passthru = {
    # Create tests for all flavors
    tests = with lib; genAttrs (map (x: x.version) versions) (versionFlavor:
      azure-static-sites-client.override { inherit versionFlavor; }
    );
    updateScript = ./update.sh;
  };

  meta = with lib; {
    description = "Azure static sites client";
    homepage = "https://github.com/Azure/static-web-apps-cli";
    sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
    license = licenses.unfree;
    mainProgram = "StaticSitesClient";
    maintainers = with maintainers; [ veehaitch ];
    platforms = [ "x86_64-linux" ];
  };
}