Skip to content

Commit

Permalink
wordpress: package plugins and themes
Browse files Browse the repository at this point in the history
  • Loading branch information
onny committed May 19, 2022
1 parent 90e10f3 commit 1674ee7
Show file tree
Hide file tree
Showing 10 changed files with 302 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pkgs/servers/web-apps/wordpress/packages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
= Add plugin to repository =

To add a plugin to the Wordpress plugin repository, add a new line to the
`wordpress-plugins.json` file with the codename of the plugin.

The codename is the last part in the url of the plugin page, for example
`cookie-notice` in in the url `https://wordpress.org/plugins/cookie-notice/`.

To regenerate the nixpkgs Wordpress plugin repository, run:

```
./generate.sh
```

After that you can commit and submit the changes.

= Usage with the Wordpress module =

The plugins will be available in the namespace `wordpressPackages.plugins`.
Using it together with the Wordpress module could look like this:

```
services.wordpress = {
sites."blog.${config.networking.domain}" = {
plugins = with wordpressPackages.plugins; [
anti-spam-bee
code-syntax-block
cookie-notice
lightbox-with-photoswipe
wp-gdpr-compliance
];
};
};
```
121 changes: 121 additions & 0 deletions pkgs/servers/web-apps/wordpress/packages/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{ lib, newScope }:

let packages = self:
let
generatedJson = {
plugins = builtins.fromJSON (builtins.readFile ./plugins.json);
themes = builtins.fromJSON (builtins.readFile ./themes.json);
languages = builtins.fromJSON (builtins.readFile ./languages.json);
pluginLanguages = builtins.fromJSON (builtins.readFile ./pluginLanguages.json);
themeLanguages = builtins.fromJSON (builtins.readFile ./themeLanguages.json);
};

in {
# Create a generic WordPress package. Most arguments are just passed
# to `mkDerivation`. The version is automatically filtered for weird characters.
mkWordpressDerivation = self.callPackage ({ stdenvNoCC, lib, filterWPString, gettext, wp-cli }:
{ type, pname, version, ... }@args:
assert lib.any (x: x == type) [ "plugin" "theme" "language" "pluginLanguage" "themeLanguage" ];
stdenvNoCC.mkDerivation ({
pname = "wordpress-${type}-${pname}";
version = filterWPString version;

dontConfigure = true;
dontBuild = true;

installPhase = ''
runHook preInstall
cp -R ./. $out
runHook postInstall
'';

passthru = {
wpName = pname;
} // (args.passthru or {});
} // lib.optionalAttrs (type == "language" || type == "pluginLanguage" || type == "themeLanguage") {
nativeBuildInputs = [ gettext wp-cli ];
dontBuild = false;
buildPhase = ''
runHook preBuild
find -name '*.po' -print0 | while IFS= read -d "" -r po; do
msgfmt -o $(basename "$po" .po).mo "$po"
done
wp i18n make-json .
rm *.po
runHook postBuild
'';
} // removeAttrs args [ "type" "pname" "version" "passthru" ])) {};

# Create a derivation from the official wordpress.org packages.
# This takes the type, the pname and the data generated from the go tool.
mkOfficialWordpressDerivation = self.callPackage ({ mkWordpressDerivation, fetchWordpress }:
{ type, pname, data }:
mkWordpressDerivation {
inherit type pname;
version = data.version;

src = fetchWordpress type data;
}) {};

# Filter out all characters that might occur in a version string but that that are not allowed
# in store paths.
filterWPString = builtins.replaceStrings [ " " "," "/" "&" ";" ''"'' "'" "$" ":" "(" ")" "[" "]" "{" "}" "|" "*" "\t" ] [ "_" "." "." "" "" "" "" "" "" "" "" "" "" "" "" "-" "" "" ];

# Fetch a package from the official wordpress.org SVN.
# The data supplied is the data straight from the go tool.
fetchWordpress = self.callPackage ({ fetchsvn }: type: data: fetchsvn {
inherit (data) rev sha256;
url = if type == "plugin" || type == "theme" then
"https://" + type + "s.svn.wordpress.org/" + data.path
else if type == "language" then
"https://i18n.svn.wordpress.org/core/" + data.version + "/" + data.path
else if type == "pluginLanguage" then
"https://i18n.svn.wordpress.org/plugins/" + data.path
else if type == "themeLanguage" then
"https://i18n.svn.wordpress.org/themes/" + data.path
else
throw "fetchWordpress: invalid package type ${type}";
}) {};

} // lib.mapAttrs (type: pkgs: lib.makeExtensible (_: lib.mapAttrs (pname: data: self.mkOfficialWordpressDerivation { type = lib.removeSuffix "s" type; inherit pname data; }) pkgs)) generatedJson;

# This creates an extensible scope and immediately extends it with our custom
# package overrides.
in (lib.makeExtensible (_: (lib.makeScope newScope packages))).extend (selfWP: superWP: {

plugins = superWP.plugins.extend (selfPlugins: superPlugins: {
# Fix the plugin caching store paths
visualcomposer = superPlugins.visualcomposer.overrideAttrs (oA: {
postInstall = ''
${oA.postInstall or ""}
rm -r $out/cache
'';
});

# Add nix syntax support
prismatic = superWP.callPackage ({ fetchurl }: superPlugins.prismatic.overrideAttrs (oA: {
postInstall = ''
${oA.postInstall or ""}
cp ${fetchurl {
url = "https://raw.githubusercontent.com/PrismJS/prism/v1.25.0/components/prism-nix.js";
sha256 = "1ajw7pdnppgyar3v42nraxm0f4rzyqb5fw75ych8q3x94v4klgc7";
}} $out/lib/prism/js/lang-nix.js
# Allow loading the js
substituteInPlace $out/inc/resources-enqueue.php \
--replace "'lang-none'," "'lang-none', 'lang-nix'," \
--replace "'language-none'," "'language-none', 'language-nix',"
# Add the language into the editor
sed -i "/Language\.\./a { label : 'Nix', value : 'nix' }," $out/js/blocks-prism.js
sed -i "/Language\.\./a { label : 'Nix', value : 'nix' }," $out/js/buttons-prism.js
'';
})) {};
});

#themes = superWP.plugins.extend (selfThemes: superThemes: {
#});
})
4 changes: 4 additions & 0 deletions pkgs/servers/web-apps/wordpress/packages/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
PLUGINS=`cat wordplress-plugins.json | jq -r '.[]' | sed -z 's/\n/,/g;s/,$/\n/'`
WP_VERSION=5.9.3 wp4nix -p $PLUGINS -pl en
rm *.log
1 change: 1 addition & 0 deletions pkgs/servers/web-apps/wordpress/packages/languages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
116 changes: 116 additions & 0 deletions pkgs/servers/web-apps/wordpress/packages/plugins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"add-widget-after-content": {
"path": "add-widget-after-content/tags/2.4.4",
"rev": "2671853",
"sha256": "0snrkd783f1qxry01858l3r0ll9381xhsig7wlmrvi1zm5jf2drc",
"version": "2.4.4"
},
"antispam-bee": {
"path": "antispam-bee/tags/2.11.0",
"rev": "2680712",
"sha256": "0r5hx47ffiy387q43bxghx4h0r1dmpq5f9pq90j7nc1rjh78h6j0",
"version": "2.11.0"
},
"async-javascript": {
"path": "async-javascript/tags/2.21.08.31",
"rev": "2666300",
"sha256": "1w82501mhln93n8qynf7cbr6i76vg4vhnkhm16k9drw1f995zh30",
"version": "2.21.08.31"
},
"breeze": {
"path": "breeze/tags/2.0.4",
"rev": "2720485",
"sha256": "1kdpr3vsxz9clab0xc4kz7981i7cznhrw409qky4h8z2wg1hw5hb",
"version": "2.0.4"
},
"co-authors-plus": {
"path": "co-authors-plus/tags/3.5.1",
"rev": "2714546",
"sha256": "0gkk7ppyw04hq72z54bs56bhyr7a67jkqzcpnmmg3mf2dvjg43js",
"version": "3.5.1"
},
"code-syntax-block": {
"path": "code-syntax-block/tags/3.0.0",
"rev": "2668886",
"sha256": "0k49bgy6sq1kqchpc72wi6lf3zfr0kvcc4cc6svmvxm5sf056h14",
"version": "3.0.0"
},
"cookie-notice": {
"path": "cookie-notice/tags/2.2.3",
"rev": "2686748",
"sha256": "101znjcmw6zp2adychr3vsczk8wc4mpfv3iifi5njdz355zpmnj6",
"version": "2.2.3"
},
"disable-xml-rpc": {
"path": "disable-xml-rpc/tags/1.0.1",
"rev": "2561901",
"sha256": "04x5dj79bx5avx8db991nlhrpd3qv3maniqmzwnyd8ab2zblzx83",
"version": "1.0.1"
},
"jetpack": {
"path": "jetpack/tags/10.9",
"rev": "2717621",
"sha256": "04srmnb4qi7pw2kpbixpask1lv13w389blwhlmasdicyqzifldgp",
"version": "10.9"
},
"jetpack-lite": {
"path": "jetpack-lite/tags/3.0.3",
"rev": "1895157",
"sha256": "04wq8cnhzgzrhm5pjwicsnavc46n6wdmb6xf8gz4wwl1di2hl471",
"version": "3.0.3"
},
"lightbox-photoswipe": {
"path": "lightbox-photoswipe/tags/3.4.2",
"rev": "2700649",
"sha256": "10j45m4f4f74r8j8b979c5x930p7b5lzx168wy3p89hljjlwqswj",
"version": "3.4.2"
},
"mailpoet": {
"path": "mailpoet/tags/3.89.2",
"rev": "2726667",
"sha256": "11k4lv4dhpigh9s2hzh4acyy36bh7050f7cb62m4b747w77z14ar",
"version": "3.89.2"
},
"opengraph": {
"path": "opengraph/tags/1.11.0",
"rev": "2665460",
"sha256": "0pjdgz6gwl1aivdnmik9wdmf8kr3mjq1dg477p3ldp1mp6ac8a65",
"version": "1.11.0"
},
"simple-login-captcha": {
"path": "simple-login-captcha/tags/1.3.3",
"rev": "2662772",
"sha256": "0yrqrg2fr27y7w8hhl3ib1b1hx3j660mmz6iq07sgs61y6ch6hzz",
"version": "1.3.3"
},
"webp-converter-for-media": {
"path": "webp-converter-for-media/tags/4.3.4",
"rev": "2726424",
"sha256": "0z50n7752cvfgl22vk9mkkp4c8z14shq4mr8qn23qxj6812zinlv",
"version": "4.3.4"
},
"wp-gdpr-compliance": {
"path": "wp-gdpr-compliance/tags/2.0.15",
"rev": "2719208",
"sha256": "11qiwjq5bd5q9qa0ba0mp9rrck7gd6sxhpzswfg3cy2wnmg2zmpc",
"version": "2.0.15"
},
"wp-mail-smtp": {
"path": "wp-mail-smtp/tags/3.4.0",
"rev": "2715420",
"sha256": "1010f7fqw4ncw5kya2p2xlrbc6sb7dfknjzg2zwgdwswnxdgspy1",
"version": "3.4.0"
},
"wp-statistics": {
"path": "wp-statistics/tags/13.2.3",
"rev": "2722232",
"sha256": "1akrjkzkh4y31r9932bl5fa8ksq6cjcrfxlwpv2jzham4s9l3ham",
"version": "13.2.3"
},
"wp-user-avatars": {
"path": "wp-user-avatars/trunk",
"rev": "2540784",
"sha256": "1g21nl6xs9zyq0ainjwa06wl90975l8f9rj0fa20zkmw17w2mdgl",
"version": "1.4.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions pkgs/servers/web-apps/wordpress/packages/themes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
21 changes: 21 additions & 0 deletions pkgs/servers/web-apps/wordpress/packages/wordplress-plugins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
"add-widget-after-content"
, "antispam-bee"
, "async-javascript"
, "breeze"
, "code-syntax-block"
, "cookie-notice"
, "co-authors-plus"
, "disable-xml-rpc"
, "jetpack"
, "jetpack-lite"
, "lightbox-photoswipe"
, "mailpoet"
, "opengraph"
, "simple-login-captcha"
, "webp-converter-for-media"
, "wp-mail-smtp"
, "wp-gdpr-compliance"
, "wp-statistics"
, "wp-user-avatars"
]
2 changes: 2 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34875,6 +34875,8 @@ with pkgs;

wordpress = callPackage ../servers/web-apps/wordpress { };

wordpressPackages = recurseIntoAttrs (callPackage ../servers/web-apps/wordpress/packages/default.nix { });

wprecon = callPackage ../tools/security/wprecon { };

wraith = callPackage ../applications/networking/irc/wraith { };
Expand Down

0 comments on commit 1674ee7

Please sign in to comment.