Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / misc / fastly / default.nix
blobca191319243f19fcf6ae0169879d9244bb9e145e
1 { lib
2 , fetchurl
3 , fetchFromGitHub
4 , installShellFiles
5 , buildGoModule
6 , go
7 , makeWrapper
8 , viceroy
9 }:
11 buildGoModule rec {
12   pname = "fastly";
13   version = "10.6.4";
15   src = fetchFromGitHub {
16     owner = "fastly";
17     repo = "cli";
18     rev = "refs/tags/v${version}";
19     hash = "sha256-+qBeE7t+d1Es63hUBO9Bcqyc0vtatcJGoYw2GE0JPxQ=";
20     # The git commit is part of the `fastly version` original output;
21     # leave that output the same in nixpkgs. Use the `.git` directory
22     # to retrieve the commit SHA, and remove the directory afterwards,
23     # since it is not needed after that.
24     leaveDotGit = true;
25     postFetch = ''
26       cd "$out"
27       git rev-parse --short HEAD > $out/COMMIT
28       find "$out" -name .git -print0 | xargs -0 rm -rf
29     '';
30   };
32   subPackages = [
33     "cmd/fastly"
34   ];
36   vendorHash = "sha256-Mh737emdQkIoNOAkaTafCoMQnLqXIGMKX6X5ClsmMzc=";
38   nativeBuildInputs = [
39     installShellFiles
40     makeWrapper
41   ];
43   # Flags as provided by the build automation of the project:
44   #   https://github.com/fastly/cli/blob/7844f9f54d56f8326962112b5534e5c40e91bf09/.goreleaser.yml#L14-L18
45   ldflags = [
46     "-s"
47     "-w"
48     "-X github.com/fastly/cli/pkg/revision.AppVersion=v${version}"
49     "-X github.com/fastly/cli/pkg/revision.Environment=release"
50     "-X github.com/fastly/cli/pkg/revision.GoHostOS=${go.GOHOSTOS}"
51     "-X github.com/fastly/cli/pkg/revision.GoHostArch=${go.GOHOSTARCH}"
52   ];
53   preBuild = let
54     cliConfigToml = fetchurl {
55       url = "https://web.archive.org/web/20231104101556/https://developer.fastly.com/api/internal/cli-config";
56       hash = "sha256-Bi5hbmMyFP4Pv2MklwNdkhGLXbI5qf6Ibvj0vWok2tI=";
57     };
58   in ''
59     cp ${cliConfigToml} ./pkg/config/config.toml
60     ldflags+=" -X github.com/fastly/cli/pkg/revision.GitCommit=$(cat COMMIT)"
61   '';
63   preFixup = ''
64     wrapProgram $out/bin/fastly --prefix PATH : ${lib.makeBinPath [ viceroy ]} \
65       --set FASTLY_VICEROY_USE_PATH 1
66   '';
68   postInstall = ''
69     export HOME="$(mktemp -d)"
70     installShellCompletion --cmd fastly \
71       --bash <($out/bin/fastly --completion-script-bash) \
72       --zsh <($out/bin/fastly --completion-script-zsh)
73   '';
75   meta = with lib; {
76     description = "Command line tool for interacting with the Fastly API";
77     homepage = "https://github.com/fastly/cli";
78     changelog = "https://github.com/fastly/cli/blob/v${version}/CHANGELOG.md";
79     license = licenses.asl20;
80     maintainers = with maintainers; [ ereslibre shyim ];
81   };