Skip to content

Commit

Permalink
Switch from treefmt to pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Nov 19, 2024
1 parent d8c7e63 commit c718a95
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 52 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ result
result-*

# direnv
.direnv
.direnv

/.pre-commit-config.yaml
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Get a Haskell development environment up and running quickly. Thanks to Nix, thi

- [Nix](https://srid.ca/haskell-nix) + [Flakes](https://serokell.io/blog/practical-nix-flakes) (via [`github:srid/haskell-flake`](https://github.com/srid/haskell-flake)) + GHC 9.6
- VSCode + [HLS](https://github.com/haskell/haskell-language-server)
- [fourmolu](https://github.com/fourmolu/fourmolu) autoformatting
- [fourmolu](https://github.com/fourmolu/fourmolu) autoformatting
- [Relude](https://github.com/kowainik/relude) as Prelude.
- `.hlint.yaml` is [from relude](https://github.com/kowainik/relude/blob/main/.hlint.yaml)
- Devshell commands are provided via [just](https://just.systems/); run `just` in devshell.
Expand All @@ -30,13 +30,16 @@ Recommended dev environment setup: https://nixos.asia/en/direnv

- Run `nix flake update` to update all flake inputs.
- Run `nix --accept-flake-config run github:juspay/omnix ci` to build _all_ outputs.
- Run `just fmt` in nix shell to autoformat the project. This uses [treefmt](https://github.com/numtide/treefmt).
- Run `just fmt` in nix shell to autoformat the project. This uses [pre-commit].
- Run `just docs` to start Hoogle with packages in your cabal file.
- Run the application without installing: `nix run github:srid/haskell-template` (or `nix run .` from checkout)

- Common workflows
- Adding library dependencies in Nix: https://community.flake.parts/haskell-flake/dependency
- Adding tests: https://srid.ca/haskell-template/tests

## Discussions

Questions? Ideas? Suggestions? Join our [NixOS Zulip](https://nixos.zulipchat.com/#narrow/stream/413949-haskell-flake) or post in [Github Discussions](https://github.com/srid/haskell-template/discussions).

[pre-commit]: https://github.com/cachix/git-hooks.nix
40 changes: 18 additions & 22 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
nixos-unified.url = "github:srid/nixos-unified";
haskell-flake.url = "github:srid/haskell-flake";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
fourmolu-nix.url = "github:jedimahdi/fourmolu-nix";

git-hooks.url = "github:cachix/git-hooks.nix";
git-hooks.flake = false;
};

outputs = inputs:
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repl *ARGS:

# Autoformat the project tree
fmt:
treefmt
pre-commit run --all-files

# Run ghcid -- auto-recompile and run `main` function
run:
Expand Down
2 changes: 1 addition & 1 deletion nix/modules/flake-parts/devshell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# See https://community.flake.parts/haskell-flake/devshell#composing-devshells
inputsFrom = [
config.haskellProjects.default.outputs.devShell # See ./nix/modules/haskell.nix
config.treefmt.build.devShell # See ./nix/modules/formatter.nix
config.pre-commit.devShell # See ./nix/modules/formatter.nix
];
packages = with pkgs; [
just
Expand Down
34 changes: 11 additions & 23 deletions nix/modules/flake-parts/formatter.nix
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
{ inputs, ... }:
{
imports = [
inputs.treefmt-nix.flakeModule
(inputs.git-hooks + /flake-module.nix)
inputs.fourmolu-nix.flakeModule
];
perSystem = { config, pkgs, ... }: {
# Auto formatters. This also adds a flake check to ensure that the
# source tree was auto formatted.
treefmt.config = {
projectRootFile = "flake.nix";

settings.global.excludes = [
".*"
"*.sql" # https://github.com/numtide/treefmt-nix/issues/257
"*.md"
"hie.yaml"
"LICENSE"
];

programs.just.enable = true;
settings.formatter.just.includes = [ "justfile" ];
programs.fourmolu = {
enable = true;
package = config.fourmolu.wrapper;
perSystem = { config, ... }: {
pre-commit.settings = {
hooks = {
nixpkgs-fmt.enable = true;
cabal-fmt.enable = true;
fourmolu = {
enable = true;
package = config.fourmolu.wrapper;
};
hlint.enable = true;
};
programs.nixpkgs-fmt.enable = true;
programs.cabal-fmt.enable = true;
programs.hlint.enable = true;
};

fourmolu.settings = {
Expand Down

0 comments on commit c718a95

Please sign in to comment.