1{ lib
2, fetchFromGitHub
3, fetchurl
4, buildPythonApplication
5, colorclass
6, installShellFiles
7, pyyaml
8, requests
9, setuptools
10, terminaltables
11}:
12
13let
14 sha256 = "0lngwmb9j3nzwhkhq4r9sy82gwjry14lvjjgm8vfivbbakjdl7xp";
15 # specVersion taken from: https://www.linode.com/docs/api/openapi.yaml at `info.version`.
16 specVersion = "4.139.0";
17 specSha256 = "1z050vm049gb8vynp34iz9jpxwbpmbf5vbs1jsirwqbfhr1skslz";
18 spec = fetchurl {
19 url = "https://raw.githubusercontent.com/linode/linode-api-docs/v${specVersion}/openapi.yaml";
20 sha256 = specSha256;
21 };
22
23in
24
25buildPythonApplication rec {
26 pname = "linode-cli";
27 version = "5.25.0";
28
29 src = fetchFromGitHub {
30 owner = "linode";
31 repo = pname;
32 rev = version;
33 inherit sha256;
34 };
35
36 patches = [
37 ./remove-update-check.patch
38 ];
39
40 # remove need for git history
41 prePatch = ''
42 substituteInPlace setup.py \
43 --replace "version=get_version()," "version='${version}',"
44 '';
45
46 propagatedBuildInputs = [
47 colorclass
48 pyyaml
49 requests
50 setuptools
51 terminaltables
52 ];
53
54 postConfigure = ''
55 python3 -m linodecli bake ${spec} --skip-config
56 cp data-3 linodecli/
57 '';
58
59 doInstallCheck = true;
60 installCheckPhase = ''
61 $out/bin/linode-cli --skip-config --version | grep ${version} > /dev/null
62 '';
63
64 nativeBuildInputs = [ installShellFiles ];
65 postInstall = ''
66 installShellCompletion --cmd linode-cli --bash <($out/bin/linode-cli --skip-config completion bash)
67 '';
68
69 passthru.updateScript = ./update.sh;
70
71 meta = with lib; {
72 description = "The Linode Command Line Interface";
73 homepage = "https://github.com/linode/linode-cli";
74 license = licenses.bsd3;
75 maintainers = with maintainers; [ ryantm ];
76 };
77}