Skip to content

Commit f3803f2

Browse files
committed
Add pre-commit
1 parent 4b7f9dd commit f3803f2

File tree

4 files changed

+247
-61
lines changed

4 files changed

+247
-61
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ result*
1212

1313
# local files created by the cluster
1414
local-cluster-info.json
15+
16+
.pre-commit-config.yaml

flake.lock

Lines changed: 163 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 48 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@
3030
url = "github:edolstra/flake-compat";
3131
flake = false;
3232
};
33-
33+
flake-parts.url = "github:hercules-ci/flake-parts";
34+
pre-commit-hooks-nix.url = "github:cachix/pre-commit-hooks.nix";
3435
};
3536

3637
outputs =
37-
{ self, nixpkgs, haskell-nix, CHaP, iohk-nix, cardano-node, ... }:
38+
inputs@{ self, nixpkgs, haskell-nix, CHaP, iohk-nix, cardano-node, flake-parts, ... }:
3839
let
3940
defaultSystems = [ "x86_64-linux" "x86_64-darwin" ];
4041

@@ -130,64 +131,51 @@
130131

131132
modules = haskellModules system;
132133
};
134+
135+
project = perSystem projectFor;
136+
flake = perSystem (system: (projectFor system).flake { });
133137
in
134-
{
135-
project = perSystem projectFor;
136-
flake = perSystem (system: (projectFor system).flake { });
137-
138-
defaultPackage = perSystem (system:
139-
let lib = "plutip-core:lib:plutip-core";
140-
in self.flake.${system}.packages.${lib});
141-
142-
packages = perSystem (system: self.flake.${system}.packages);
143-
144-
apps = perSystem (system: self.flake.${system}.apps);
145-
146-
devShell = perSystem (system: self.flake.${system}.devShell);
147-
148-
# This will build all of the project's executables and the tests
149-
check = perSystem
150-
(system:
151-
(nixpkgsFor system).runCommand "combined-check"
152-
{
153-
nativeBuildInputs = builtins.attrValues self.checks.${system}
154-
++ builtins.attrValues self.flake.${system}.packages;
155-
} ''mkdir $out''
156-
);
157-
158-
checks = perSystem (system:
159-
self.flake.${system}.checks // {
160-
formatting = (nixpkgsFor system).runCommand "formatting-check"
161-
{
162-
nativeBuildInputs = [
163-
self.devShell.${system}.inputDerivation
164-
self.devShell.${system}.nativeBuildInputs
165-
];
166-
}
167-
''
168-
cd ${self}
169-
export LC_CTYPE=C.UTF-8
170-
export LC_ALL=C.UTF-8
171-
export LANG=C.UTF-8
172-
export IN_NIX_SHELL='pure'
173-
# this check is temporarily skipped in CI due to a bug in
174-
# fourmolu:
175-
#
176-
# ```
177-
# Formatting is not idempotent:
178-
# src/Plutip/Launch/Cluster.hs<rendered>:753:19
179-
# before: " sgs\n "
180-
# after: " sgs{ Ledger.s"
181-
# Please, consider reporting the bug.
182-
# ```
183-
# make format_check cabalfmt_check nixpkgsfmt_check lint
184-
mkdir $out
185-
'';
186-
});
187-
188-
haskellModules = perSystem haskellModules;
189-
190-
# Instruction for the Hercules CI to build on x86_64-linux only, to avoid errors about systems without agents.
191-
herculesCI.ciSystems = [ "x86_64-linux" ];
138+
flake-parts.lib.mkFlake { inherit inputs; } {
139+
imports = [
140+
./pre-commit.nix
141+
];
142+
flake = {
143+
inherit project flake;
144+
145+
# This will build all of the project's executables and the tests
146+
check = perSystem
147+
(system:
148+
(nixpkgsFor system).runCommand "combined-check"
149+
{
150+
nativeBuildInputs = builtins.attrValues self.checks.${system}
151+
++ builtins.attrValues self.flake.${system}.packages;
152+
} ''mkdir $out''
153+
);
154+
155+
haskellModules = perSystem haskellModules;
156+
157+
# Instruction for the Hercules CI to build on x86_64-linux only, to avoid errors about systems without agents.
158+
herculesCI.ciSystems = [ "x86_64-linux" ];
159+
};
160+
systems = defaultSystems;
161+
perSystem = { system, config, pkgs, ... }: {
162+
packages = flake.${system}.packages
163+
// {
164+
default = config.packages."plutip-core:lib:plutip-core";
165+
};
166+
167+
apps = flake.${system}.apps;
168+
169+
devShells = {
170+
# Adds pre-commit packages and shell hook to the haskell shell
171+
default = pkgs.mkShell {
172+
inputsFrom = [ config.devShells.haskell config.devShells.dev-pre-commit ];
173+
shellHook = config.devShells.haskell.shellHook + config.devShells.dev-pre-commit.shellHook;
174+
};
175+
haskell = flake.${system}.devShell;
176+
};
177+
178+
checks = flake.${system}.checks;
179+
};
192180
};
193181
}

pre-commit.nix

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{ inputs, ... }: {
2+
imports = [
3+
inputs.pre-commit-hooks-nix.flakeModule
4+
];
5+
perSystem = { pkgs, system, config, ... }:
6+
{
7+
devShells.dev-pre-commit = config.pre-commit.devShell;
8+
# devShells.default = config.pre-commit.devShell;
9+
10+
pre-commit = {
11+
settings = {
12+
excludes = [
13+
"cluster-data/"
14+
"src/Plutip/Launch/"
15+
];
16+
17+
hooks = {
18+
nixpkgs-fmt.enable = true;
19+
deadnix.enable = true;
20+
cabal-fmt.enable = true;
21+
fourmolu.enable = true;
22+
shellcheck.enable = true;
23+
hlint.enable = true;
24+
typos.enable = true;
25+
markdownlint.enable = true;
26+
};
27+
28+
settings = {
29+
ormolu.cabalDefaultExtensions = true;
30+
};
31+
};
32+
};
33+
};
34+
}

0 commit comments

Comments
 (0)