summary refs log tree commit diff
path: root/pkgs/development/tools/wp-cli/default.nix
blob: c52f2553e3d6524ac82c4f4c9c5204a373e87ed8 (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
48
49
50
51
{ stdenv, lib, fetchurl, php }:

let
  version = "1.1.0";

  bin  = "bin/wp";
  ini  = "etc/php/wp-cli.ini";
  phar = "share/wp-cli/wp-cli.phar";

  completion = fetchurl {
    url    = "https://raw.githubusercontent.com/wp-cli/wp-cli/v${version}/utils/wp-completion.bash";
    sha256 = "15d330x6d3fizrm6ckzmdknqg6wjlx5fr87bmkbd5s6a1ihs0g24";
  };

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

  src = fetchurl {
    url    = "https://github.com/wp-cli/wp-cli/releases/download/v${version}/${name}.phar";
    sha256 = "08b2lzc8fa9f5xldbdza6x3lg6jsp3wfwpyy187gxqw5pmqp11xc";
  };

  buildCommand = ''
    mkdir -p $out/bin $out/etc/php

    cat <<_EOF > $out/${bin}
    #! ${stdenv.shell} -eu
    exec ${lib.getBin php}/bin/php \\
      -c $out/${ini} \\
      -f $out/${phar} "\$@"
    _EOF
    chmod 755 $out/${bin}

    cat <<_EOF > $out/${ini}
    [Phar]
    phar.readonly = Off
    _EOF
    chmod 644 $out/${ini}

    install -Dm644 ${src}        $out/${phar}
    install -Dm644 ${completion} $out/share/bash-completion/completions/wp
  '';

  meta = with stdenv.lib; {
    description = "A command line interface for WordPress";
    maintainers = with maintainers; [ peterhoeg ];
    platforms = platforms.all;
    homepage = https://wp-cli.org;
    license = licenses.mit;
  };
}