Skip to content

Commit cc143d8

Browse files
committed
Added nix
1 parent 67aef1f commit cc143d8

18 files changed

+1131
-0
lines changed

.stylish-haskell.yaml

Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
# Stylish-haskell configuration file used for the network layer
2+
# It's based on default config provided by `stylish-haskell --defaults` but
3+
# has some changes ==================================
4+
5+
# The stylish-haskell tool is mainly configured by specifying steps. These steps
6+
# are a list, so they have an order, and one specific step may appear more than
7+
# once (if needed). Each file is processed by these steps in the given order.
8+
steps:
9+
# Convert some ASCII sequences to their Unicode equivalents. This is disabled
10+
# by default.
11+
# - unicode_syntax:
12+
# # In order to make this work, we also need to insert the UnicodeSyntax
13+
# # language pragma. If this flag is set to true, we insert it when it's
14+
# # not already present. You may want to disable it if you configure
15+
# # language extensions using some other method than pragmas. Default:
16+
# # true.
17+
# add_language_pragma: true
18+
- module_header:
19+
# # How many spaces use for indentation in the module header.
20+
indent: 2
21+
#
22+
# # Should export lists be sorted? Sorting is only performed within the
23+
# # export section, as delineated by Haddock comments.
24+
sort: false
25+
#
26+
# # See `separate_lists` for the `imports` step.
27+
separate_lists: true
28+
#
29+
# # When to break the "where".
30+
# # Possible values:
31+
# # - exports: only break when there is an explicit export list.
32+
# # - single: only break when the export list counts more than one export.
33+
# # - inline: only break when the export list is too long. This is
34+
# # determined by the `columns` setting. Not applicable when the export
35+
# # list contains comments as newlines will be required.
36+
# # - always: always break before the "where".
37+
break_where: single
38+
# # Where to put open bracket
39+
# # Possible values:
40+
# # - same_line: put open bracket on the same line as the module name, before the
41+
# # comment of the module
42+
# # - next_line: put open bracket on the next line, after module comment
43+
open_bracket: next_line
44+
45+
# Align the right hand side of some elements. This is quite conservative
46+
# and only applies to statements where each element occupies a single
47+
# line.
48+
- simple_align:
49+
cases: true
50+
top_level_patterns: true
51+
records: true
52+
53+
# Import cleanup
54+
- imports:
55+
# There are different ways we can align names and lists.
56+
#
57+
# - global: Align the import names and import list throughout the entire
58+
# file.
59+
#
60+
# - file: Like global, but don't add padding when there are no qualified
61+
# imports in the file.
62+
#
63+
# - group: Only align the imports per group (a group is formed by adjacent
64+
# import lines).
65+
#
66+
# - none: Do not perform any alignment.
67+
#
68+
# Default: global.
69+
align: global
70+
71+
# The following options affect only import list alignment.
72+
#
73+
# List align has following options:
74+
#
75+
# - after_alias: Import list is aligned with end of import including
76+
# 'as' and 'hiding' keywords.
77+
#
78+
# > import qualified Data.List as List (concat, foldl, foldr, head,
79+
# > init, last, length)
80+
#
81+
# - with_alias: Import list is aligned with start of alias or hiding.
82+
#
83+
# > import qualified Data.List as List (concat, foldl, foldr, head,
84+
# > init, last, length)
85+
#
86+
# - new_line: Import list starts always on new line.
87+
#
88+
# > import qualified Data.List as List
89+
# > (concat, foldl, foldr, head, init, last, length)
90+
#
91+
# Default: after_alias
92+
list_align: with_module_name
93+
94+
# Right-pad the module names to align imports in a group:
95+
#
96+
# - true: a little more readable
97+
#
98+
# > import qualified Data.List as List (concat, foldl, foldr,
99+
# > init, last, length)
100+
# > import qualified Data.List.Extra as List (concat, foldl, foldr,
101+
# > init, last, length)
102+
#
103+
# - false: diff-safe
104+
#
105+
# > import qualified Data.List as List (concat, foldl, foldr, init,
106+
# > last, length)
107+
# > import qualified Data.List.Extra as List (concat, foldl, foldr,
108+
# > init, last, length)
109+
#
110+
# Default: true
111+
112+
# Note: we intentionally disable it to make diffs less verbose and avoid
113+
# merge conflicts in some cases.
114+
pad_module_names: false
115+
116+
# Long list align style takes effect when import is too long. This is
117+
# determined by 'columns' setting.
118+
#
119+
# - inline: This option will put as much specs on same line as possible.
120+
#
121+
# - new_line: Import list will start on new line.
122+
#
123+
# - new_line_multiline: Import list will start on new line when it's
124+
# short enough to fit to single line. Otherwise it'll be multiline.
125+
#
126+
# - multiline: One line per import list entry.
127+
# Type with constructor list acts like single import.
128+
#
129+
# > import qualified Data.Map as M
130+
# > ( empty
131+
# > , singleton
132+
# > , ...
133+
# > , delete
134+
# > )
135+
#
136+
# Default: inline
137+
long_list_align: inline
138+
139+
# Align empty list (importing instances)
140+
#
141+
# Empty list align has following options
142+
#
143+
# - inherit: inherit list_align setting
144+
#
145+
# - right_after: () is right after the module name:
146+
#
147+
# > import Vector.Instances ()
148+
#
149+
# Default: inherit
150+
empty_list_align: inherit
151+
152+
# List padding determines indentation of import list on lines after import.
153+
# This option affects 'long_list_align'.
154+
#
155+
# - <integer>: constant value
156+
#
157+
# - module_name: align under start of module name.
158+
# Useful for 'file' and 'group' align settings.
159+
list_padding: 4
160+
161+
# Separate lists option affects formatting of import list for type
162+
# or class. The only difference is single space between type and list
163+
# of constructors, selectors and class functions.
164+
#
165+
# - true: There is single space between Foldable type and list of it's
166+
# functions.
167+
#
168+
# > import Data.Foldable (Foldable (fold, foldl, foldMap))
169+
#
170+
# - false: There is no space between Foldable type and list of it's
171+
# functions.
172+
#
173+
# > import Data.Foldable (Foldable(fold, foldl, foldMap))
174+
#
175+
# Default: true
176+
separate_lists: true
177+
178+
# Space surround option affects formatting of import lists on a single
179+
# line. The only difference is single space after the initial
180+
# parenthesis and a single space before the terminal parenthesis.
181+
#
182+
# - true: There is single space associated with the enclosing
183+
# parenthesis.
184+
#
185+
# > import Data.Foo ( foo )
186+
#
187+
# - false: There is no space associated with the enclosing parenthesis
188+
#
189+
# > import Data.Foo (foo)
190+
#
191+
# Default: false
192+
space_surround: false
193+
194+
# Language pragmas
195+
- language_pragmas:
196+
# We can generate different styles of language pragma lists.
197+
#
198+
# - vertical: Vertical-spaced language pragmas, one per line.
199+
#
200+
# - compact: A more compact style.
201+
#
202+
# - compact_line: Similar to compact, but wrap each line with
203+
# `{-#LANGUAGE #-}'.
204+
#
205+
# Default: vertical.
206+
style: vertical
207+
208+
# stylish-haskell can detect redundancy of some language pragmas. If this
209+
# is set to true, it will remove those redundant pragmas. Default: true.
210+
remove_redundant: true
211+
212+
# Replace tabs by spaces. This is disabled by default.
213+
# - tabs:
214+
# # Number of spaces to use for each tab. Default: 8, as specified by the
215+
# # Haskell report.
216+
# spaces: 8
217+
218+
# Remove trailing whitespace
219+
- trailing_whitespace: {}
220+
221+
# A common setting is the number of columns (parts of) code will be wrapped
222+
# to. Different steps take this into account. Default: 80.
223+
columns: 80
224+
225+
# By default, line endings are converted according to the OS. You can override
226+
# preferred format here.
227+
#
228+
# - native: Native newline format. CRLF on Windows, LF on other OSes.
229+
#
230+
# - lf: Convert to LF ("\n").
231+
#
232+
# - crlf: Convert to CRLF ("\r\n").
233+
#
234+
# Default: native.
235+
newline: native
236+
237+
# These syntax-affecting language extensions are enabled so that
238+
# stylish-haskell wouldn't fail with parsing errors when processing files
239+
# in projects that have those extensions enabled in the .cabal file
240+
# rather than locally.
241+
#
242+
# To my best knowledge, no harm should result from enabling an extension
243+
# that isn't actually used in the file/project. —@neongreen
244+
language_extensions:
245+
- BangPatterns
246+
- ConstraintKinds
247+
- DataKinds
248+
- DefaultSignatures
249+
- DeriveDataTypeable
250+
- DeriveGeneric
251+
- ExistentialQuantification
252+
- FlexibleContexts
253+
- FlexibleInstances
254+
- FunctionalDependencies
255+
- GADTs
256+
- GeneralizedNewtypeDeriving
257+
- LambdaCase
258+
- MultiParamTypeClasses
259+
- MultiWayIf
260+
- NoImplicitPrelude
261+
- OverloadedStrings
262+
- PolyKinds
263+
- RecordWildCards
264+
- ScopedTypeVariables
265+
- StandaloneDeriving
266+
- TemplateHaskell
267+
- TupleSections
268+
- TypeApplications
269+
- TypeFamilies
270+
- ViewPatterns
271+
- ExplicitNamespaces
272+

default.nix

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{ system ? builtins.currentSystem, crossSystem ? null
2+
# allows to cutomize haskellNix (profiling, see ./nix/io-sim.nix)
3+
, config ? { }
4+
# allows to override dependencies of the project without modifications,
5+
# eg. to test build against local checkout of nixpkgs and iohk-nix:
6+
# nix build -f default.nix cardano-ledger-byron --arg sourcesOverride '{
7+
# iohk-nix = ../iohk-nix;
8+
# }'
9+
, sourcesOverride ? { }
10+
# pinned version of nixpkgs augmented with overlays (iohk-nix and our packages).
11+
, pkgs ? import ./nix { inherit system crossSystem config sourcesOverride; }
12+
, gitrev ? pkgs.iohkNix.commitIdFromGitRepoOrZero ./.git }:
13+
with pkgs;
14+
with commonLib;
15+
let
16+
haskellPackages = recRecurseIntoAttrs
17+
# the Haskell.nix package set, reduced to local packages.
18+
(selectProjectPackages ioSimHaskellPackages);
19+
20+
validate-mainnet = import ./nix/validate-mainnet.nix {
21+
inherit pkgs;
22+
byron-db-converter =
23+
haskellPackages.ouroboros-consensus-byron.components.exes.db-converter;
24+
db-analyser =
25+
haskellPackages.ouroboros-consensus-cardano.components.exes.db-analyser;
26+
onlyImmutableDB = false;
27+
};
28+
29+
self = {
30+
inherit haskellPackages;
31+
32+
inherit (haskellPackages.io-sim.identifier) version;
33+
34+
# `tests` are the test suites which have been built.
35+
tests = collectComponents' "tests" haskellPackages;
36+
# `benchmarks` (only built, not run).
37+
benchmarks = collectComponents' "benchmarks" haskellPackages;
38+
39+
libs = collectComponents' "library" haskellPackages;
40+
41+
exes = collectComponents' "exes" haskellPackages;
42+
43+
checks = recurseIntoAttrs {
44+
# `checks.tests` collect results of executing the tests:
45+
tests = collectChecks' haskellPackages;
46+
styles = recurseIntoAttrs {
47+
check-nixfmt = callPackage ./nix/check-nixfmt.nix { };
48+
check-stylish = callPackage ./nix/check-stylish.nix { };
49+
};
50+
};
51+
52+
# These are not run on hydra, but will be built separately in a nightly
53+
# build job.
54+
nightly-checks = {
55+
inherit validate-mainnet;
56+
gnuparallel = pkgs.parallel;
57+
glibcLocales = pkgs.glibcLocales;
58+
59+
Cardano =
60+
haskellPackages.ouroboros-consensus-cardano-test.components.tests.test;
61+
Shelley =
62+
haskellPackages.ouroboros-consensus-shelley-test.components.tests.test;
63+
};
64+
65+
shell = import ./shell.nix {
66+
inherit pkgs;
67+
withHoogle = true;
68+
};
69+
};
70+
in self

nix/check-nixfmt.nix

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{ runCommand, fd, nixfmt }:
2+
3+
runCommand "check-nixfmt" {
4+
buildInputs = [ fd nixfmt ];
5+
src = ./..;
6+
} ''
7+
unpackPhase
8+
cd $sourceRoot
9+
fd -e nix -X nixfmt -c
10+
echo $? >> $out
11+
''

nix/check-stylish.nix

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{ runCommand, fd, lib, stylish-haskell }:
2+
3+
runCommand "check-stylish" {
4+
meta.platforms = with lib.platforms; [ linux ];
5+
buildInputs = [ fd stylish-haskell ];
6+
src = ./..;
7+
} ''
8+
unpackPhase
9+
cd $sourceRoot
10+
fd . './io-sim' -e hs -E Setup.hs -X stylish-haskell -c .stylish-haskell.yaml -i
11+
fd . './io-classes' -e hs -E Setup.hs -X stylish-haskell -c .stylish-haskell.yaml -i
12+
fd . './strict-stm' -e hs -E Setup.hs -X stylish-haskell -c .stylish-haskell.yaml -i
13+
diff -ru $src .
14+
15+
EXIT_CODE=$?
16+
if [[ $EXIT_CODE != 0 ]]
17+
then
18+
diff -ru $src .
19+
echo "*** Stylish-haskell found changes that need addressed first"
20+
exit $EXIT_CODE
21+
else
22+
echo $EXIT_CODE > $out
23+
fi
24+
''

0 commit comments

Comments
 (0)