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 = "1hhbwyhw6nmzb2a88papfca5rjavav6srcnvmbni5l6ln79pgqj7";
15 # specVersion taken from: https://www.linode.com/docs/api/openapi.yaml at `info.version`.
16 specVersion = "4.107.0";
17 specSha256 = "1z260w0517k3sgd2ygzwzkhq5w9rbkls69mnl84501fpd2nx7qvi";
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.11.1";
28
29 src = fetchFromGitHub {
30 owner = "linode";
31 repo = pname;
32 rev = version;
33 inherit sha256;
34 };
35
36 # remove need for git history
37 prePatch = ''
38 substituteInPlace setup.py \
39 --replace "version=get_version()," "version='${version}',"
40 '';
41
42 propagatedBuildInputs = [
43 colorclass
44 pyyaml
45 requests
46 setuptools
47 terminaltables
48 ];
49
50 postConfigure = ''
51 python3 -m linodecli bake ${spec} --skip-config
52 cp data-3 linodecli/
53 '';
54
55 doInstallCheck = true;
56 installCheckPhase = ''
57 $out/bin/linode-cli --skip-config --version | grep ${version} > /dev/null
58 '';
59
60 nativeBuildInputs = [ installShellFiles ];
61 postInstall = ''
62 installShellCompletion --cmd linode-cli --bash <($out/bin/linode-cli --skip-config completion bash)
63 '';
64
65 passthru.updateScript = ./update.sh;
66
67 meta = with lib; {
68 description = "The Linode Command Line Interface";
69 homepage = "https://github.com/linode/linode-cli";
70 license = licenses.bsd3;
71 maintainers = with maintainers; [ ryantm ];
72 };
73}