2015-03-10 15:53:50 +00:00
|
|
|
{ config, lib, pkgs, serverInfo, php, ... }:
|
2015-06-25 14:21:14 +00:00
|
|
|
# http://codex.wordpress.org/Hardening_WordPress
|
2015-03-10 15:53:50 +00:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2015-06-25 14:21:14 +00:00
|
|
|
|
2015-09-07 21:05:02 +00:00
|
|
|
version = "4.3";
|
|
|
|
fullversion = "${version}";
|
2015-03-10 15:53:50 +00:00
|
|
|
|
|
|
|
# Our bare-bones wp-config.php file using the above settings
|
|
|
|
wordpressConfig = pkgs.writeText "wp-config.php" ''
|
|
|
|
<?php
|
|
|
|
define('DB_NAME', '${config.dbName}');
|
|
|
|
define('DB_USER', '${config.dbUser}');
|
|
|
|
define('DB_PASSWORD', '${config.dbPassword}');
|
|
|
|
define('DB_HOST', '${config.dbHost}');
|
|
|
|
define('DB_CHARSET', 'utf8');
|
|
|
|
$table_prefix = '${config.tablePrefix}';
|
2015-09-08 23:12:10 +00:00
|
|
|
${config.extraConfig}
|
2015-03-10 15:53:50 +00:00
|
|
|
if ( !defined('ABSPATH') )
|
|
|
|
define('ABSPATH', dirname(__FILE__) . '/');
|
|
|
|
require_once(ABSPATH . 'wp-settings.php');
|
|
|
|
'';
|
|
|
|
|
|
|
|
# .htaccess to support pretty URLs
|
|
|
|
htaccess = pkgs.writeText "htaccess" ''
|
|
|
|
<IfModule mod_rewrite.c>
|
|
|
|
RewriteEngine On
|
|
|
|
RewriteBase /
|
2015-06-25 14:21:14 +00:00
|
|
|
RewriteRule ^index\.php$ - [L]
|
|
|
|
|
|
|
|
# add a trailing slash to /wp-admin
|
|
|
|
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
|
|
|
|
|
|
|
|
RewriteCond %{REQUEST_FILENAME} -f [OR]
|
|
|
|
RewriteCond %{REQUEST_FILENAME} -d
|
|
|
|
RewriteRule ^ - [L]
|
|
|
|
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
|
|
|
|
RewriteRule ^(.*\.php)$ $1 [L]
|
|
|
|
RewriteRule . index.php [L]
|
2015-03-10 15:53:50 +00:00
|
|
|
</IfModule>
|
2015-09-10 11:21:38 +00:00
|
|
|
|
|
|
|
${config.extraHtaccess}
|
2015-03-10 15:53:50 +00:00
|
|
|
'';
|
|
|
|
|
2015-06-25 14:21:14 +00:00
|
|
|
# WP translation can be found here:
|
2015-07-03 11:06:02 +00:00
|
|
|
# https://github.com/nixcloud/wordpress-translations
|
2015-06-25 14:21:14 +00:00
|
|
|
supportedLanguages = {
|
2015-07-03 11:06:02 +00:00
|
|
|
en_GB = { revision="d6c005372a5318fd758b710b77a800c86518be13"; sha256="0qbbsi87k47q4rgczxx541xz4z4f4fr49hw4lnaxkdsf5maz8p9p"; };
|
|
|
|
de_DE = { revision="3c62955c27baaae98fd99feb35593d46562f4736"; sha256="1shndgd11dk836dakrjlg2arwv08vqx6j4xjh4jshvwmjab6ng6p"; };
|
|
|
|
zh_ZN = { revision="12b9f811e8cae4b6ee41de343d35deb0a8fdda6d"; sha256="1339ggsxh0g6lab37jmfxicsax4h702rc3fsvv5azs7mcznvwh47"; };
|
|
|
|
fr_FR = { revision="688c8b1543e3d38d9e8f57e0a6f2a2c3c8b588bd"; sha256="1j41iak0i6k7a4wzyav0yrllkdjjskvs45w53db8vfm8phq1n014"; };
|
2015-06-25 14:21:14 +00:00
|
|
|
};
|
|
|
|
|
2015-07-03 11:06:02 +00:00
|
|
|
downloadLanguagePack = language: revision: sha256s:
|
2015-06-25 14:21:14 +00:00
|
|
|
pkgs.stdenv.mkDerivation rec {
|
2015-07-03 11:06:02 +00:00
|
|
|
name = "wp_${language}";
|
|
|
|
src = pkgs.fetchFromGitHub {
|
|
|
|
owner = "nixcloud";
|
|
|
|
repo = "wordpress-translations";
|
|
|
|
rev = revision;
|
|
|
|
sha256 = sha256s;
|
2015-06-25 14:21:14 +00:00
|
|
|
};
|
|
|
|
installPhase = "mkdir -p $out; cp -R * $out/";
|
|
|
|
};
|
|
|
|
|
2015-07-03 11:06:02 +00:00
|
|
|
selectedLanguages = map (lang: downloadLanguagePack lang supportedLanguages.${lang}.revision supportedLanguages.${lang}.sha256) (config.languages);
|
2015-06-25 14:21:14 +00:00
|
|
|
|
2015-03-10 15:53:50 +00:00
|
|
|
# The wordpress package itself
|
|
|
|
wordpressRoot = pkgs.stdenv.mkDerivation rec {
|
|
|
|
name = "wordpress";
|
2015-06-25 14:21:14 +00:00
|
|
|
src = pkgs.fetchFromGitHub {
|
|
|
|
owner = "WordPress";
|
|
|
|
repo = "WordPress";
|
|
|
|
rev = "${fullversion}";
|
2015-09-07 21:05:02 +00:00
|
|
|
sha256 = "0sz5jjhjpwqis8336gyq9a77cr4sf8zahd1y4pzmpvpzn9cn503y";
|
2015-03-10 15:53:50 +00:00
|
|
|
};
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out
|
2015-06-25 14:21:14 +00:00
|
|
|
# copy all the wordpress files we downloaded
|
2015-03-10 15:53:50 +00:00
|
|
|
cp -R * $out/
|
2015-06-25 14:21:14 +00:00
|
|
|
|
|
|
|
# symlink the wordpress config
|
2015-03-10 15:53:50 +00:00
|
|
|
ln -s ${wordpressConfig} $out/wp-config.php
|
2015-06-25 14:21:14 +00:00
|
|
|
# symlink custom .htaccess
|
2015-03-10 15:53:50 +00:00
|
|
|
ln -s ${htaccess} $out/.htaccess
|
2015-06-25 14:21:14 +00:00
|
|
|
# symlink uploads directory
|
2015-03-10 15:53:50 +00:00
|
|
|
ln -s ${config.wordpressUploads} $out/wp-content/uploads
|
2015-06-25 14:21:14 +00:00
|
|
|
|
|
|
|
# remove bundled plugins(s) coming with wordpress
|
|
|
|
rm -Rf $out/wp-content/plugins/*
|
|
|
|
# remove bundled themes(s) coming with wordpress
|
|
|
|
rm -Rf $out/wp-content/themes/*
|
|
|
|
|
|
|
|
# symlink additional theme(s)
|
2015-03-10 15:53:50 +00:00
|
|
|
${concatMapStrings (theme: "ln -s ${theme} $out/wp-content/themes/${theme.name}\n") config.themes}
|
2015-06-25 14:21:14 +00:00
|
|
|
# symlink additional plugin(s)
|
|
|
|
${concatMapStrings (plugin: "ln -s ${plugin} $out/wp-content/plugins/${plugin.name}\n") (config.plugins) }
|
|
|
|
|
|
|
|
# symlink additional translation(s)
|
|
|
|
mkdir -p $out/wp-content/languages
|
|
|
|
${concatMapStrings (language: "ln -s ${language}/*.mo ${language}/*.po $out/wp-content/languages/\n") (selectedLanguages) }
|
2015-03-10 15:53:50 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
# And some httpd extraConfig to make things work nicely
|
|
|
|
extraConfig = ''
|
|
|
|
<Directory ${wordpressRoot}>
|
|
|
|
DirectoryIndex index.php
|
|
|
|
Allow from *
|
|
|
|
Options FollowSymLinks
|
|
|
|
AllowOverride All
|
|
|
|
</Directory>
|
|
|
|
'';
|
|
|
|
|
|
|
|
enablePHP = true;
|
|
|
|
|
|
|
|
options = {
|
|
|
|
dbHost = mkOption {
|
|
|
|
default = "localhost";
|
|
|
|
description = "The location of the database server.";
|
|
|
|
example = "localhost";
|
|
|
|
};
|
|
|
|
dbName = mkOption {
|
|
|
|
default = "wordpress";
|
|
|
|
description = "Name of the database that holds the Wordpress data.";
|
|
|
|
example = "localhost";
|
|
|
|
};
|
|
|
|
dbUser = mkOption {
|
|
|
|
default = "wordpress";
|
2015-06-25 14:21:14 +00:00
|
|
|
description = "The dbUser, read: the username, for the database.";
|
2015-03-10 15:53:50 +00:00
|
|
|
example = "wordpress";
|
|
|
|
};
|
|
|
|
dbPassword = mkOption {
|
|
|
|
default = "wordpress";
|
2015-06-25 14:21:14 +00:00
|
|
|
description = "The mysql password to the respective dbUser.";
|
2015-03-10 15:53:50 +00:00
|
|
|
example = "wordpress";
|
|
|
|
};
|
|
|
|
tablePrefix = mkOption {
|
|
|
|
default = "wp_";
|
|
|
|
description = ''
|
|
|
|
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'/>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
wordpressUploads = mkOption {
|
|
|
|
default = "/data/uploads";
|
|
|
|
description = ''
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
plugins = mkOption {
|
|
|
|
default = [];
|
|
|
|
type = types.listOf types.path;
|
|
|
|
description =
|
|
|
|
''
|
2015-06-25 14:21:14 +00:00
|
|
|
List of path(s) to respective plugin(s) which are symlinked from the 'plugins' directory. Note: These plugins need to be packaged before use, see example.
|
2015-03-10 15:53:50 +00:00
|
|
|
'';
|
|
|
|
example = ''
|
|
|
|
# Wordpress plugin 'akismet' installation example
|
|
|
|
akismetPlugin = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "akismet-plugin";
|
|
|
|
# Download the theme from the wordpress site
|
|
|
|
src = pkgs.fetchurl {
|
|
|
|
url = https://downloads.wordpress.org/plugin/akismet.3.1.zip;
|
|
|
|
sha256 = "1i4k7qyzna08822ncaz5l00wwxkwcdg4j9h3z2g0ay23q640pclg";
|
|
|
|
};
|
|
|
|
# We need unzip to build this package
|
|
|
|
buildInputs = [ pkgs.unzip ];
|
|
|
|
# Installing simply means copying all files to the output directory
|
|
|
|
installPhase = "mkdir -p $out; cp -R * $out/";
|
|
|
|
};
|
|
|
|
|
|
|
|
And then pass this theme to the themes list like this:
|
|
|
|
plugins = [ akismetPlugin ];
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
themes = mkOption {
|
|
|
|
default = [];
|
|
|
|
type = types.listOf types.path;
|
|
|
|
description =
|
|
|
|
''
|
2015-06-25 14:21:14 +00:00
|
|
|
List of path(s) to respective theme(s) which are symlinked from the 'theme' directory. Note: These themes need to be packaged before use, see example.
|
2015-03-10 15:53:50 +00:00
|
|
|
'';
|
|
|
|
example = ''
|
|
|
|
# For shits and giggles, let's package the responsive theme
|
|
|
|
responsiveTheme = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "responsive-theme";
|
|
|
|
# Download the theme from the wordpress site
|
|
|
|
src = pkgs.fetchurl {
|
|
|
|
url = http://wordpress.org/themes/download/responsive.1.9.7.6.zip;
|
|
|
|
sha256 = "06i26xlc5kdnx903b1gfvnysx49fb4kh4pixn89qii3a30fgd8r8";
|
|
|
|
};
|
|
|
|
# We need unzip to build this package
|
|
|
|
buildInputs = [ pkgs.unzip ];
|
|
|
|
# Installing simply means copying all files to the output directory
|
|
|
|
installPhase = "mkdir -p $out; cp -R * $out/";
|
|
|
|
};
|
|
|
|
|
|
|
|
And then pass this theme to the themes list like this:
|
|
|
|
themes = [ responsiveTheme ];
|
|
|
|
'';
|
|
|
|
};
|
2015-06-25 14:21:14 +00:00
|
|
|
languages = mkOption {
|
|
|
|
default = [];
|
|
|
|
description = "Installs wordpress language packs based on the list, see wordpress.nix for possible translations.";
|
|
|
|
example = "[ \"en_GB\" \"de_DE\" ];";
|
|
|
|
};
|
2015-03-10 15:53:50 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
example =
|
|
|
|
''
|
|
|
|
define( 'AUTOSAVE_INTERVAL', 60 ); // Seconds
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Any additional text to be appended to Wordpress's wp-config.php
|
|
|
|
configuration file. This is a PHP script. For configuration
|
|
|
|
settings, see <link xlink:href='http://codex.wordpress.org/Editing_wp-config.php'/>.
|
|
|
|
'';
|
|
|
|
};
|
2015-09-10 11:21:38 +00:00
|
|
|
extraHtaccess = mkOption {
|
|
|
|
default = "";
|
|
|
|
example =
|
|
|
|
''
|
|
|
|
php_value upload_max_filesize 20M
|
|
|
|
php_value post_max_size 20M
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Any additional text to be appended to Wordpress's .htaccess file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2015-03-10 15:53:50 +00:00
|
|
|
|
|
|
|
documentRoot = wordpressRoot;
|
|
|
|
|
2015-07-03 11:06:02 +00:00
|
|
|
# FIXME adding the user has to be done manually for the time being
|
2015-03-10 15:53:50 +00:00
|
|
|
startupScript = pkgs.writeScript "init-wordpress.sh" ''
|
|
|
|
#!/bin/sh
|
|
|
|
mkdir -p ${config.wordpressUploads}
|
|
|
|
chown ${serverInfo.serverConfig.user} ${config.wordpressUploads}
|
|
|
|
|
|
|
|
# we should use systemd dependencies here
|
|
|
|
#waitForUnit("network-interfaces.target");
|
|
|
|
if [ ! -d ${serverInfo.fullConfig.services.mysql.dataDir}/${config.dbName} ]; then
|
2015-06-25 14:21:14 +00:00
|
|
|
echo "Need to create the database '${config.dbName}' and grant permissions to user named '${config.dbUser}'."
|
2015-03-10 15:53:50 +00:00
|
|
|
# Wait until MySQL is up
|
|
|
|
while [ ! -e /var/run/mysql/mysqld.pid ]; do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
${pkgs.mysql}/bin/mysql -e 'CREATE DATABASE ${config.dbName};'
|
|
|
|
${pkgs.mysql}/bin/mysql -e 'GRANT ALL ON ${config.dbName}.* TO ${config.dbUser}@localhost IDENTIFIED BY "${config.dbPassword}";'
|
2015-06-25 14:21:14 +00:00
|
|
|
else
|
|
|
|
echo "Good, no need to do anything database related."
|
2015-03-10 15:53:50 +00:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
}
|