From 9495682f57afdae63f4ea3585169adbc3b72f434 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Thu, 28 Mar 2024 14:24:58 +0100 Subject: [PATCH] bekkalokk: package mediawiki extensions outside of module --- flake.nix | 3 + hosts/bekkalokk/services/mediawiki.nix | 17 +---- packages/mediawiki-extensions/default.nix | 7 ++ .../delete-batch/default.nix | 7 ++ .../pluggable-auth/default.nix | 7 ++ .../simple-saml-php/default.nix | 7 ++ .../update-mediawiki-extensions.py | 66 +++++++++++++++++++ .../user-merge/default.nix | 7 ++ 8 files changed, 105 insertions(+), 16 deletions(-) create mode 100644 packages/mediawiki-extensions/default.nix create mode 100644 packages/mediawiki-extensions/delete-batch/default.nix create mode 100644 packages/mediawiki-extensions/pluggable-auth/default.nix create mode 100644 packages/mediawiki-extensions/simple-saml-php/default.nix create mode 100755 packages/mediawiki-extensions/update-mediawiki-extensions.py create mode 100644 packages/mediawiki-extensions/user-merge/default.nix diff --git a/flake.nix b/flake.nix index 26c6e6d..1607e6b 100644 --- a/flake.nix +++ b/flake.nix @@ -80,6 +80,7 @@ overlays = [ (final: prev: { heimdal = unstablePkgs.heimdal; + mediawiki-extensions = final.callPackage ./packages/mediawiki-extensions { }; }) ]; }; @@ -123,6 +124,8 @@ (nixlib.getAttrs allMachines self.packages.x86_64-linux); simplesamlphp = pkgs.callPackage ./packages/simplesamlphp { }; + + mediawiki-extensions = pkgs.callPackage ./packages/mediawiki-extensions { }; } // nixlib.genAttrs allMachines (machine: self.nixosConfigurations.${machine}.config.system.build.toplevel); }; diff --git a/hosts/bekkalokk/services/mediawiki.nix b/hosts/bekkalokk/services/mediawiki.nix index 1caea97..dc1727c 100644 --- a/hosts/bekkalokk/services/mediawiki.nix +++ b/hosts/bekkalokk/services/mediawiki.nix @@ -60,22 +60,7 @@ in { }; extensions = { - DeleteBatch = pkgs.fetchzip { - url = "https://extdist.wmflabs.org/dist/extensions/DeleteBatch-REL1_39-995ea6f.tar.gz"; - sha256 = "sha256-0F4GLCy2f5WcWIY2YgF1tVxgYbglR0VOsj/pMrW93b8="; - }; - UserMerge = pkgs.fetchzip { - url = "https://extdist.wmflabs.org/dist/extensions/UserMerge-REL1_39-b10d50e.tar.gz"; - sha256 = "sha256-bXhj1+OlOUJDbvEuc8iwqb1LLEu6cN6+C/7cAvnWPOQ="; - }; - PluggableAuth = pkgs.fetchzip { - url = "https://extdist.wmflabs.org/dist/extensions/PluggableAuth-REL1_39-1210fc3.tar.gz"; - sha256 = "sha256-F6bTMCzkK3kZwZGIsNE87WlZWqXXmTMhEjApO99YKR0="; - }; - SimpleSAMLphp = pkgs.fetchzip { - url = "https://extdist.wmflabs.org/dist/extensions/SimpleSAMLphp-REL1_39-dcf0acb.tar.gz"; - sha256 = "sha256-tCvFmb2+q2rxms+lRo5pgoI3h6GjCwXAR8XisPg03TQ="; - }; + inherit (pkgs.mediawiki-extensions) DeleteBatch UserMerge PluggableAuth SimpleSAMLphp; }; extraConfig = let diff --git a/packages/mediawiki-extensions/default.nix b/packages/mediawiki-extensions/default.nix new file mode 100644 index 0000000..72117b9 --- /dev/null +++ b/packages/mediawiki-extensions/default.nix @@ -0,0 +1,7 @@ +{ pkgs, lib }: +lib.makeScope pkgs.newScope (self: { + DeleteBatch = self.callPackage ./delete-batch { }; + PluggableAuth = self.callPackage ./pluggable-auth { }; + SimpleSAMLphp = self.callPackage ./simple-saml-php { }; + UserMerge = self.callPackage ./user-merge { }; +}) diff --git a/packages/mediawiki-extensions/delete-batch/default.nix b/packages/mediawiki-extensions/delete-batch/default.nix new file mode 100644 index 0000000..dc7de57 --- /dev/null +++ b/packages/mediawiki-extensions/delete-batch/default.nix @@ -0,0 +1,7 @@ +{ fetchzip }: + +fetchzip { + name = "mediawiki-delete-batch"; + url = "https://extdist.wmflabs.org/dist/extensions/DeleteBatch-REL1_41-5774fdd.tar.gz"; + hash = "sha256-ROkn93lf0mNXBvij9X2pMhd8LXZ0azOz7ZRaqZvhh8k="; +} diff --git a/packages/mediawiki-extensions/pluggable-auth/default.nix b/packages/mediawiki-extensions/pluggable-auth/default.nix new file mode 100644 index 0000000..58b793e --- /dev/null +++ b/packages/mediawiki-extensions/pluggable-auth/default.nix @@ -0,0 +1,7 @@ +{ fetchzip }: + +fetchzip { + name = "mediawiki-pluggable-auth-source"; + url = "https://extdist.wmflabs.org/dist/extensions/PluggableAuth-REL1_41-d5b3ad8.tar.gz"; + hash = "sha256-OLlkKeSlfNgWXWwDdINrYRZpYuSGRwzZHgU8EYW6rYU="; +} diff --git a/packages/mediawiki-extensions/simple-saml-php/default.nix b/packages/mediawiki-extensions/simple-saml-php/default.nix new file mode 100644 index 0000000..59ef5fa --- /dev/null +++ b/packages/mediawiki-extensions/simple-saml-php/default.nix @@ -0,0 +1,7 @@ +{ fetchzip }: + +fetchzip { + name = "mediawiki-simple-saml-php-source"; + url = "https://extdist.wmflabs.org/dist/extensions/SimpleSAMLphp-REL1_41-9ae0678.tar.gz"; + hash = "sha256-AmCaG5QXMJvi3N6zFyWylwYDt8GvyIk/0GFpM1Y0vkY="; +} diff --git a/packages/mediawiki-extensions/update-mediawiki-extensions.py b/packages/mediawiki-extensions/update-mediawiki-extensions.py new file mode 100755 index 0000000..099b18d --- /dev/null +++ b/packages/mediawiki-extensions/update-mediawiki-extensions.py @@ -0,0 +1,66 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i python3 -p "python3.withPackages(ps: with ps; [ beautifulsoup4 requests ])" + +import os +from pathlib import Path +import re +import subprocess +from collections import defaultdict +from pprint import pprint + +import bs4 +import requests + +BASE_URL = "https://extdist.wmflabs.org/dist/extensions" + +def fetch_plugin_list(skip_master=True) -> dict[str, list[str]]: + content = requests.get(BASE_URL).text + soup = bs4.BeautifulSoup(content, features="html.parser") + result = defaultdict(list) + for a in soup.find_all('a'): + if skip_master and 'master' in a.text: + continue + split = a.text.split('-') + result[split[0]].append(a.text) + return result + +def update(package_file: Path, plugin_list: dict[str, list[str]]) -> None: + assert package_file.is_file() + with open(package_file) as file: + content = file.read() + + tarball = re.search(f'url = "{BASE_URL}/(.+\.tar\.gz)";', content).group(1) + split = tarball.split('-') + updated_tarball = plugin_list[split[0]][-1] + + _hash = re.search(f'hash = "(.+?)";', content).group(1) + + out, err = subprocess.Popen( + ["nix-prefetch-url", "--unpack", "--type", "sha256", f"{BASE_URL}/{updated_tarball}"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ).communicate() + out, err = subprocess.Popen( + ["nix", "hash", "to-sri", "--type", "sha256", out.decode().strip()], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ).communicate() + + updated_hash = out.decode().strip() + + if tarball == updated_tarball and _hash == updated_hash: + return + + print(f"Updating: {tarball} ({_hash[7:14]}) -> {updated_tarball} ({updated_hash[7:14]})") + + updated_text = re.sub(f'url = "{BASE_URL}/.+?\.tar\.gz";', f'url = "{BASE_URL}/{updated_tarball}";', content) + updated_text = re.sub('hash = ".+";', f'hash = "{updated_hash}";', updated_text) + with open(package_file, 'w') as file: + file.write(updated_text) + +if __name__ == "__main__": + plugin_list = fetch_plugin_list() + + for direntry in os.scandir(Path(__file__).parent): + if direntry.is_dir(): + update(Path(direntry) / "default.nix", plugin_list) diff --git a/packages/mediawiki-extensions/user-merge/default.nix b/packages/mediawiki-extensions/user-merge/default.nix new file mode 100644 index 0000000..d918297 --- /dev/null +++ b/packages/mediawiki-extensions/user-merge/default.nix @@ -0,0 +1,7 @@ +{ fetchzip }: + +fetchzip { + name = "mediawiki-user-merge-source"; + url = "https://extdist.wmflabs.org/dist/extensions/UserMerge-REL1_41-a53af3b.tar.gz"; + hash = "sha256-TxUkEqMW79thYl1la2r+w9laRnd3uSYYg1xDB+1he1g="; +}