numtide / treefmt-nix

treefmt nix configuration
https://numtide.github.io/treefmt/
MIT License
270 stars 83 forks source link

dprint fails with "/nix/store/r4r6inyjds6ac9s3jjg398hi52v8i7ip-dprint/bin/dprint: line 3: exec: dprint: not found" #74

Closed KaiserKarel closed 1 year ago

KaiserKarel commented 1 year ago

Describe the bug

I added dprint to my flake.nix:

programs.dprint = {
            enable = true;
            config = {
              includes = [ "**/*.json" ];
              plugins = [
                "https://plugins.dprint.dev/json-0.17.2.wasm"
              ];
            };
          };

Calling nix fmt then fails with /nix/store/r4r6inyjds6ac9s3jjg398hi52v8i7ip-dprint/bin/dprint: line 3: exec: dprint: not found

System information

This is on aarch64-darwin, but also occurs on other architectures.

my flake.lock entry is:

"treefmt-nix": {
      "inputs": {
        "nixpkgs": [
          "nixpkgs"
        ]
      },
      "locked": {
        "lastModified": 1684244577,
        "narHash": "sha256-nnpCF/a5d0l68g/n4mAP+YUL+TxlYmmTK3HNzEy409Y=",
        "owner": "numtide",
        "repo": "treefmt-nix",
        "rev": "c1b28acff9d302b0924ee0d67c4a42d20eb11b28",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "treefmt-nix",
        "type": "github"
      }
    },

And my input is:

treefmt-nix = {
      url = "github:numtide/treefmt-nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
zimbatm commented 1 year ago

@gkze can you take a look since you introduced it in https://github.com/numtide/treefmt-nix/pull/73?

Something like this should fix it, but I don't have the environment to test it.

diff --git a/programs/dprint.nix b/programs/dprint.nix
index 0c64eec..54453b2 100644
--- a/programs/dprint.nix
+++ b/programs/dprint.nix
@@ -93,7 +93,7 @@ in
           configFile = mkConfigFile { config = cfg.config; };
           x = pkgs.writeShellScriptBin "dprint" ''
             set -euo pipefail
-            exec dprint --config=${configFile} "$@"
+            exec ${lib.getExe config.package} --config=${configFile} "$@"
           '';
         in
         (x // { meta = config.package.meta // x.meta; });
gkze commented 1 year ago

I got it working on my target repo with cfg.package (config.package is treefmt), not sure how else I could test it