Unverified Commit 4812f945 authored by Jörg Thalheim's avatar Jörg Thalheim Committed by GitHub
Browse files

dprint-plugins: getPluginList helper (#398815)

parents 5146e337 0ae2e312
Loading
Loading
Loading
Loading
+32 −16
Original line number Diff line number Diff line
{ 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; }
+4 −6
Original line number Diff line number Diff line
@@ -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"],