1# Source: https://git.helsinki.tools/helsinki-systems/wp4nix/-/blob/master/default.nix
2# Licensed under: MIT
3# Slightly modified
4
5{ lib, newScope, plugins, themes, languages, callPackage }:
6
7let packages = self:
8 let
9 generatedJson = {
10 inherit plugins themes languages;
11 };
12
13 in {
14 # Create a generic WordPress package. Most arguments are just passed
15 # to `mkDerivation`. The version is automatically filtered for weird characters.
16 mkWordpressDerivation = self.callPackage ({ stdenvNoCC, lib, filterWPString, gettext, wp-cli }:
17 { type, pname, version, ... }@args:
18 assert lib.any (x: x == type) [ "plugin" "theme" "language" ];
19 stdenvNoCC.mkDerivation ({
20 pname = "wordpress-${type}-${pname}";
21 version = filterWPString version;
22
23 dontConfigure = true;
24 dontBuild = true;
25
26 installPhase = ''
27 runHook preInstall
28 cp -R ./. $out
29 runHook postInstall
30 '';
31
32 passthru = {
33 wpName = pname;
34 } // (args.passthru or {});
35 } // lib.optionalAttrs (type == "language") {
36 nativeBuildInputs = [ gettext wp-cli ];
37 dontBuild = false;
38 buildPhase = ''
39 runHook preBuild
40
41 find -name '*.po' -print0 | while IFS= read -d "" -r po; do
42 msgfmt -o $(basename "$po" .po).mo "$po"
43 done
44 wp i18n make-json .
45 rm *.po
46
47 runHook postBuild
48 '';
49 } // removeAttrs args [ "type" "pname" "version" "passthru" ])) {};
50
51 # Create a derivation from the official wordpress.org packages.
52 # This takes the type, the pname and the data generated from the go tool.
53 mkOfficialWordpressDerivation = self.callPackage ({ mkWordpressDerivation, fetchWordpress }:
54 { type, pname, data }:
55 mkWordpressDerivation {
56 inherit type pname;
57 version = data.version;
58
59 src = fetchWordpress type data;
60 }) {};
61
62 # Filter out all characters that might occur in a version string but that that are not allowed
63 # in store paths.
64 filterWPString = builtins.replaceStrings [ " " "," "/" "&" ";" ''"'' "'" "$" ":" "(" ")" "[" "]" "{" "}" "|" "*" "\t" ] [ "_" "." "." "" "" "" "" "" "" "" "" "" "" "" "" "-" "" "" ];
65
66 # Fetch a package from the official wordpress.org SVN.
67 # The data supplied is the data straight from the go tool.
68 fetchWordpress = self.callPackage ({ fetchsvn }: type: data: fetchsvn {
69 inherit (data) rev sha256;
70 url = if type == "plugin" || type == "theme" then
71 "https://" + type + "s.svn.wordpress.org/" + data.path
72 else if type == "language" then
73 "https://i18n.svn.wordpress.org/core/" + data.version + "/" + data.path
74 else if type == "pluginLanguage" then
75 "https://i18n.svn.wordpress.org/plugins/" + data.path
76 else if type == "themeLanguage" then
77 "https://i18n.svn.wordpress.org/themes/" + data.path
78 else
79 throw "fetchWordpress: invalid package type ${type}";
80 }) {};
81
82 } // lib.mapAttrs (type: pkgs: lib.makeExtensible (_: lib.mapAttrs (pname: data: self.mkOfficialWordpressDerivation { type = lib.removeSuffix "s" type; inherit pname data; }) pkgs)) generatedJson;
83
84# This creates an extensible scope.
85in lib.recursiveUpdate ((lib.makeExtensible (_: (lib.makeScope newScope packages))).extend (selfWP: superWP: {})) (callPackage ./thirdparty.nix {})