Skip to content

Commit

Permalink
Add pre-commit infrastructure (#401)
Browse files Browse the repository at this point in the history
Does not include any hooks yet.
  • Loading branch information
aaronmondal committed Nov 17, 2023
1 parent db724c0 commit 8de3014
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Check pre-commit hooks
on:
pull_request:
branches:
- main
push:
branches:
- main

permissions: read-all

jobs:
pre-commit-checks:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: >- # v3.5.3
actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
- name: Install Nix
uses: >- #v7
DeterminateSystems/nix-installer-action@5620eb4af6b562c53e4d4628c0b6e4f9d9ae8612
- name: Cache Nix derivations
uses: >- # Custom commit, last pinned at 2023-11-17.
DeterminateSystems/magic-nix-cache-action@a04e6275a6bea232cd04fc6f3cbf20d4cb02a3e1
- name: Run pre-commit hooks
run: nix flake check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ __pycache__
.devenv/
.direnv/
.DS_Store
.pre-commit-config.yaml
127 changes: 126 additions & 1 deletion flake.lock

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

10 changes: 10 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
};

outputs = inputs@{ nixpkgs, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" ];
imports = [ inputs.pre-commit-hooks.flakeModule ];
perSystem = { config, self', inputs', pkgs, system, ... }:
let
# Link OpenSSL statically into the openssl-sys crate.
Expand All @@ -19,17 +21,25 @@
bazel = pkgs.bazel;
writeShellScriptBin = pkgs.writeShellScriptBin;
};

hooks = import ./tools/pre-commit-hooks.nix { inherit pkgs; };
in
{
pre-commit.settings = { inherit hooks; };
devShells.default = pkgs.mkShell {
nativeBuildInputs = [
# Development tooling goes here.
pkgs.cargo
pkgs.rustc
pkgs.pre-commit
openssl_static # Required explicitly for cargo test support.
bazel
];
shellHook = ''
# Generate the .pre-commit-config.yaml symlink when entering the
# development shell.
${config.pre-commit.installationScript}
# The Bazel and Cargo builds in nix require a Clang toolchain.
# TODO(aaronmondal): The Bazel build currently uses the
# irreproducible host C++ toolchain. Provide
Expand Down
4 changes: 4 additions & 0 deletions tools/pre-commit-hooks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{ pkgs, ... }:
{
# TODO(aaronmondal): Add hooks here.
}

0 comments on commit 8de3014

Please sign in to comment.