lol
1{ lib, fetchurl, fetchFromGitHub, installShellFiles, buildGoModule, go }:
2
3buildGoModule rec {
4 pname = "fastly";
5 version = "4.3.0";
6
7 src = fetchFromGitHub {
8 owner = "fastly";
9 repo = "cli";
10 rev = "v${version}";
11 sha256 = "sha256-TxN0DQ4OKfHn+u4ixpCgcyRRTs52IZRjgcbJuqajeVo=";
12 # The git commit is part of the `fastly version` original output;
13 # leave that output the same in nixpkgs. Use the `.git` directory
14 # to retrieve the commit SHA, and remove the directory afterwards,
15 # since it is not needed after that.
16 leaveDotGit = true;
17 postFetch = ''
18 cd "$out"
19 git rev-parse --short HEAD > $out/COMMIT
20 find "$out" -name .git -print0 | xargs -0 rm -rf
21 '';
22 };
23
24 subPackages = [ "cmd/fastly" ];
25
26 vendorSha256 = "sha256-7EtyQYPe+oJmQ7uECbjkBjLnM9T03g6gFwUwebKuccc=";
27
28 nativeBuildInputs = [ installShellFiles ];
29
30 # Flags as provided by the build automation of the project:
31 # https://github.com/fastly/cli/blob/7844f9f54d56f8326962112b5534e5c40e91bf09/.goreleaser.yml#L14-L18
32 ldflags = [
33 "-s"
34 "-w"
35 "-X github.com/fastly/cli/pkg/revision.AppVersion=v${version}"
36 "-X github.com/fastly/cli/pkg/revision.Environment=release"
37 "-X github.com/fastly/cli/pkg/revision.GoHostOS=${go.GOHOSTOS}"
38 "-X github.com/fastly/cli/pkg/revision.GoHostArch=${go.GOHOSTARCH}"
39 ];
40 preBuild = let
41 cliConfigToml = fetchurl {
42 url = "https://web.archive.org/web/20221104122906/https://developer.fastly.com/api/internal/cli-config";
43 sha256 = "sha256-BHsUWrMp//X95gcB+WbD/nfyduZUkH8jHXk3CfOBAhg=";
44 };
45 in ''
46 cp ${cliConfigToml} ./pkg/config/config.toml
47 ldflags+=" -X github.com/fastly/cli/pkg/revision.GitCommit=$(cat COMMIT)"
48 '';
49
50 postInstall = ''
51 export HOME="$(mktemp -d)"
52 installShellCompletion --cmd fastly \
53 --bash <($out/bin/fastly --completion-script-bash) \
54 --zsh <($out/bin/fastly --completion-script-zsh)
55 '';
56
57 meta = with lib; {
58 description = "Command line tool for interacting with the Fastly API";
59 license = licenses.asl20;
60 homepage = "https://github.com/fastly/cli";
61 maintainers = with maintainers; [ ereslibre shyim ];
62 };
63}