summary refs log tree commit diff
path: root/pkgs/tools/networking/slack-cli/default.nix
blob: dc8b25d868c8f0e562405e334bdd9912ae99b7d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# slack-cli must be configured using the SLACK_CLI_TOKEN environment variable.
# Using `slack init` will not work because it tries to write to the Nix store.
#
# There is no reason that we couldn't change the file path that slack-cli uses
# for token storage, except that it would make the Nix package inconsistent with
# upstream and other distributions.

{ stdenv, lib, writeShellScriptBin, fetchFromGitHub, curl, jq }:

let
  wrapper = writeShellScriptBin "slack" ''
    [ "$1" = "init" -a -z "$SLACK_CLI_TOKEN" ] && cat >&2 <<-'MESSAGE'
    WARNING: slack-cli must be configured using the SLACK_CLI_TOKEN environment
    variable. Using `slack init` will not work because it tries to write to the
    Nix store.

    MESSAGE

    export PATH=${lib.makeBinPath [ curl jq ]}:"$PATH"
    exec "$(dirname "$0")/.slack-wrapped" "$@"
  '';

in stdenv.mkDerivation rec {
    name = "slack-cli-${version}";
    version = "0.18.0";

    src = fetchFromGitHub {
      owner = "rockymadden";
      repo = "slack-cli";
      rev = "v${version}";
      sha256 = "022yr3cpfg0v7cxi62zzk08vp0l3w851qpfh6amyfgjiynnfyddl";
    };

    dontBuild = true;

    installPhase = ''
      mkdir -p "$out/bin"
      cp src/slack "$out/bin/.slack-wrapped"
      ln -s ${wrapper}/bin/slack "$out/bin/slack"
    '';

    meta = {
      license = lib.licenses.mit;
      maintainers = [ lib.maintainers.qyliss ];
      platforms = lib.platforms.unix;
    };
  }