diff --git a/flake.nix b/flake.nix index fc0ebdf..4ec5cc5 100644 --- a/flake.nix +++ b/flake.nix @@ -59,6 +59,7 @@ inherit system; overlays = [ inputs.pvv-calendar-bot.overlays.${system}.default + self.overlays.default ]; }; } @@ -121,6 +122,10 @@ default = nixpkgs.legacyPackages.${system}.callPackage ./shell.nix { }; }); + overlays.default = (final: prev: { + mediawiki-extensions = final.callPackage ./packages/mediawiki-extensions { }; + }); + packages = { "x86_64-linux" = let pkgs = nixpkgs.legacyPackages."x86_64-linux"; @@ -130,6 +135,7 @@ (nixlib.getAttrs importantMachines self.packages.x86_64-linux); all-machines = pkgs.linkFarm "all-machines" (nixlib.getAttrs allMachines self.packages.x86_64-linux); + 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 ee75199..7ed32c7 100644 --- a/hosts/bekkalokk/services/mediawiki.nix +++ b/hosts/bekkalokk/services/mediawiki.nix @@ -1,4 +1,4 @@ -{ pkgs, lib, config, values, pkgs-unstable, ... }: let +{ pkgs, lib, config, values, ... }: let cfg = config.services.mediawiki; # "mediawiki" @@ -60,30 +60,11 @@ in { }; extensions = { - DeleteBatch = pkgs.fetchzip { - name = "mediawiki-delete-batch-source"; - url = "https://extdist.wmflabs.org/dist/extensions/DeleteBatch-REL1_40-4fe36dc.tar.gz"; - hash = "sha256-jmRkjHFQR9cjPr1eBHVDLHm0xO4OPn9HYiYwrkBT/aA="; - }; - UserMerge = pkgs.fetchzip { - name = "mediawiki-user-merge-source"; - url = "https://extdist.wmflabs.org/dist/extensions/UserMerge-REL1_40-7407806.tar.gz"; - hash = "sha256-NHAw79pDxjia46J5DIGV9AoF9UazSahT8DZgUUn/pQE="; - }; - PluggableAuth = pkgs.fetchzip { - name = "mediawiki-pluggable-auth-source"; - url = "https://extdist.wmflabs.org/dist/extensions/PluggableAuth-REL1_40-eb10a76.tar.gz"; - hash = "sha256-GFmtQc0SeBpvI+7iHOVw77JR2h+hwPxo8+wZ9RED8a8="; - }; - SimpleSAMLphp = pkgs.fetchzip { - name = "mediawiki-simple-saml-php-source"; - url = "https://extdist.wmflabs.org/dist/extensions/SimpleSAMLphp-REL1_40-8043943.tar.gz"; - hash = "sha256-HJHcrv/FNqPJegrHo4VPVjw0alkyHwetFZiLwjHsf6Y="; - }; + inherit (pkgs.mediawiki-extensions) DeleteBatch UserMerge PluggableAuth SimpleSAMLphp; }; extraConfig = let - SimpleSAMLphpRepo = pkgs-unstable.php.buildComposerProject rec { + SimpleSAMLphpRepo = pkgs.php.buildComposerProject rec { pname = "configuredSimpleSAML"; version = "2.1.0-rc1"; src = pkgs.fetchFromGitHub { 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="; +}