Obsidian Systems' shared Haskell code style, packaged as a Nix
flake that wraps fourmolu with a common
fourmolu.yaml.
Point any of our Haskell projects at this flake and they all format the same way, without each repo having to vendor and maintain its own copy of the config.
# Format in place, using the bundled Obsidian Systems config.
nix run github:obsidiansystems/style.hs -- --mode inplace src/
# Check formatting without writing (e.g. in CI).
nix run github:obsidiansystems/style.hs -- --mode check src/Everything after -- is forwarded straight to fourmolu, so any flag fourmolu
accepts works here too.
Reference the flake as an input and use the fourmolu package as your formatter,
for example in a dev shell:
{
inputs.style.url = "github:obsidiansystems/style.hs";
outputs = { self, nixpkgs, style, ... }:
let system = "x86_64-linux";
in {
devShells.${system}.default =
nixpkgs.legacyPackages.${system}.mkShell {
packages = [ style.packages.${system}.fourmolu ];
};
};
}Inside that shell, plain fourmolu already uses the Obsidian Systems style, with
no --config needed.
Add this repo as a submodule and symlink your project's fourmolu.yaml to the
vendored one. fourmolu discovers fourmolu.yaml from the project root
automatically, so editors, formatters, and CI all pick up the style with no
flags:
git submodule add https://github.com/obsidiansystems/style.hs style.hs
ln -s style.hs/fourmolu.yaml fourmolu.yamlPull in later changes to the shared style by updating the submodule:
git submodule update --remote style.hsfourmolu.yaml is both the config and a runnable
Nix shebang
script. Copy it into a project and run it directly to format files using itself as
the config:
./fourmolu.yaml --mode inplace src/This needs nix on PATH with flakes enabled.
The wrapper resolves which config to use as follows:
- No
--config: the bundledfourmolu.yaml(the default). --config <path>/--config=<path>: your own config file. Repeated--configflags collapse to the last one, since fourmolu itself rejects duplicates.--config -: read the config from stdin.
| File | Purpose |
|---|---|
fourmolu.yaml |
The shared style config; also a runnable Nix shebang script. |
fourmolu.nix |
Builds the fourmolu wrapper that bundles the config and handles --config. |
flake.nix |
Exposes the fourmolu (and default) package for every supported system. |
inputs.nix |
flake-compat shim so non-flake Nix can consume the inputs. |