btrbk: add mainProgram (#356350)
[NixPkgs.git] / pkgs / by-name / en / ente-cli / package.nix
blobb35152a3daaa5acb08a4d1c33bfeb413871ac22a
2   lib,
3   buildGoModule,
4   ente-cli,
5   fetchFromGitHub,
6   installShellFiles,
7   nix-update-script,
8   stdenv,
9   testers,
11 let
12   version = "0.2.2";
14   canExecute = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
16 buildGoModule {
17   pname = "ente-cli";
18   inherit version;
20   src = fetchFromGitHub {
21     owner = "ente-io";
22     repo = "ente";
23     rev = "refs/tags/cli-v${version}";
24     hash = "sha256-ynbljYl73XwCnt3RUNmOYdrN8FX3sJ+3qDhWa8m2YJs=";
25     sparseCheckout = [ "cli" ];
26   };
28   modRoot = "./cli";
30   vendorHash = "sha256-Gg1mifMVt6Ma8yQ/t0R5nf6NXbzLZBpuZrYsW48p0mw=";
32   CGO_ENABLED = 0;
34   ldflags = [
35     "-s"
36     "-w"
37     "-X main.AppVersion=cli-v${version}"
38   ];
40   nativeBuildInputs = [ installShellFiles ];
42   postInstall =
43     ''
44       mv $out/bin/{cli,ente}
45     ''
46     # running ente results in the following errors:
47     # > mkdir /homeless-shelter: permission denied
48     # > error getting password from keyring: exec: "dbus-launch": executable file not found in $PATH
49     # fix by setting ENTE_CLI_CONFIG_PATH to $TMP and ENTE_CLI_SECRETS_PATH to a non existing path
50     # also guarding with `isLinux` because ENTE_CLI_SECRETS_PATH doesn't help on darwin:
51     # > error setting password in keyring: exit status 195
52     #
53     + lib.optionalString (stdenv.buildPlatform.isLinux && canExecute) ''
54       export ENTE_CLI_CONFIG_PATH=$TMP
55       export ENTE_CLI_SECRETS_PATH=$TMP/secrets
57       installShellCompletion --cmd ente \
58         --bash <($out/bin/ente completion bash) \
59         --fish <($out/bin/ente completion fish) \
60         --zsh <($out/bin/ente completion zsh)
61     '';
63   passthru = {
64     # only works on linux, see comment above about ENTE_CLI_SECRETS_PATH on darwin
65     tests.version = lib.optionalAttrs stdenv.isLinux (
66       testers.testVersion {
67         package = ente-cli;
68         command = ''
69           env ENTE_CLI_CONFIG_PATH=$TMP \
70               ENTE_CLI_SECRETS_PATH=$TMP/secrets \
71               ente version
72         '';
73         version = "Version cli-v${ente-cli.version}";
74       }
75     );
76     updateScript = nix-update-script {
77       extraArgs = [
78         "--version-regex"
79         "cli-(.+)"
80       ];
81     };
82   };
84   meta = {
85     description = "CLI client for downloading your data from Ente";
86     longDescription = ''
87       The Ente CLI is a Command Line Utility for exporting data from Ente. It also does a few more things, for example, you can use it to decrypting the export from Ente Auth.
88     '';
89     homepage = "https://github.com/ente-io/ente/tree/main/cli#readme";
90     changelog = "https://github.com/ente-io/ente/releases/tag/cli-v${version}";
91     license = lib.licenses.agpl3Only;
92     maintainers = [
93       lib.maintainers.zi3m5f
94     ];
95     mainProgram = "ente";
96   };