module(wp): add fetchers utilities

This commit is contained in:
Raito Bezarius 2021-11-22 22:04:22 +01:00
parent 98d9e0c140
commit b8a237fe65
3 changed files with 47 additions and 2 deletions

View file

@ -0,0 +1,45 @@
{ fetchzip, runCommand, unzip, ... }: {
# Builds a package from a zip archive.
# The archive must have exactly one, top-level directory which will stripped.
# Example: zipArchive "my-package-name" ./my-package.zip
zipArchive = name: path: runCommand name { buildInputs = [ unzip ]; } ''
unzip "${path}" -d "$TEMPDIR"
top_dir=$(find "$TEMPDIR" -type d -mindepth 1 -maxdepth 1)
if [ "$(echo "$top_dir" | wc -l)" -ne 1 ]; then
echo Archive must have exactly one top-level directory.
exit 1
fi
mv "$top_dir" "$out"
'';
# Builds a package from a folder.
# Example: folder "my-package-name" ./my-package
folder = name: path: runCommand name {} ''
ln -s "${path}" "$out"
'';
# Builds a package from a registered WordPress plugin.
# Example: getPlugin "akismet" "3.2" "0ri9a0lbr269r3crmsa6hn4v4nd4dyblrb0ffvkmig2pvvx25hyn"
# To determine the name, version, and SHA256 hash of a plugin, find it on
# https://wordpress.org/plugins and look at the URL of the "Download" button. Most URLs will tell
# you the name and version. To determine the hash, install `nix-prefetch-zip`
# (via `nix-env -i nix-prefetch-zip`) and run it on the plugin URL:
# `nix-prefetch-zip <URL>`.
getPlugin = name: version: sha256: fetchzip {
inherit name sha256;
url = "https://downloads.wordpress.org/plugin/${name}.${version}.zip";
};
# Builds a package from a registered WordPress theme.
# Example: getTheme "twentyseventeen" "1.0" "01779xz4c3b1drv3v2d1p1rdh1w9a0wsxjxpvp4nzwm26h7bvg7n"
# To determine the name, version, and SHA256 hash of a theme, find it on
# https://wordpress.org/themes and look at the URL of the "Download" button. Most URLs will tell
# you the name and version. To determine the hash, install `nix-prefetch-zip`
# (via `nix-env -i nix-prefetch-zip`) and run it on the theme URL:
# `nix-prefetch-zip <URL>`.
getTheme = name: version: sha256: fetchzip {
inherit name sha256;
url = "https://downloads.wordpress.org/theme/${name}.${version}.zip";
};
}

View file

@ -1,7 +1,7 @@
# A list of your WordPress plugins.
{ callPackage, ... }:
let
utils = callPackage ./utils.nix {};
utils = callPackage ./fetchers-utils.nix {};
getPlugin = utils.getPlugin;
requiredPlugins = [

View file

@ -1,7 +1,7 @@
# A list of your WordPress themes.
{ callPackage, ... }:
let
utils = callPackage ./utils.nix {};
utils = callPackage ./fetchers-utils.nix {};
getTheme = utils.getTheme;
in [
(getTheme "twentyseventeen" "1.1" "1xsdz1s68mavz9i4lhckh7rqw266jqm5mn3ql1gbz03zf6ghf982")