dprint-plugins: getPluginList helper
Signed-off-by: phanirithvij <phanirithvij2000@gmail.com> Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>
This commit is contained in:
co-authored by
Jörg Thalheim
parent
52d6be7407
commit
0ae2e31243
@@ -1,4 +1,8 @@
|
||||
{ lib, fetchurl }:
|
||||
{
|
||||
lib,
|
||||
fetchurl,
|
||||
stdenv,
|
||||
}:
|
||||
let
|
||||
mkDprintPlugin =
|
||||
{
|
||||
@@ -12,28 +16,32 @@ let
|
||||
license ? lib.licenses.mit,
|
||||
maintainers ? [ lib.maintainers.phanirithvij ],
|
||||
}:
|
||||
fetchurl {
|
||||
inherit
|
||||
hash
|
||||
url
|
||||
pname
|
||||
version
|
||||
;
|
||||
name = "${pname}-${version}.wasm";
|
||||
stdenv.mkDerivation (finalAttrs: {
|
||||
inherit pname version;
|
||||
src = fetchurl { inherit url hash; };
|
||||
dontUnpack = true;
|
||||
meta = {
|
||||
inherit
|
||||
description
|
||||
license
|
||||
maintainers
|
||||
;
|
||||
inherit description license maintainers;
|
||||
};
|
||||
/*
|
||||
in the dprint configuration
|
||||
dprint expects a plugin path to end with .wasm extension
|
||||
|
||||
for auto update with nixpkgs-update to work
|
||||
we cannot have .wasm extension at the end in the nix store path
|
||||
*/
|
||||
buildPhase = ''
|
||||
mkdir -p $out
|
||||
cp $src $out/plugin.wasm
|
||||
'';
|
||||
passthru = {
|
||||
updateScript = ./update-plugins.py;
|
||||
inherit initConfig updateUrl;
|
||||
};
|
||||
};
|
||||
});
|
||||
inherit (lib)
|
||||
filterAttrs
|
||||
isDerivation
|
||||
mapAttrs'
|
||||
nameValuePair
|
||||
removeSuffix
|
||||
@@ -45,5 +53,13 @@ let
|
||||
name: _:
|
||||
nameValuePair (removeSuffix ".nix" name) (import (./. + "/${name}") { inherit mkDprintPlugin; })
|
||||
) files;
|
||||
# Expects a function that receives the dprint plugin set as an input
|
||||
# and returns a list of plugins
|
||||
# Example:
|
||||
# pkgs.dprint-plugins.getPluginList (plugins: [
|
||||
# plugins.dprint-plugin-toml
|
||||
# (pkgs.callPackage ./dprint/plugins/sample.nix {})
|
||||
# ]
|
||||
getPluginList = cb: map (p: "${p}/plugin.wasm") (cb plugins);
|
||||
in
|
||||
plugins // { inherit mkDprintPlugin; }
|
||||
plugins // { inherit mkDprintPlugin getPluginList; }
|
||||
|
||||
@@ -29,11 +29,9 @@ else:
|
||||
|
||||
|
||||
# get sri hash for a url, no unpack
|
||||
def nix_prefetch_url(url, name, algo="sha256"):
|
||||
def nix_prefetch_url(url, algo="sha256"):
|
||||
hash = (
|
||||
subprocess.check_output(
|
||||
["nix-prefetch-url", "--type", algo, "--name", name, url]
|
||||
)
|
||||
subprocess.check_output(["nix-prefetch-url", "--type", algo, url])
|
||||
.decode("utf-8")
|
||||
.rstrip()
|
||||
)
|
||||
@@ -119,7 +117,7 @@ def update_plugin_by_name(name):
|
||||
data = requests.get(p["updateUrl"]).json()
|
||||
p["url"] = data["url"]
|
||||
p["version"] = data["version"]
|
||||
p["hash"] = nix_prefetch_url(data["url"], f"{name}-{data["version"]}.wasm")
|
||||
p["hash"] = nix_prefetch_url(data["url"])
|
||||
|
||||
write_plugin_derivation(p)
|
||||
|
||||
@@ -136,7 +134,7 @@ def update_plugins():
|
||||
pname = pname.replace("/", "-")
|
||||
drv_attrs = {
|
||||
"url": e["url"],
|
||||
"hash": nix_prefetch_url(e["url"], f"{pname}-{e["version"]}.wasm"),
|
||||
"hash": nix_prefetch_url(e["url"]),
|
||||
"updateUrl": update_url,
|
||||
"pname": pname,
|
||||
"version": e["version"],
|
||||
|
||||
Reference in New Issue
Block a user