Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dprint is inconsistent #278

Open
phanirithvij opened this issue Dec 11, 2024 · 9 comments
Open

dprint is inconsistent #278

phanirithvij opened this issue Dec 11, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@phanirithvij
Copy link

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 0ce9d14, via flake, nixpkgs-unstable.

@phanirithvij phanirithvij added the bug Something isn't working label Dec 11, 2024
@phanirithvij
Copy link
Author

phanirithvij commented Dec 29, 2024

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.

@zimbatm
Copy link
Member

zimbatm commented Dec 30, 2024

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.

@phanirithvij
Copy link
Author

phanirithvij commented Dec 30, 2024

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

@zimbatm
Copy link
Member

zimbatm commented Dec 30, 2024

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.

@phanirithvij
Copy link
Author

alright, I will try it out

@zimbatm
Copy link
Member

zimbatm commented Dec 30, 2024

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.

@phanirithvij
Copy link
Author

okay.

@phanirithvij
Copy link
Author

phanirithvij commented Dec 30, 2024

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants