Skip to content

Commit 3b05dcd

Browse files
committed
Migrating pre-commit-hooks from LB
1 parent 1a1bba5 commit 3b05dcd

File tree

9 files changed

+116
-7
lines changed

9 files changed

+116
-7
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake .#default

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ cabal.project.local
2828
cabal.project.local~
2929
.HTF/
3030
.ghc.environment.*
31+
.direnv/

examples/build.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ _:
55
{
66
imports =
77
[
8+
./pre-commit.nix
89
./haskell-flake-project/build.nix
910
./rust-flake-project/build.nix
1011
./typescript-flake-project/build.nix

examples/pre-commit.nix

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{ inputs, config, ... }: {
2+
imports = [
3+
inputs.pre-commit-hooks.flakeModule
4+
config.flake-lang.rustMonorepoPreCommit
5+
config.flake-lang.denoPreCommit
6+
];
7+
perSystem = _: {
8+
pre-commit.settings = {
9+
hooks = {
10+
rust-monorepo.enable = true;
11+
my-deno.enable = true;
12+
};
13+
};
14+
};
15+
}

flake-lang/build.nix

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# Note(jaredponn):
2-
1+
# NOTE(jaredponn):
32
# Loosely, the key idea is that in this flake we want to have an attribute like
43
# ```
54
# lib.<system> = {
@@ -10,7 +9,7 @@
109
# };
1110
# ```
1211
# This is unfortunately not super easy to do with flake-parts! Some useful
13-
# links + examples are as follows.
12+
# links + examples are as follows.
1413
# - [1] https://github.com/hercules-ci/flake-parts/blob/main/lib.nix
1514
# - [2] https://github.com/hercules-ci/flake-parts/pull/63/files
1615
# - [3] https://github.com/hercules-ci/flake-parts/blob/main/modules/formatter.nix
@@ -79,8 +78,23 @@
7978
default = import ./typescript/flake-typescript.nix pkgs;
8079
readOnly = true;
8180
description = lib.mdDoc builtins.readFile ./typescript/description.md;
82-
# TODO(jaredponn): add an example
83-
# example = lib.mdDoc '' '';
81+
example = lib.mdDoc ''TODO(jaredponn)'';
82+
};
83+
84+
rustMonorepoPreCommit = lib.mkOption {
85+
type = lib.types.flakeModule;
86+
default = ./pre-commit-hooks/rust-monorepo.nix;
87+
readOnly = true;
88+
description = lib.mdDoc ''pre-commit-hooks.nix hook for Rust in a monorepo setting'';
89+
example = lib.mdDoc ''TODO(bladyjoker)'';
90+
};
91+
92+
denoPreCommit = lib.mkOption {
93+
type = lib.types.flakeModule;
94+
default = ./pre-commit-hooks/deno.nix;
95+
readOnly = true;
96+
description = lib.mdDoc ''pre-commit-hooks.nix hook for Deno in a monorepo setting'';
97+
example = lib.mdDoc ''TODO(bladyjoker)'';
8498
};
8599

86100
};

flake-lang/pre-commit-hooks/deno.nix

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{ inputs, ... }: {
2+
imports = [
3+
inputs.pre-commit-hooks.flakeModule # Adds perSystem.pre-commit options
4+
./tools.nix
5+
];
6+
perSystem = { config, ... }:
7+
{
8+
pre-commit.settings.hooks = {
9+
# TODO(jaredponn): Why do we use our strange version of `denofmt` and
10+
# `denolint`? The default implemented version in `pre-commit-hooks.nix`
11+
# is a bit buggy (see
12+
# https://github.com/cachix/pre-commit-hooks.nix/issues/374), and the
13+
# latest version of `deno` on nix doesn't allow explicitly applying
14+
# the formatter to specific files
15+
my-denofmt =
16+
{
17+
name = "denofmt";
18+
description = "Format Typescript code.";
19+
entry = "${config.flake-lang.pre-commit-hooks.tools.deno}/bin/deno fmt";
20+
files = "(\\.m?ts$)|(^tsconfig?(-base)\\.json$)";
21+
};
22+
23+
my-denolint =
24+
{
25+
name = "denolint";
26+
description = "Lint Typescript code.";
27+
entry = "${config.flake-lang.pre-commit-hooks.tools.deno}/bin/deno lint";
28+
files = "\\.m?ts$";
29+
};
30+
31+
};
32+
};
33+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{ inputs, ... }: {
2+
imports = [
3+
inputs.pre-commit-hooks.flakeModule # Adds perSystem.pre-commit options
4+
./tools.nix
5+
];
6+
perSystem = { config, ... }:
7+
{
8+
pre-commit.settings.hooks = {
9+
rustfmt-monorepo =
10+
{
11+
name = "rustfmt";
12+
description = "Format Rust code.";
13+
entry = "${config.flake-lang.pre-commit-hooks.tools.rustfmt}/bin/rustfmt --color always";
14+
files = "\\.rs$";
15+
};
16+
17+
};
18+
};
19+
}

flake-lang/pre-commit-hooks/tools.nix

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{ flake-parts-lib, lib, ... }: {
2+
perSystem = flake-parts-lib.mkPerSystemOption ({ pkgs, pkgsForRust, ... }: {
3+
options = {
4+
flake-lang.pre-commit-hooks.tools = {
5+
6+
rustfmt = lib.mkOption {
7+
type = lib.types.derivation;
8+
default = pkgsForRust.rustfmt;
9+
readOnly = false;
10+
description = lib.mdDoc ''Rust formatter to use for pre-commit hooks'';
11+
};
12+
13+
deno = lib.mkOption {
14+
type = lib.types.derivation;
15+
default = pkgs.deno;
16+
readOnly = false;
17+
description = lib.mdDoc ''Deno tool to use for pre-commit hooks'';
18+
};
19+
20+
};
21+
};
22+
});
23+
}

pre-commit.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{ inputs, ... }: {
2-
imports = [ inputs.pre-commit-hooks.flakeModule ];
2+
imports = [
3+
inputs.pre-commit-hooks.flakeModule
4+
];
35
perSystem = { config, ... }: {
4-
devShells.dev-pre-commit = config.pre-commit.devShell;
6+
devShells.default = config.pre-commit.devShell;
57
pre-commit.settings = {
68
hooks = {
79
# Typos

0 commit comments

Comments
 (0)