This commit is contained in:
Max Headroom 2021-03-17 21:01:27 +01:00
commit 933a1efc72
8 changed files with 188 additions and 0 deletions

24
.drone.yml Normal file
View file

@ -0,0 +1,24 @@
kind: pipeline
type: exec
name: Update extensions
platform:
os: linux
arch: amd64
steps:
- name: Update
commands:
- python3 update.py
- name: Commit changes
environment:
GIT_AUTHOR_NAME: Drone
GIT_AUTHOR_EMAIL: drone@bots.void
DRONE_DEPLOY_KEY:
from_secret: drone-deploy-key
commands:
- git add .
- git commit -m '[CI] Update extensions' || exit 0
- git remote add pushback https://drone:$DRONE_DEPLOY_KEY@git.privatevoid.net/max/nix-crx.git
- git push pushback master

1
README Normal file
View file

@ -0,0 +1 @@
Chromium extensions for use with Nix

38
extensions.json Normal file
View file

@ -0,0 +1,38 @@
[
{
"name": "bitwarden",
"id": "nngceckbapebfimnlniiiahkandclblb",
"updateMethod": "google"
},
{
"name": "ublock-origin",
"id": "cjpalhdlnbpafiamejdnhcphjbkeiagm",
"updateMethod": "google"
},
{
"name": "ipfs-companion",
"id": "nibjojkomfdiaoajekhjakgkdhaomnch",
"updateMethod": "google"
},
{
"name": "floccus-bookmark-sync",
"id": "fnaicdffflnofjppbagibeoednhnbjhg",
"updateMethod": "google"
},
{
"name": "h264ify",
"id": "aleakchihdccplidncghkekgioiakgal",
"updateMethod": "google"
},
{
"name": "i-dont-care-about-cookies",
"id": "fihnjjcciajhdojfnbdddfaoknhalnja",
"updateMethod": "google"
},
{
"name": "chromium-web-store",
"id": "ocaahdebbfolfmndjeplogmgcagdmblk",
"updateMethod": "github",
"updateUrl": "https://api.github.com/repos/NeverDecaf/chromium-web-store/releases"
}
]

19
extensions/crx.nix Normal file
View file

@ -0,0 +1,19 @@
{ stdenv, lib, fetchurl }: crxMeta:
let
extensions = lib.importJSON ./extensions-generated.json;
in
with crxMeta; stdenv.mkDerivation {
name = "${id}-${name}-${version}";
inherit version;
src = fetchurl { inherit url; inherit sha256; };
preferLocalBuild = true;
allowSubstitutes = false;
buildCommand = ''
mkdir -p "$out"
install -v -m644 "$src" "$out/${id}.crx"
'';
inherit id;
}

18
extensions/default.nix Normal file
View file

@ -0,0 +1,18 @@
pkgs: lib:
let
extensions = lib.importJSON ./extensions-generated.json;
enhance = ext: ext // {
crx = with ext; {
inherit id;
inherit version;
crxPath = "${outPath}/${id}.crx";
};
};
in
builtins.listToAttrs (map (crxMeta:
{
name = crxMeta.name;
value = enhance (pkgs.callPackage ./crx.nix {} crxMeta);
}
)
extensions)

27
flake.lock Normal file
View file

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1615797423,
"narHash": "sha256-5NGDZXPQzuoxf/42NiyC9YwwhwzfMfIRrz3aT0XHzSc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "266dc8c3d052f549826ba246d06787a219533b8f",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

15
flake.nix Normal file
View file

@ -0,0 +1,15 @@
{
description = "Chromium extensions as Nix derivations";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
in
{
packages.x86_64-linux = import ./extensions pkgs nixpkgs.lib;
};
}

46
update.py Executable file
View file

@ -0,0 +1,46 @@
#!/usr/bin/env nix-shell
#! nix-shell -i python -p python3
import json
import xml.etree.ElementTree as ET
import hashlib
from urllib.request import urlopen
from os.path import abspath, dirname
JSON_PATH = dirname(abspath(__file__)) + '/extensions.json'
JSON_OUT_PATH = dirname(abspath(__file__)) + '/extensions/extensions-generated.json'
with open(JSON_PATH, 'r') as f:
exts = json.load(f)
for ext in exts:
print(f"updating {ext['name']}")
if ext["updateMethod"] == "github":
with urlopen(ext["updateUrl"]) as r:
latest = json.load(r)[0]
ext["url"] = latest["assets"][0]["browser_download_url"]
with urlopen(ext["url"]) as blob:
sha256 = hashlib.new("SHA256")
if blob.status == 200:
size, n = 0, 16384
buf = bytearray(n)
while n != 0:
n = blob.readinto(buf)
size += n
if n>0:
sha256.update(buf[:n])
ext["sha256"] = sha256.hexdigest().lower()
ext["version"] = latest["tag_name"].lstrip("v")
elif ext["updateMethod"] == "google":
resp = urlopen(f"https://clients2.google.com/service/update2/crx?response=updatecheck&acceptformat=crx2,crx3&prodversion=89.0.0.0&x=id%3D{ext['id']}%26uc")
xml = resp.read()
xmltree = ET.fromstring(xml)
app = xmltree.find("{http://www.google.com/update2/response}app").find("{http://www.google.com/update2/response}updatecheck")
latest = app.attrib
ext["url"] = latest["codebase"]
ext["sha256"] = latest["hash_sha256"]
ext["version"] = latest["version"]
with open(JSON_OUT_PATH, 'w') as out:
json.dump(exts, out)