numtide / treefmt-nix

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

Overriding Terraform package is incompatible with terraform-with-plugins #27

Open srounce opened 1 year ago

srounce commented 1 year ago

Describe the bug

When setting programs.terraform.package to the result of terraform-with-plugins the terraform binary cannot be found:

Failed to load formatter #terraform due to error: cannot find binary path

To Reproduce

Steps to reproduce the behaviour:

  1. Given the following expression:
    let 
    tf = nixpkgs.terraform.withPlugins (p: [
    p.null
    ]);
    in
    {
    formatter.x86_64-linux = sources.treefmt-nix.lib.mkWrapper
    nixpkgs
    {
      programs.terraform = {
        enable = true;
        package = tf;
      };
    };
    }

Expected behavior

Treefmt should find the Terraform binary.

System information

OS: Nixos unstable (5efc8ca954272c4376ac929f4c5ffefcc20551d5)

Versions:

Additional context

@zimbatm diagnosed this issue as being due to the pname of the terraform-with-plugins result not being "terraform". Currently settings.formatter.terraform.command = lib.mkForce "${tf}/bin/terraform"; is a valid workaround.

zowoq commented 1 year ago

Adding pname to the wrapper in https://github.com/NixOS/nixpkgs/pull/224005.

zimbatm commented 1 year ago

The best way to fix this is to either 1) move the -with-plugins annotation to the version (eg: terraform-1.2.3+with-plugins) 2) or set meta.mainProgram = "terraform" on the terraform package

Or both

zowoq commented 1 year ago

Sorry, I don't understand why we would need to do either of those, does setting the wrapper pname to terraform not work?

Rechecked, I can reproduce the failure from the example and it works once pname is set.