1{
2 lib,
3 fetchurl,
4 stdenv,
5 dprint,
6 writableTmpDirAsHomeHook,
7}:
8let
9 mkDprintPlugin =
10 {
11 url,
12 hash,
13 pname,
14 version,
15 description,
16 initConfig,
17 updateUrl,
18 license ? lib.licenses.mit,
19 maintainers ? [ lib.maintainers.phanirithvij ],
20 }:
21 stdenv.mkDerivation (finalAttrs: {
22 inherit pname version;
23 src = fetchurl { inherit url hash; };
24 dontUnpack = true;
25 meta = {
26 inherit description license maintainers;
27 };
28 /*
29 in the dprint configuration
30 dprint expects a plugin path to end with .wasm extension
31
32 for auto update with nixpkgs-update to work
33 we cannot have .wasm extension at the end in the nix store path
34 */
35 buildPhase = ''
36 mkdir -p $out
37 cp $src $out/plugin.wasm
38 '';
39 doInstallCheck = true;
40 nativeInstallCheckInputs = [
41 dprint
42 writableTmpDirAsHomeHook
43 ];
44 # Prevent schema unmatching errors
45 # See https://github.com/NixOS/nixpkgs/pull/369415#issuecomment-2566112144 for detail
46 installCheckPhase = ''
47 runHook preInstallCheck
48
49 mkdir empty && cd empty
50 dprint check --allow-no-files --config-discovery=false --plugins "$out/plugin.wasm"
51
52 runHook postInstallCheck
53 '';
54 passthru = {
55 updateScript = ./update-plugins.py;
56 inherit initConfig updateUrl;
57 };
58 });
59 inherit (lib)
60 filterAttrs
61 isDerivation
62 mapAttrs'
63 nameValuePair
64 removeSuffix
65 ;
66 files = filterAttrs (
67 name: type: type == "regular" && name != "default.nix" && lib.hasSuffix ".nix" name
68 ) (builtins.readDir ./.);
69 plugins = mapAttrs' (
70 name: _:
71 nameValuePair (removeSuffix ".nix" name) (import (./. + "/${name}") { inherit mkDprintPlugin; })
72 ) files;
73 # Expects a function that receives the dprint plugin set as an input
74 # and returns a list of plugins
75 # Example:
76 # pkgs.dprint-plugins.getPluginList (plugins: [
77 # plugins.dprint-plugin-toml
78 # (pkgs.callPackage ./dprint/plugins/sample.nix {})
79 # ]
80 getPluginList = cb: map (p: "${p}/plugin.wasm") (cb plugins);
81in
82plugins // { inherit mkDprintPlugin getPluginList; }