Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .config/filegen-manifest.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions .github/workflows/check-pre-commit-hooks.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions .pre-commit-config.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ To use the standards in a new project, create the following
# Specify a default devshell for the project; other options are
# documented in the devshells section below.
#
# devShells.default = inputs'.famedly-engineering-standards.devShells.rust;
# devShells.default = inputs'.famedly-engineering-standards.devShells.standards;

famedly.standards = {
# Read module documentation for further details, but most
Expand All @@ -87,6 +87,7 @@ The following basic devshells are available:

| Name | Purpose |
| --------- | ------- |
| standards | Contains basic tools and configuration used by all famedly projects. |
| rust | Contains the Famedly Rust toolchain, and everything required to build Rust projects. |
| k8s | Contains miscellaneous k8s-related utilities, especially useful on MacOS. |

Expand Down Expand Up @@ -154,3 +155,35 @@ to ensure that most developers can interact with this repository.
If you struggle creating a completely new file, ask someone with more
nix experience to help you hook this into the filegen-activate
command.

### Adding pre-commit hooks

Pre-commit hooks are intended to be *very* fast to execute. These
should be ergonomic to run every time you create a git commit - when
doing rebase operations, that can mean dozens in a few 100ms.

As such, these should never contain expensive operations - compiling
code is absolutely not acceptable, and even complex parsing (for
formatting) may be pushing it.

For more expensive operations, add a workflow instead, and let CI
perform the check.

---

To actually add a pre-commit hook, in addition to defining the hook,
any dependencies required **must** be added to the `prek`
wrapper. Assuming the dependency is packaged in nixpkgs, this is quite
easy:

```nix
{
config.perSystem = { pkgs, ... }: {
prek-pre-commit.package.runtimePkgs = [ pkgs.foobar ];
};
}
```

More complex modifications to the `prek` wrapper are possible too,
refer to our [wrapper module provider](https://birdeehub.github.io/nix-wrapper-modules/modules/default.html)
for details.
23 changes: 22 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};

wrappers = {
url = "github:BirdeeHub/nix-wrapper-modules";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs =
Expand All @@ -37,7 +42,10 @@

flakeModules = rec {
filegen = ./nix/modules/filegen.nix;
prek-pre-commit = importApply ./nix/modules/prek-pre-commit.nix { inherit filegen; };
prek-pre-commit = importApply ./nix/modules/prek-pre-commit.nix {
inherit filegen;
inherit (inputs) wrappers;
};
};

default = importApply ./nix (args // { inherit importApply flakeModules; });
Expand Down
19 changes: 16 additions & 3 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,20 @@ importingFlake: {
];

# TODO: Break this out into a proper ecosystem-oriented module.
perSystem = { pkgs, lib, ... }: {
devshells.k8s.packages = lib.attrValues { inherit (pkgs) kubectl kubelogin-oidc kubetui; };
};
perSystem =
{
config,
pkgs,
lib,
...
}:
{
devshells.k8s = {
packages = lib.attrValues { inherit (pkgs) kubectl kubelogin-oidc kubetui; };

# TODO: Find a better way to inherit devshell
# configurations.
commands = lib.filter (command: command.name != "menu") config.devshells.standards.commands;
};
};
}
10 changes: 8 additions & 2 deletions nix/general/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
lib,
importApply,
...
}:
}@args:
importingFlake: {
imports = [ ./action-versions.nix ];
imports = [
./action-versions.nix
(importApply ./devshell.nix args)
(importApply ./pre-commit-hooks.nix args)

./workflows/check-pre-commit-hooks.nix
];

config.perSystem =
{ config, ... }:
Expand Down
29 changes: 29 additions & 0 deletions nix/general/devshell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
flakeModules,
inputs,
lib,
...
}:
importingFlake: {
config.perSystem = { config, ... }: {
devshells.standards = {
name = lib.mkDefault "engineering-standards";

commands = [
{
name = "prek";
help = "Run pre-commit hooks on currently staged changes";
category = "[[lints and checks]]";
package = config.prek-pre-commit.package.wrapper;
}

{
name = "prek -s main -o HEAD";
help = "Run pre-commit hooks on all commits in the current branch";
category = "[[lints and checks]]";
package = config.prek-pre-commit.package.wrapper;
}
];
};
};
}
Loading