mirror of
https://github.com/ilyakooo0/ormolu.git
synced 2024-10-27 03:28:33 +03:00
Add nix expression for reformatting sources of arbitrary packages
See the description in readme.
This commit is contained in:
parent
a444abc764
commit
7a9aab77b3
12
README.md
12
README.md
@ -64,6 +64,18 @@ formatted output.
|
|||||||
$ ormolu --mode inplace Module.hs
|
$ 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
|
## Contributing
|
||||||
|
|
||||||
See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
||||||
|
15
default.nix
15
default.nix
@ -1,18 +1,29 @@
|
|||||||
let
|
let
|
||||||
pkgs = import ./nix/nixpkgs;
|
pkgs = import ./nix/nixpkgs;
|
||||||
gitignoreSource = import ./nix/gitignore { inherit (pkgs) lib; };
|
|
||||||
compiler = "ghc864";
|
compiler = "ghc864";
|
||||||
source = gitignoreSource ./.;
|
source = pkgs.lib.sourceByRegex ./.[
|
||||||
|
"^.*\.md$"
|
||||||
|
"^app.*$"
|
||||||
|
"^data.*$"
|
||||||
|
"^ormolu.cabal$"
|
||||||
|
"^src.*$"
|
||||||
|
"^tests.*$"
|
||||||
|
];
|
||||||
haskellPackages = pkgs.haskell.packages.${compiler}.override {
|
haskellPackages = pkgs.haskell.packages.${compiler}.override {
|
||||||
overrides = (self: super:
|
overrides = (self: super:
|
||||||
super // {
|
super // {
|
||||||
"ormolu" = super.callCabal2nix "ormolu" source { };
|
"ormolu" = super.callCabal2nix "ormolu" source { };
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
ormolize = import ./nix/ormolize {
|
||||||
|
inherit pkgs;
|
||||||
|
inherit haskellPackages;
|
||||||
|
};
|
||||||
in {
|
in {
|
||||||
ormolu = haskellPackages.ormolu;
|
ormolu = haskellPackages.ormolu;
|
||||||
ormolu-shell = haskellPackages.shellFor {
|
ormolu-shell = haskellPackages.shellFor {
|
||||||
packages = ps: [ ps.ormolu ];
|
packages = ps: [ ps.ormolu ];
|
||||||
buildInputs = [ pkgs.cabal-install ];
|
buildInputs = [ pkgs.cabal-install ];
|
||||||
};
|
};
|
||||||
|
hackage = pkgs.lib.mapAttrs ormolize haskellPackages;
|
||||||
}
|
}
|
||||||
|
@ -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
19
nix/ormolize/default.nix
Normal 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
18
nix/ormolize/ormolize.sh
Executable 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"
|
Loading…
Reference in New Issue
Block a user