about summary refs log tree commit diff
path: root/nixpkgs/pkgs/servers/web-apps/wordpress/packages/default.nix
blob: 715e9556bc7fd0e848b0e96620aa9f2f533662d9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Source: https://git.helsinki.tools/helsinki-systems/wp4nix/-/blob/master/default.nix
# Licensed under: MIT
# Slightly modified

{ lib, newScope, plugins, themes, languages, callPackage }:

let packages = self:
  let
    generatedJson = {
      inherit plugins themes languages;
    };

  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" ];
        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") {
          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.
in lib.recursiveUpdate ((lib.makeExtensible (_: (lib.makeScope newScope packages))).extend (selfWP: superWP: {})) (callPackage ./thirdparty.nix {})