Fourmolu-nix
fourmolu-nix
makes a wrapper for fourmolu with settings already pass to it so
you no longer need fourmolu.yaml
or even to be in root of project to have
these options set for you.
Getting started
For creating the wrapper, you can use mkWrapper
function from lib which takes
pkgs and configuration and returns wrapped fourmolu with the provided configuration.
Flakes
# flake.nix
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
utils.url = "github:numtide/flake-utils";
fourmolu-nix.url = "github:jedimahdi/fourmolu-nix";
};
outputs = {
nixpkgs,
utils,
fourmolu-nix,
...
}:
utils.lib.eachDefaultSystem (
system: let
pkgs = nixpkgs.legacyPackages.${system};
fourmoluWrapper = fourmolu-nix.lib.mkWrapper pkgs {
settings = {
indentation = 4;
comma-style = "leading";
record-brace-space = true;
extensions = ["OverloadedRecordDot", "RecordWildCards"];
};
};
in {
devShells.default = pkgs.mkShell {
nativeBuildInputs = [
fourmoluWrapper
];
};
}
);
}
Flake-parts
With flake-parts you don't need to call mkWrapper
, just add
inputs.fourmolu-nix.flakeModule
to list of imports.
Fourmolu wrapper will be accessible via config.fourmolu.wrapper
.
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
fourmolu-nix.url = "github:jedimahdi/fourmolu-nix";
};
outputs = inputs:
inputs.flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
inputs.fourmolu-nix.flakeModule
];
systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"];
perSystem = {
config,
pkgs,
...
}: {
fourmolu.settings = {
indentation = 4;
import-export-style = "diff-friendly";
extensions = ["ImportQualifiedPost" "OverloadedRecordDot"];
};
devShells.default = pkgs.mkShell {
nativeBuildInputs = [
config.fourmolu.wrapper
];
};
};
};
}
Note: fourmolu-nix
will automatically set the wrapper package for treefmt-nix
fourmolu program.
Configuration
See options for the full list of configs.
fourmolu-nix
options
The following options can be set in a flake-parts configuration.
If you want to use lib, you don't need fourmolu.
part of options.
{
settings = {
indentaion = 4;
};
}
fourmolu.package
fourmolu derivation to use.
Type: package
Default:
pkgs.haskellPackages.fourmolu
fourmolu.devShell
A development shell with fourmolu installed.
Type: package (read only)
fourmolu.settings
fourmolu configuration
Type: submodule
Default:
{ }
fourmolu.settings.column-limit
Max line length for automatic line breaking
Type: value “none” (singular enum) or (positive integer, meaning >0)
Default:
"none"
Example:
80
fourmolu.settings.comma-style
How to place commas in multi-line lists, records, etc.
Type: one of “trailing”, “leading”
Default:
"leading"
fourmolu.settings.extensions
List of ghc extensions to pass to fourmolu
Type: list of string
Default:
[ ]
fourmolu.settings.function-arrows
Styling of arrows in type signatures
Type: one of “trailing”, “leading”, “leading-args”
Default:
"trailing"
Example:
"leading"
fourmolu.settings.haddock-style
How to print Haddock comments
Type: one of “single-line”, “multi-line”, “multi-line-compact”
Default:
"multi-line"
fourmolu.settings.haddock-style-module
How to print module docstring
Type: one of “single-line”, “multi-line”, “multi-line-compact”
Default:
"multi-line"
fourmolu.settings.import-export-style
Styling of import/export lists
Type: one of “trailing”, “leading”, “diff-friendly”
Default:
"diff-friendly"
Example:
"leading"
fourmolu.settings.in-style
How to align the ‘in’ keyword with respect to the ‘let’ keyword
Type: one of “right-align”, “left-align”, “no-space”
Default:
"right-align"
fourmolu.settings.indent-wheres
Whether to full-indent or half-indent ‘where’ bindings past the preceding body
Type: boolean
Default:
false
fourmolu.settings.indentation
Number of spaces per indentation step
Type: positive integer, meaning >0
Default:
2
Example:
4
fourmolu.settings.let-style
Styling of let blocks
Type: one of “auto”, “inline”, “newline”, “mixed”
Default:
"auto"
fourmolu.settings.newlines-between-decls
Number of spaces between top-level declarations
Type: positive integer, meaning >0
Default:
1
fourmolu.settings.options
Fourmolu options to pass to wrapped fourmolu
Type: list of string
Default:
[ ]
fourmolu.settings.record-brace-space
Whether to leave a space before an opening record brace
Type: boolean
Default:
false
fourmolu.settings.respectful
Give the programmer more choice on where to insert blank lines
Type: boolean
Default:
true
fourmolu.settings.single-constraint-parens
Whether to put parentheses around a single constraint
Type: one of “auto”, “always”, “never”
Default:
"always"
fourmolu.settings.unicode
Output Unicode syntax
Type: one of “detect”, “always”, “never”
Default:
"never"
fourmolu.wrapper
The fourmolu package, wrapped with the settings as arguments.
Type: package (read only)
Default:
wrapped fourmolu
command