1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 runCommand,
6 inflow,
7 diffutils,
8}:
9
10stdenv.mkDerivation rec {
11 pname = "inflow";
12 version = "1.0.1";
13
14 src = fetchFromGitHub {
15 owner = "stephen-huan";
16 repo = "inflow";
17 rev = "v${version}";
18 hash = "sha256-xKUqkrPwITai8g6U1NiNieAip/AzISgFfFtvR30hLNk=";
19 };
20
21 buildPhase = ''
22 runHook preBuild
23
24 $CXX -Wall -Wpedantic -Wextra -O3 -o inflow inflow.cpp
25
26 runHook postBuild
27 '';
28
29 installPhase = ''
30 runHook preInstall
31
32 install -Dm755 inflow -t $out/bin
33
34 runHook postInstall
35 '';
36
37 passthru.tests = {
38 reflowWithLineLength =
39 runCommand "${pname}-test"
40 {
41 nativeBuildInputs = [ inflow ];
42 buildInputs = [ diffutils ];
43 }
44 ''
45 cat <<EOF > input.txt
46 xxxxx xxx xxx xxxx xxxxxxxxx xx x xxxxxxxxx x xxxx xxxx xxxxxxx xxxxxxxx xxx
47 xxxxxxxxx xxxxxxxx xx xx xxxxx xxxxx xxxx xx x xxxx xx xxxxxxxx xxxxxxxx xxxx
48 xxx xxxx xxxx xxx xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxx xxx xxxxx xx xxxx x xxxx
49 xxxxxxxx xxxx xxxx xx xxxxx xxxx xxxxx xxxx xxxxxxxxx xxx xxxxxxxxxxx xxxxxx
50 xxx xxxxxxxxx xxxx xxxx xx x xx xxxx xxx xxxx xx xxx xxx xxxxxxxxxxx xxxx xxxxx
51 x xxxxx xxxxxxx xxxxxxx xx xx xxxxxx xx xxxxx
52 EOF
53
54 inflow 72 < input.txt > actual.txt
55
56 cat <<EOF > expected.txt
57 xxxxx xxx xxx xxxx xxxxxxxxx xx x xxxxxxxxx x xxxx xxxx xxxxxxx
58 xxxxxxxx xxx xxxxxxxxx xxxxxxxx xx xx xxxxx xxxxx xxxx xx x xxxx
59 xx xxxxxxxx xxxxxxxx xxxx xxx xxxx xxxx xxx xxxxxxxxxxxxxxxxxxx
60 xxxxxxxxxxxxx xxx xxxxx xx xxxx x xxxx xxxxxxxx xxxx xxxx xx xxxxx
61 xxxx xxxxx xxxx xxxxxxxxx xxx xxxxxxxxxxx xxxxxx xxx xxxxxxxxx
62 xxxx xxxx xx x xx xxxx xxx xxxx xx xxx xxx xxxxxxxxxxx xxxx xxxxx
63 x xxxxx xxxxxxx xxxxxxx xx xx xxxxxx xx xxxxx
64 EOF
65
66 if ! cmp --silent expected.txt actual.txt
67 then
68 echo "Error: actual.txt and expected.txt are different"
69 diff actual.txt expected.txt
70 exit 1
71 fi
72
73 touch $out
74 '';
75 };
76
77 meta = with lib; {
78 description = "Variance-optimal paragraph formatter";
79 homepage = "https://github.com/stephen-huan/inflow";
80 license = licenses.unlicense;
81 mainProgram = "inflow";
82 maintainers = with maintainers; [ fbrs ];
83 platforms = platforms.all;
84 };
85}