···
1
+
{ config, lib, pkgs, serverInfo, php, ... }:
6
+
# https://wordpress.org/plugins/postgresql-for-wordpress/
7
+
# Wordpress plugin 'postgresql-for-wordpress' installation example
8
+
postgresqlForWordpressPlugin = pkgs.stdenv.mkDerivation {
9
+
name = "postgresql-for-wordpress-plugin";
10
+
# Download the theme from the wordpress site
11
+
src = pkgs.fetchurl {
12
+
url = https://downloads.wordpress.org/plugin/postgresql-for-wordpress.1.3.1.zip;
13
+
sha256 = "f11a5d76af884c7bec2bc653ed5bd29d3ede9a8657bd67ab7824e329e5d809e8";
15
+
# We need unzip to build this package
16
+
buildInputs = [ pkgs.unzip ];
17
+
# Installing simply means copying all files to the output directory
18
+
installPhase = "mkdir -p $out; cp -R * $out/";
21
+
# Our bare-bones wp-config.php file using the above settings
22
+
wordpressConfig = pkgs.writeText "wp-config.php" ''
24
+
define('DB_NAME', '${config.dbName}');
25
+
define('DB_USER', '${config.dbUser}');
26
+
define('DB_PASSWORD', '${config.dbPassword}');
27
+
define('DB_HOST', '${config.dbHost}');
28
+
define('DB_CHARSET', 'utf8');
29
+
$table_prefix = '${config.tablePrefix}';
30
+
if ( !defined('ABSPATH') )
31
+
define('ABSPATH', dirname(__FILE__) . '/');
32
+
require_once(ABSPATH . 'wp-settings.php');
33
+
${config.extraConfig}
36
+
# .htaccess to support pretty URLs
37
+
htaccess = pkgs.writeText "htaccess" ''
38
+
<IfModule mod_rewrite.c>
41
+
RewriteCond %{REQUEST_FILENAME} !-f
42
+
RewriteCond %{REQUEST_FILENAME} !-d
43
+
RewriteRule . /index.php [L]
47
+
# The wordpress package itself
48
+
wordpressRoot = pkgs.stdenv.mkDerivation rec {
50
+
# Fetch directly from the wordpress site, want to upgrade?
51
+
# Just change the version URL and update the hash
52
+
src = pkgs.fetchurl {
53
+
url = http://wordpress.org/wordpress-4.1.1.tar.gz;
54
+
sha256 = "1s9y0i9ms3m6dswb9gqrr95plnx6imahc07fyhvrp5g35f6c12k1";
58
+
# Copy all the wordpress files we downloaded
60
+
# We'll symlink the wordpress config
61
+
ln -s ${wordpressConfig} $out/wp-config.php
62
+
# As well as our custom .htaccess
63
+
ln -s ${htaccess} $out/.htaccess
64
+
# And the uploads directory
65
+
ln -s ${config.wordpressUploads} $out/wp-content/uploads
67
+
${concatMapStrings (theme: "ln -s ${theme} $out/wp-content/themes/${theme.name}\n") config.themes}
69
+
# remove bundled plugin(s) coming with wordpress
70
+
rm -Rf $out/wp-content/plugins/akismet
72
+
${concatMapStrings (plugin: "ln -s ${plugin} $out/wp-content/plugins/${plugin.name}\n") (config.plugins ++ [ postgresqlForWordpressPlugin]) }
80
+
# And some httpd extraConfig to make things work nicely
82
+
<Directory ${wordpressRoot}>
83
+
DirectoryIndex index.php
85
+
Options FollowSymLinks
94
+
default = "localhost";
95
+
description = "The location of the database server.";
96
+
example = "localhost";
99
+
default = "wordpress";
100
+
description = "Name of the database that holds the Wordpress data.";
101
+
example = "localhost";
103
+
dbUser = mkOption {
104
+
default = "wordpress";
105
+
description = "The dbUser, read the username, for the database.";
106
+
example = "wordpress";
108
+
dbPassword = mkOption {
109
+
default = "wordpress";
110
+
description = "The password to the respective dbUser.";
111
+
example = "wordpress";
113
+
tablePrefix = mkOption {
116
+
The $table_prefix is the value placed in the front of your database tables. Change the value if you want to use something other than wp_ for your database prefix. Typically this is changed if you are installing multiple WordPress blogs in the same database. See <link xlink:href='http://codex.wordpress.org/Editing_wp-config.php#table_prefix'/>.
119
+
wordpressUploads = mkOption {
120
+
default = "/data/uploads";
122
+
This directory is used for uploads of pictures and must be accessible (read: owned) by the httpd running user. The directory passed here is automatically created and permissions are given to the httpd running user.
125
+
plugins = mkOption {
127
+
type = types.listOf types.path;
130
+
List of path(s) to respective plugin(s) which are symlinked from the 'plugins' directory. Note: These plugins need to be packaged before use.
133
+
# Wordpress plugin 'akismet' installation example
134
+
akismetPlugin = pkgs.stdenv.mkDerivation {
135
+
name = "akismet-plugin";
136
+
# Download the theme from the wordpress site
137
+
src = pkgs.fetchurl {
138
+
url = https://downloads.wordpress.org/plugin/akismet.3.1.zip;
139
+
sha256 = "1i4k7qyzna08822ncaz5l00wwxkwcdg4j9h3z2g0ay23q640pclg";
141
+
# We need unzip to build this package
142
+
buildInputs = [ pkgs.unzip ];
143
+
# Installing simply means copying all files to the output directory
144
+
installPhase = "mkdir -p $out; cp -R * $out/";
147
+
And then pass this theme to the themes list like this:
148
+
plugins = [ akismetPlugin ];
151
+
themes = mkOption {
153
+
type = types.listOf types.path;
156
+
List of path(s) to respective theme(s) which are symlinked from the 'theme' directory. Note: These themes need to be packaged before use.
159
+
# For shits and giggles, let's package the responsive theme
160
+
responsiveTheme = pkgs.stdenv.mkDerivation {
161
+
name = "responsive-theme";
162
+
# Download the theme from the wordpress site
163
+
src = pkgs.fetchurl {
164
+
url = http://wordpress.org/themes/download/responsive.1.9.7.6.zip;
165
+
sha256 = "06i26xlc5kdnx903b1gfvnysx49fb4kh4pixn89qii3a30fgd8r8";
167
+
# We need unzip to build this package
168
+
buildInputs = [ pkgs.unzip ];
169
+
# Installing simply means copying all files to the output directory
170
+
installPhase = "mkdir -p $out; cp -R * $out/";
173
+
And then pass this theme to the themes list like this:
174
+
themes = [ responsiveTheme ];
177
+
extraConfig = mkOption {
181
+
define( 'AUTOSAVE_INTERVAL', 60 ); // Seconds
184
+
Any additional text to be appended to Wordpress's wp-config.php
185
+
configuration file. This is a PHP script. For configuration
186
+
settings, see <link xlink:href='http://codex.wordpress.org/Editing_wp-config.php'/>.
191
+
documentRoot = wordpressRoot;
193
+
startupScript = pkgs.writeScript "init-wordpress.sh" ''
195
+
mkdir -p ${config.wordpressUploads}
196
+
chown ${serverInfo.serverConfig.user} ${config.wordpressUploads}
198
+
# we should use systemd dependencies here
199
+
#waitForUnit("network-interfaces.target");
200
+
if [ ! -d ${serverInfo.fullConfig.services.mysql.dataDir}/${config.dbName} ]; then
201
+
# Wait until MySQL is up
202
+
while [ ! -e /var/run/mysql/mysqld.pid ]; do
205
+
${pkgs.mysql}/bin/mysql -e 'CREATE DATABASE ${config.dbName};'
206
+
${pkgs.mysql}/bin/mysql -e 'GRANT ALL ON ${config.dbName}.* TO ${config.dbUser}@localhost IDENTIFIED BY "${config.dbPassword}";'