treefmt-nix icon indicating copy to clipboard operation
treefmt-nix copied to clipboard

dprint is inconsistent

Open phanirithvij opened this issue 11 months ago • 9 comments

Describe the bug

programs.dprint.enable = true;
programs.dprint.includes = [ "**/*.md" ];  # expected to work, fails
programs.dprint.settings.includes = [ "**/*.md" ];  # succeeds

programs.prettier.excludes = [ "*/vendor/*" ];  # succeeds

Expected behavior

Expect the settings API to be consistent.

System information

latest commit 0ce9d149d99bc383d1f2d85f31f6ebd146e46085, via flake, nixpkgs-unstable.

phanirithvij avatar Dec 11 '24 01:12 phanirithvij

Also a nix flake check with dprint, with plugins configured, is failing.

# treefmt.nix
_: {
  projectRootFile = "flake.nix";
  programs.dprint.enable = true;
  programs.dprint.settings = {
    includes = [ "**/*.toml" ];
    plugins = [ "https://plugins.dprint.dev/toml-0.6.3.wasm" ];
  };
}

nix flake check with a formatting check fails with

       > ERRO formatter | dprint: failed to apply with options '[fmt --config /nix/store/n5lir3h3ybd9ajzm131xf2zdhqwxgslh-dprint.json]': exit status 12
       >
       > Failed loading native certs. No such file or directory (os error 2)
       > Error resolving plugin https://plugins.dprint.dev/toml-0.6.3.wasm: Error downloading https://plugins.dprint.dev/toml-0.6.3.wasm - Error: https://plugins.dprint.dev/toml-0.6.3.wasm: Dns Failed: resolve dns name 'plugins.dprint.dev:443': failed to lookup address information: Temporary failure in name resolution
       >
$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.66, NixOS, 25.05 (Warbler), 25.05pre-git`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.24.11`
$ nix config show | grep sandbox
sandbox = true
sandbox-build-dir = /build
sandbox-dev-shm-size = 50%
sandbox-fallback = false

whereas a nix fmt or treefmt works.

phanirithvij avatar Dec 29 '24 08:12 phanirithvij

For the second issues, try replacing the "https://plugins.dprint.dev/toml-0.6.3.wasm" url with (pkgs.fetchurl { url = "https://plugins.dprint.dev/toml-0.6.3.wasm"; hash = "sha256-aDfo/sKfOeNpyfd/4N1LgL1bObTTnviYrA8T7M/1KNs="; }) value.

zimbatm avatar Dec 30 '24 09:12 zimbatm

Thanks, that is what I ended up doing. but I don't know how to keep them up-to-date.

I'm thinking it is best to define the plugins in dprint.json, so that it allows for easy auto updates, even if doing this is imperative.

or need to come up with a dprint.withPlugins interface in nixpkgs. which I don't know how

phanirithvij avatar Dec 30 '24 09:12 phanirithvij

The first thing to do is to assemble the package set somewhere. Probably in nixpkgs since it has all the update infrastructure. What you want is to get an attrset of pkgs.dprint-plugins.<name> to fetchurl calls. Once you have that, we can take a look at how to automate the updates with the ryantm updater bot and add them to treefmt-nix. You can find inspiration in the vimPlugins and terraform-providers.

zimbatm avatar Dec 30 '24 10:12 zimbatm

alright, I will try it out

phanirithvij avatar Dec 30 '24 10:12 phanirithvij

feel free to ping me on nixpkgs side if you send a PR.

for your first observation, this is a general problem with the current design of the modules. I will see what I can do.

zimbatm avatar Dec 30 '24 10:12 zimbatm

okay.

phanirithvij avatar Dec 30 '24 10:12 phanirithvij

with that pr this is working

    plugins = map toString (
      with pkgs.dprint-plugins; # or dprint.plugins
      [
        dprint-plugin-json
        dprint-plugin-markdown
        dprint-plugin-toml
        g-plane-pretty_yaml
      ]
    );

phanirithvij avatar Dec 30 '24 21:12 phanirithvij

okay,

programs.dprint.includes = [ "**/*.md" ];  # works
programs.dprint.settings.includes = [ "**/*.md" ];  # no longer works, it uses ".*" (set as default in dprint.nix)

you may close this issue @zimbatm if you think this is done.

Thank you for guiding me through the above nixpkgs pr as well as this treewide fix.

phanirithvij avatar Jan 04 '25 18:01 phanirithvij