From b8a237fe6530425ca8c7ae77458f43da9aae9f5b Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Mon, 22 Nov 2021 22:04:22 +0100 Subject: [PATCH] module(wp): add fetchers utilities --- modules/web-apps/wordpress/fetchers-utils.nix | 45 +++++++++++++++++++ modules/web-apps/wordpress/plugins.nix | 2 +- modules/web-apps/wordpress/themes.nix | 2 +- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 modules/web-apps/wordpress/fetchers-utils.nix diff --git a/modules/web-apps/wordpress/fetchers-utils.nix b/modules/web-apps/wordpress/fetchers-utils.nix new file mode 100644 index 0000000..40fbbb2 --- /dev/null +++ b/modules/web-apps/wordpress/fetchers-utils.nix @@ -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 `. + 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 `. + getTheme = name: version: sha256: fetchzip { + inherit name sha256; + url = "https://downloads.wordpress.org/theme/${name}.${version}.zip"; + }; +} diff --git a/modules/web-apps/wordpress/plugins.nix b/modules/web-apps/wordpress/plugins.nix index 267c4c4..2e07ace 100644 --- a/modules/web-apps/wordpress/plugins.nix +++ b/modules/web-apps/wordpress/plugins.nix @@ -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 = [ diff --git a/modules/web-apps/wordpress/themes.nix b/modules/web-apps/wordpress/themes.nix index 97e9a53..a4a153e 100644 --- a/modules/web-apps/wordpress/themes.nix +++ b/modules/web-apps/wordpress/themes.nix @@ -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")