1{ stdenv, lib, fetchurl, writeScript, writeText, php, runtimeShell }:
2
3let
4 version = "2.0.1";
5
6 completion = fetchurl {
7 url = "https://raw.githubusercontent.com/wp-cli/wp-cli/v${version}/utils/wp-completion.bash";
8 sha256 = "15d330x6d3fizrm6ckzmdknqg6wjlx5fr87bmkbd5s6a1ihs0g24";
9 };
10
11in stdenv.mkDerivation rec {
12 name = "wp-cli-${version}";
13 inherit version;
14
15 src = fetchurl {
16 url = "https://github.com/wp-cli/wp-cli/releases/download/v${version}/${name}.phar";
17 sha256 = "05lbay4c0477465vv4h8d2j94pk3haz1a7f0ncb127fvxz3a2pcg";
18 };
19
20 buildCommand = ''
21 dir=$out/share/wp-cli
22 mkdir -p $out/bin $dir
23
24 cat <<_EOF > $out/bin/wp
25#!${runtimeShell}
26
27set -euo pipefail
28
29exec ${lib.getBin php}/bin/php \\
30 -c $dir/php.ini \\
31 -f $dir/wp-cli -- "\$@"
32_EOF
33 chmod 0755 $out/bin/wp
34
35 cat <<_EOF > $dir/php.ini
36[PHP]
37memory_limit = -1 ; no limit as composer uses a lot of memory
38
39[Phar]
40phar.readonly = Off
41_EOF
42
43 install -Dm644 ${src} $dir/wp-cli
44 install -Dm644 ${completion} $out/share/bash-completion/completions/wp
45
46 # this is a very basic run test
47 $out/bin/wp --info
48 '';
49
50 meta = with stdenv.lib; {
51 description = "A command line interface for WordPress";
52 homepage = https://wp-cli.org;
53 license = licenses.mit;
54 maintainers = with maintainers; [ peterhoeg ];
55 platforms = platforms.all;
56 };
57}