-
Notifications
You must be signed in to change notification settings - Fork 38
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
add treefmt.withConfig #169
Conversation
.envrc
Outdated
@@ -0,0 +1,2 @@ | |||
export PRJ_ROOT=$PWD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting trick! Does direnv
always use project root (parent dir of .direnv
file) as PWD
even if you open the terminal directly in one of its sub directories?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is necessary so that relative paths in the .envrc
have the same result, even if the user jumps into a sub-folder directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DIRENV_DIR
already exists and can be queried if you use direnv, there may be no need to set PRJ_ROOT
then.
@zimbatm What do you think of exposing a |
Sounds good, the flake module probably can call treefmt.withConfig with its resulting schema at the end. |
Great; I'd be happy to test it out here: |
@srid ok this is ready if you want to give it a try |
@zimbatm Trying it out on haskell-template, diff --git a/flake.nix b/flake.nix
index 9918a57..684242e 100644
--- a/flake.nix
+++ b/flake.nix
@@ -5,22 +5,23 @@
flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs.follows = "nixpkgs";
haskell-flake.url = "github:srid/haskell-flake";
+ treefmt.url = "github:numtide/treefmt/withConfig";
+ treefmt.flake = false;
};
- outputs = { self, nixpkgs, flake-parts, haskell-flake, ... }:
+ outputs = inputs@{ self, nixpkgs, flake-parts, haskell-flake, treefmt, ... }:
flake-parts.lib.mkFlake { inherit self; } {
systems = nixpkgs.lib.systems.flakeExposed;
imports = [
haskell-flake.flakeModule
];
- perSystem = { self', pkgs, ... }: {
+ perSystem = { self', system, pkgs, ... }: {
haskellProjects.default = {
root = ./.;
buildTools = hp: {
- # TODO: Use https://github.com/numtide/treefmt/pull/169
inherit (pkgs)
- treefmt
nixpkgs-fmt;
+ treefmt = (import treefmt { inherit system; nixpkgs = pkgs; }).treefmt.withConfig (pkgs.lib.importTOML ./treefmt.toml);
inherit (hp)
cabal-fmt
fourmolu; I see:
I wanted to see how EDIT: I suppose we could add |
agreed. And since the absolute path to the project root would vary from machine to machine, I don't have a really good solution for it. Unless maybe the function also takes a command that points to the project root, like |
01b66aa
to
582c5aa
Compare
What if we had a wrapper script to determine the project root by traversing until a parent directory with a |
We can refine this idea to avoid the sub-flake assumption as follows: formatter = pkgs.treefmt.withConfig (nixpkgs.lib.importTOML ./treefmt.toml) { projectRootFile = "flake.nix" }; Basically, this tells the wrapper script to @zimbatm If we can get this feature merged, it would be useful in Platonic-Systems/treefmt-flake#1. Ultimately, I imagine that |
yeah, that makes sense. Do you have the time to finish this PR so it takes |
ok, I think this is ready now. Any last words/feedback? |
flake.nix
Outdated
@@ -20,6 +20,14 @@ | |||
|
|||
packages = pkgs; | |||
|
|||
# In Nix 2.8 you can run `nix fmt` to format this whole repo. Note that you need to have loaded the | |||
# `nix develop` shell before so the various formatters are available in the PATH. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's true only if the dependencies are not specified in nix. if the config has references to packages then it should work even outside of nix develop
I've tested it to work after applying #178 Looks good to merge. I'd only suggest making |
Rebased. It looks like flake.parts doesn't support the formatter option yet. I will give it another shot next week. |
574b533
to
19a0b32
Compare
Blocked on hercules-ci/flake-parts#56 |
56: add formatter schema r=roberth a=zimbatm This is needed for flakes that want to support `nix fmt`. Right now it's missing some testing as I didn't find a test framework for it. Needed by numtide/treefmt#169 Co-authored-by: zimbatm <[email protected]> Co-authored-by: Jonas Chevalier <[email protected]>
56: add formatter schema r=roberth a=zimbatm This is needed for flakes that want to support `nix fmt`. Right now it's missing some testing as I didn't find a test framework for it. Needed by numtide/treefmt#169 Co-authored-by: zimbatm <[email protected]> Co-authored-by: Jonas Chevalier <[email protected]>
4d960bc
to
1bac2bc
Compare
ok, I think this is ready |
f44778c
to
f11a866
Compare
Co-authored-by: Jörg Thalheim <[email protected]>
905fe05
to
de9885d
Compare
This is useful if you want to configure treefmt with nix, and precisely pass all the commands from nixpkgs. Co-authored-by: Sridhar Ratnakumar <[email protected]>
@zimbatm Will this ( |
I'm unsure about the policy regarding nix modules in the pkgs/ tree. Are there any precedents? |
I have seen |
that's not quite the same, plus it's using IFD :-D With @Mic92 we discussed moving this to another repo, so all the module systems could live separate from the code, and include pre-made samples for the various programs. |
Now live at https://github.com/numtide/treefmt-nix . Looking for feedback! |
Sure: numtide/treefmt-nix#2 |
This is useful if you want to configure treefmt with nix, and precisely
pass all the commands from nixpkgs.