Skip to content

Commit

Permalink
config(*.nix): Configure pre-commit to be used in the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinNikov committed Dec 20, 2024
1 parent c77b04e commit 1b90df5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/reusable-lint-job.yml
Original file line number Diff line number Diff line change
@@ -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

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ matrix-*.json
shardMatrix.json

.vscode

# Pre Commit
.pre-commit-config.yaml
10 changes: 9 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,22 @@
system,
pkgs,
inputs',
self',
...
}:
{
_module.args.pkgs = import nixpkgs {
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 =
Expand Down
13 changes: 8 additions & 5 deletions shells/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
self',
pkgs,
flake,
inputs',
...
}:
Expand All @@ -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;
}

0 comments on commit 1b90df5

Please sign in to comment.