From 1b90df56358165df5ba8e389177d1ac1fe8aea21 Mon Sep 17 00:00:00 2001 From: Martin Nikov Date: Fri, 20 Dec 2024 17:30:43 +0200 Subject: [PATCH] config(*.nix): Configure pre-commit to be used in the repo --- .github/workflows/reusable-lint-job.yml | 48 +++++++++++++++++++++++++ .gitignore | 3 ++ flake.nix | 10 +++++- shells/default.nix | 13 ++++--- 4 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/reusable-lint-job.yml diff --git a/.github/workflows/reusable-lint-job.yml b/.github/workflows/reusable-lint-job.yml new file mode 100644 index 00000000..1ce155ef --- /dev/null +++ b/.github/workflows/reusable-lint-job.yml @@ -0,0 +1,48 @@ +name: "Lint" + +on: + # Allow this workflow to be reused by other workflows: + workflow_call: + inputs: + runner: + description: 'JSON-encoded list of runner labels' + default: '["self-hosted"]' + required: false + type: string + + secrets: + NIX_GITHUB_TOKEN: + description: GitHub token to add as access-token in nix.conf + required: false + CACHIX_AUTH_TOKEN: + description: 'Cachix auth token' + required: true + +jobs: + lint: + runs-on: self-hosted + steps: + - uses: actions/checkout@v4 + + - name: Install Nix + uses: metacraft-labs/nixos-modules/.github/install-nix@main + with: + nix-github-token: ${{ secrets.NIX_GITHUB_TOKEN }} + cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }} + cachix-cache: ${{ vars.CACHIX_CACHE }} + trusted-public-keys: ${{ vars.TRUSTED_PUBLIC_KEYS }} + substituters: ${{ vars.SUBSTITUTERS }} + + - uses: cachix/cachix-action@v15 + with: + name: ${{ vars.CACHIX_CACHE }} + authToken: ${{ secrets.CACHIX_AUTH_TOKEN }} + + - name: Build & activate the Nix Dev Shell + run: | + eval "$(nix print-dev-env --accept-flake-config --accept-flake-config --impure .#devShells.x86_64-linux.default || echo exit 1)" + env >> "$GITHUB_ENV" + + - name: Check formatting + run: pre-commit run --all + diff --git a/.gitignore b/.gitignore index 6e10d488..038b447a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ matrix-*.json shardMatrix.json .vscode + +# Pre Commit +.pre-commit-config.yaml diff --git a/flake.nix b/flake.nix index 22b86a0d..e2ea203a 100644 --- a/flake.nix +++ b/flake.nix @@ -246,6 +246,7 @@ system, pkgs, inputs', + self', ... }: { @@ -253,7 +254,14 @@ inherit system; config.allowUnfree = true; }; - devShells.default = import ./shells/default.nix { inherit pkgs flake inputs'; }; + devShells.default = import ./shells/default.nix { + inherit + pkgs + flake + inputs' + self' + ; + }; devShells.ci = import ./shells/ci.nix { inherit pkgs; }; }; flake.lib.create = diff --git a/shells/default.nix b/shells/default.nix index 377e7308..eab06227 100644 --- a/shells/default.nix +++ b/shells/default.nix @@ -1,6 +1,6 @@ { + self', pkgs, - flake, inputs', ... }: @@ -27,10 +27,13 @@ pkgs.mkShell { inputs'.dlang-nix.packages.dmd inputs'.dlang-nix.packages.dub act + self'.checks.pre-commit-check.enabledPackages ]; - shellHook = '' - export REPO_ROOT="$PWD" - figlet -t "${flake.description}" - ''; + shellHook = + '' + export REPO_ROOT="$PWD" + figlet -t "Metacraft Nixos Modules" + '' + + self'.checks.pre-commit-check.shellHook; }