1
1
mirror of https://github.com/tweag/ormolu.git synced 2024-09-11 21:27:46 +03:00

Add nix expression for reformatting sources of arbitrary packages

See the description in readme.
This commit is contained in:
mrkkrp 2019-07-14 01:01:02 +02:00 committed by Mark Karpov
parent a444abc764
commit 7a9aab77b3
5 changed files with 62 additions and 10 deletions

View File

@ -64,6 +64,18 @@ formatted output.
$ ormolu --mode inplace Module.hs
```
## Running on Hackage
It's possible to try Ormolu on arbitrary packages from Hackage. For that
execute:
```console
$ nix-build -A hackage.<package>
```
Then inspect `result/log.txt` for possible problems. The derivation will
also contain formatted files for inspection.
## Contributing
See [CONTRIBUTING.md](./CONTRIBUTING.md).

View File

@ -1,18 +1,29 @@
let
pkgs = import ./nix/nixpkgs;
gitignoreSource = import ./nix/gitignore { inherit (pkgs) lib; };
compiler = "ghc864";
source = gitignoreSource ./.;
source = pkgs.lib.sourceByRegex ./.[
"^.*\.md$"
"^app.*$"
"^data.*$"
"^ormolu.cabal$"
"^src.*$"
"^tests.*$"
];
haskellPackages = pkgs.haskell.packages.${compiler}.override {
overrides = (self: super:
super // {
"ormolu" = super.callCabal2nix "ormolu" source { };
});
};
ormolize = import ./nix/ormolize {
inherit pkgs;
inherit haskellPackages;
};
in {
ormolu = haskellPackages.ormolu;
ormolu-shell = haskellPackages.shellFor {
packages = ps: [ ps.ormolu ];
buildInputs = [ pkgs.cabal-install ];
};
hackage = pkgs.lib.mapAttrs ormolize haskellPackages;
}

View File

@ -1,8 +0,0 @@
{ lib }:
let
rev = "ec5dd0536a5e4c3a99c797b86180f7261197c124";
sha256 = "0k2r8y21rn4kr5dmddd3906x0733fs3bb8hzfpabkdav3wcy3klv";
url = "https://github.com/hercules-ci/gitignore/archive/${rev}.tar.gz";
nixGitIgnore = builtins.fetchTarball { inherit url sha256; };
in (import nixGitIgnore { inherit lib; }).gitignoreSource

19
nix/ormolize/default.nix Normal file
View File

@ -0,0 +1,19 @@
{ pkgs, haskellPackages }: _: p:
pkgs.stdenv.mkDerivation {
name = p.name + "-ormolized";
src = p.src;
buildInputs = [
haskellPackages.cpphs
haskellPackages.ormolu
pkgs.glibcLocales
];
LANG = "en_US.UTF-8";
buildPhase = ''
find . -name '*.hs' -exec bash ${./ormolize.sh} {} \; 2> log.txt
'';
installPhase = ''
mkdir "$out"
find . -name '*.hs' -exec cp --parents {} $out \;
cp log.txt $out/log.txt
'';
}

18
nix/ormolize/ormolize.sh Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -euo pipefail
# drop includes
sed -i '/^#include/d' "$1"
# drop CPP
sed -i '/^{-# LANGUAGE CPP/d' "$1"
# deal with CPP in a fairly straightforward way
cpphs "$1" --noline > "$1-nocpp" 2> /dev/null
# annoyingly, cpphs cannot modify files in place
mv "$1-nocpp" "$1"
# run ormolu
ormolu -m inplace "$1"