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