Skip to content

Commit 7905b57

Browse files
committed
Code quality automation and Nix reshuffle
1 parent 4e768ee commit 7905b57

File tree

6 files changed

+134
-93
lines changed

6 files changed

+134
-93
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ result
55
.vscode/
66
*~
77
*#*
8+
.pre-commit-config.yaml

flake.lock

+45-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+49-77
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,72 @@
11
{
22
description = "cardano-open-oracle-protocol";
3+
nixConfig.bash-prompt =
4+
"\\[\\e[0m\\][\\[\\e[0;2m\\]nix-develop \\[\\e[0;1m\\]cardano-open-oracle-protocol \\[\\e[0;93m\\]\\w\\[\\e[0m\\]]\\[\\e[0m\\]$ \\[\\e[0m\\]";
35

46
inputs = {
5-
haskell-nix.url = "github:input-output-hk/haskell.nix";
7+
haskell-nix.url = "github:mlabs-haskell/haskell.nix";
68
nixpkgs.follows = "haskell-nix/nixpkgs-unstable";
7-
pre-commit-hooks = {
8-
url = "github:cachix/pre-commit-hooks.nix";
9-
inputs.flake-utils.follows = "flake-utils";
10-
};
119
flake-utils = {
1210
url = "github:numtide/flake-utils";
1311
inputs.nixpkgs.follows = "haskell-nix/nixpkgs-unstable";
1412
};
13+
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
14+
http2-grpc-native = {
15+
url = github:haskell-grpc-native/http2-grpc-haskell;
16+
flake = false;
17+
};
1518
};
1619

17-
outputs = inputs @ {
18-
self,
19-
nixpkgs,
20-
flake-utils,
21-
haskell-nix,
22-
...
23-
}:
24-
flake-utils.lib.eachSystem ["x86_64-linux" "x86_64-darwin"] (system: let
25-
extra-tools = [];
26-
20+
outputs =
21+
{ self
22+
, nixpkgs
23+
, flake-utils
24+
, haskell-nix
25+
, pre-commit-hooks
26+
, http2-grpc-native
27+
, ...
28+
}:
29+
flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" ] (system:
30+
let
31+
inherit self;# To appease nix-linter
2732
pkgs = import nixpkgs {
2833
inherit system;
29-
inherit (haskell-nix) config;
3034
};
3135
pkgsWithOverlay = import nixpkgs {
32-
inherit system overlays;
36+
inherit system;
3337
inherit (haskell-nix) config;
38+
overlays = [ haskell-nix.overlay ];
3439
};
35-
ghcVersion = "921";
36-
compiler-nix-name = "ghc" + ghcVersion;
3740

38-
hls =
39-
pkgs.haskell-language-server.override
40-
{
41-
supportedGhcVersions = [ghcVersion];
42-
};
43-
44-
pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
45-
src = ./.;
46-
settings = {
47-
ormolu.defaultExtensions = [
48-
"TypeApplications"
49-
"QualifiedDo"
50-
];
51-
};
52-
hooks = {
53-
alejandra.enable = true;
54-
cabal-fmt.enable = true;
55-
fourmolu.enable = true;
56-
};
41+
pre-commit-check = pre-commit-hooks.lib.${system}.run (import ./pre-commit-check.nix);
42+
pre-commit-devShell = pkgs.mkShell {
43+
inherit (pre-commit-check) shellHook;
5744
};
45+
ghcVersion = "8107";
46+
compiler-nix-name = "ghc" + ghcVersion;
5847

59-
overlays = [
60-
haskell-nix.overlay
61-
(final: prev: {
62-
cardano-open-oracle-protocol = final.haskell-nix.project' {
63-
inherit compiler-nix-name;
64-
src = ./pure-impl;
65-
shell = {
66-
buildInputs =
67-
[
68-
pkgs.nixpkgs-fmt
69-
pkgs.haskellPackages.cabal-fmt
70-
pkgs.haskellPackages.fourmolu
71-
hls
72-
]
73-
++ extra-tools;
74-
tools = {
75-
cabal = {};
76-
hlint = {};
77-
};
78-
crossPlatform = [];
79-
inherit (pre-commit-check) shellHook;
80-
};
81-
};
82-
})
83-
];
84-
85-
flake = pkgsWithOverlay.cardano-open-oracle-protocol.flake {crossPlatforms = p: [];};
86-
87-
package = flake.packages."cardano-open-oracle-protocol:exe:cardano-open-oracle-protocol";
88-
89-
# the nix code formatter for nix fmt
90-
formatter = pkgs.alejandra;
48+
pureImplProj = import ./pure-impl/pure-impl.nix {
49+
inherit pkgs compiler-nix-name;
50+
haskell-nix = pkgsWithOverlay.haskell-nix;
51+
};
52+
pureImplFlake = pureImplProj.flake { };
53+
protoProj = import ./proto/proto.nix {
54+
inherit pkgs compiler-nix-name http2-grpc-native;
55+
haskell-nix = pkgsWithOverlay.haskell-nix;
56+
};
57+
protoFlake = protoProj.flake { };
9158

92-
checks = {inherit pre-commit-check;};
9359
in
94-
flake
95-
// {
96-
defaultPackage = package;
97-
inherit formatter;
98-
inherit checks;
99-
});
60+
{
61+
62+
# Standard flake attributes
63+
packages = pureImplFlake.packages // protoFlake.packages;
64+
checks = pureImplFlake.checks // protoFlake.checks // pre-commit-check;
65+
devShells = rec {
66+
proto = protoFlake.devShell;
67+
pure-impl = pureImplFlake.devShell;
68+
pre-commit = pre-commit-devShell;
69+
default = proto;
70+
};
71+
});
10072
}

pre-commit-check.nix

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
src = ./.;
3+
settings = {
4+
ormolu.cabalDefaultExtensions = true;
5+
};
6+
7+
hooks = {
8+
nixpkgs-fmt.enable = true;
9+
nix-linter.enable = true;
10+
cabal-fmt.enable = true;
11+
fourmolu.enable = true;
12+
shellcheck.enable = true;
13+
hlint.enable = true;
14+
#FIXME hunspell.enable = true;
15+
#FIXME markdownlint.enable = true;
16+
};
17+
18+
tools = { };
19+
}

pure-impl/app/OrcFax/MerkleTree.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE TypeApplications #-}
12
{-# OPTIONS_GHC -Wno-orphans #-}
23

34
module OrcFax.MerkleTree (proveIn, prop_proof_holds_for_id_in_tree, prop_proof_does_not_hold_for_id_not_in_tree, prop_in_oracle_tree, inLeaf, wrongData, wrongId, sampleOracle) where
@@ -155,7 +156,7 @@ instance Arbitrary IdAndOracleTree where
155156
instance Arbitrary IdNotInOracleTree where
156157
arbitrary = do
157158
oracleTree :: Tree OracleData <- arbitrary
158-
oracleId :: Id <- arbitrary `suchThat` (\e -> not $ e `elem` fmap i oracleTree)
159+
oracleId :: Id <- arbitrary `suchThat` (\e -> e `notElem` fmap i oracleTree)
159160
pure $ MkIdNotInOracleTree (oracleId, oracleTree)
160161

161162
prop_proof_holds_for_id_in_tree :: IdAndOracleTree -> Property

pure-impl/pure-impl.nix

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{ pkgs, haskell-nix, compiler-nix-name }:
2+
haskell-nix.project' {
3+
inherit compiler-nix-name;
4+
src = ./.;
5+
shell = {
6+
buildInputs =
7+
[
8+
pkgs.nixpkgs-fmt
9+
pkgs.haskellPackages.cabal-fmt
10+
pkgs.haskellPackages.fourmolu
11+
];
12+
tools = {
13+
cabal = { };
14+
hlint = { };
15+
# haskell-language-server = {};
16+
};
17+
};
18+
}

0 commit comments

Comments
 (0)