Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 207 lines 5.2 kB view raw
1# Source: https://git.helsinki.tools/helsinki-systems/wp4nix/-/blob/master/default.nix 2# Licensed under: MIT 3# Slightly modified 4 5{ 6 lib, 7 newScope, 8 plugins, 9 themes, 10 languages, 11 callPackage, 12}: 13 14let 15 packages = 16 self: 17 let 18 generatedJson = { 19 inherit plugins themes languages; 20 }; 21 sourceJson = { 22 plugins = builtins.fromJSON (builtins.readFile ./wordpress-plugins.json); 23 themes = builtins.fromJSON (builtins.readFile ./wordpress-themes.json); 24 languages = builtins.fromJSON (builtins.readFile ./wordpress-languages.json); 25 }; 26 27 in 28 { 29 # Create a generic WordPress package. Most arguments are just passed 30 # to `mkDerivation`. The version is automatically filtered for weird characters. 31 mkWordpressDerivation = self.callPackage ( 32 { 33 stdenvNoCC, 34 lib, 35 filterWPString, 36 gettext, 37 wp-cli, 38 }: 39 { 40 type, 41 pname, 42 version, 43 license, 44 ... 45 }@args: 46 assert lib.any (x: x == type) [ 47 "plugin" 48 "theme" 49 "language" 50 ]; 51 stdenvNoCC.mkDerivation ( 52 { 53 pname = "wordpress-${type}-${pname}"; 54 version = filterWPString version; 55 56 dontConfigure = true; 57 dontBuild = true; 58 59 installPhase = '' 60 runHook preInstall 61 cp -R ./. $out 62 runHook postInstall 63 ''; 64 65 passthru = { 66 wpName = pname; 67 }; 68 69 meta = { 70 license = lib.licenses.${license}; 71 } 72 // (args.passthru or { }); 73 } 74 // lib.optionalAttrs (type == "language") { 75 nativeBuildInputs = [ 76 gettext 77 wp-cli 78 ]; 79 dontBuild = false; 80 buildPhase = '' 81 runHook preBuild 82 83 find -name '*.po' -print0 | while IFS= read -d "" -r po; do 84 msgfmt -o $(basename "$po" .po).mo "$po" 85 done 86 wp i18n make-json . 87 rm *.po 88 89 runHook postBuild 90 ''; 91 } 92 // removeAttrs args [ 93 "type" 94 "pname" 95 "version" 96 "passthru" 97 ] 98 ) 99 ) { }; 100 101 # Create a derivation from the official wordpress.org packages. 102 # This takes the type, the pname and the data generated from the go tool. 103 mkOfficialWordpressDerivation = self.callPackage ( 104 { mkWordpressDerivation, fetchWordpress }: 105 { 106 type, 107 pname, 108 data, 109 license, 110 }: 111 mkWordpressDerivation { 112 inherit type pname license; 113 version = data.version; 114 115 src = fetchWordpress type data; 116 } 117 ) { }; 118 119 # Filter out all characters that might occur in a version string but that that are not allowed 120 # in store paths. 121 filterWPString = 122 builtins.replaceStrings 123 [ 124 " " 125 "," 126 "/" 127 "&" 128 ";" 129 ''"'' 130 "'" 131 "$" 132 ":" 133 "(" 134 ")" 135 "[" 136 "]" 137 "{" 138 "}" 139 "|" 140 "*" 141 "\t" 142 ] 143 [ 144 "_" 145 "." 146 "." 147 "" 148 "" 149 "" 150 "" 151 "" 152 "" 153 "" 154 "" 155 "" 156 "" 157 "" 158 "" 159 "-" 160 "" 161 "" 162 ]; 163 164 # Fetch a package from the official wordpress.org SVN. 165 # The data supplied is the data straight from the go tool. 166 fetchWordpress = self.callPackage ( 167 { fetchsvn }: 168 type: data: 169 fetchsvn { 170 inherit (data) rev sha256; 171 url = 172 if type == "plugin" || type == "theme" then 173 "https://" + type + "s.svn.wordpress.org/" + data.path 174 else if type == "language" then 175 "https://i18n.svn.wordpress.org/core/" + data.version + "/" + data.path 176 else if type == "pluginLanguage" then 177 "https://i18n.svn.wordpress.org/plugins/" + data.path 178 else if type == "themeLanguage" then 179 "https://i18n.svn.wordpress.org/themes/" + data.path 180 else 181 throw "fetchWordpress: invalid package type ${type}"; 182 } 183 ) { }; 184 185 } 186 // lib.mapAttrs ( 187 type: pkgs: 188 lib.recurseIntoAttrs ( 189 lib.makeExtensible ( 190 _: 191 lib.mapAttrs ( 192 pname: data: 193 self.mkOfficialWordpressDerivation { 194 type = lib.removeSuffix "s" type; 195 inherit pname data; 196 license = sourceJson.${type}.${pname}; 197 } 198 ) pkgs 199 ) 200 ) 201 ) generatedJson; 202 203in 204# This creates an extensible scope. 205lib.recursiveUpdate ((lib.makeExtensible (_: (lib.makeScope newScope packages))).extend ( 206 selfWP: superWP: { } 207)) (callPackage ./thirdparty.nix { })