Skip to content

Commit 7dfcdb4

Browse files
authored
treewide: add developer shell and pre-commit hooks and improve workflows (#519)
Add developer shells with direnv integration and the deadnix, hlint, nixfmt-rfc-style, statix, stylish-haskell, typos, and yamllint pre-commit hooks. Ensure 'nix flake check' works as expected and add the nix-flake-check package, which is a parallelized alternative to 'nix flake check'. Improve and update the GitHub workflows. Closes: #236 Link: #519 Approved-by: Daniel Thwaites <[email protected]>
2 parents 7c8874b + ad64260 commit 7dfcdb4

File tree

124 files changed

+3415
-2550
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+3415
-2550
lines changed

.envrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.github/workflows/backport.yml

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,44 @@
1-
# Derived from https://github.com/NixOS/nixpkgs/blob/2ab6f6d61630889491f86396b27a76ffb6fbc7bb/.github/workflows/backport.yml
2-
1+
---
2+
# Derived from
3+
# https://github.com/NixOS/nixpkgs/blob/2ab6f6d61630889491f86396b27a76ffb6fbc7bb/.github/workflows/backport.yml
34
name: Backport
45

5-
on:
6+
on: # yamllint disable-line rule:truthy
67
pull_request_target:
78
types: [closed, labeled]
89

910
permissions: {}
1011

1112
jobs:
1213
backport:
13-
name: Backport
1414
runs-on: ubuntu-latest
1515

1616
if: >
1717
(
1818
github.repository_owner == 'danth' &&
1919
github.event.pull_request.merged == true &&
20-
(github.event_name != 'labeled' || startsWith('backport', github.event.label.name))
20+
(
21+
github.event_name != 'labeled' ||
22+
startsWith('backport', github.event.label.name)
23+
)
2124
)
2225
2326
steps:
2427
# Use a GitHub App rather than the default token so that GitHub Actions
2528
# workflows may run on the created pull request.
26-
- name: Create GitHub access token
27-
uses: actions/create-github-app-token@v1
29+
- uses: actions/create-github-app-token@v1
2830
id: app-token
2931
with:
3032
app-id: ${{ vars.BACKPORT_APP_ID }}
3133
private-key: ${{ secrets.BACKPORT_PRIVATE_KEY }}
3234

33-
- name: Checkout original pull request
34-
uses: actions/checkout@v4
35+
- uses: actions/checkout@v4
3536
with:
3637
ref: ${{ github.event.pull_request.head.sha }}
3738
token: ${{ steps.app-token.outputs.token }}
3839

39-
- name: Create backport pull request
40-
uses: korthout/backport-action@v3
40+
- uses: korthout/backport-action@v3
4141
with:
4242
github_token: ${{ steps.app-token.outputs.token }}
4343
pull_title: "[${target_branch}] ${pull_title}"
44-
pull_description: |-
45-
This is an automated backport of #${pull_number}.
44+
pull_description: "This is an automated backport of #${pull_number}."

.github/workflows/build.yml

-61
This file was deleted.

.github/workflows/check.yml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
name: Check
3+
4+
on: # yamllint disable-line rule:truthy
5+
push:
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
get-derivations:
12+
runs-on: ubuntu-24.04
13+
14+
steps:
15+
- uses: DeterminateSystems/nix-installer-action@v16
16+
- uses: DeterminateSystems/magic-nix-cache-action@v8
17+
18+
- id: get-derivations
19+
run: |
20+
nix flake show --json \
21+
github:${{
22+
github.repository
23+
}}/${{
24+
github.event.pull_request.head.sha || github.sha
25+
}} |
26+
jq --raw-output '
27+
def format_output($arch; $type):
28+
{
29+
arch: $arch,
30+
key: .,
31+
32+
os: (
33+
if $arch == "x86_64-linux" then
34+
"ubuntu-24.04"
35+
else
36+
"macos-14"
37+
end
38+
),
39+
40+
type: $type
41+
};
42+
43+
[
44+
["x86_64-linux", "x86_64-darwin"][] as $arch |
45+
(.checks[$arch] | keys) as $checks |
46+
(.packages[$arch] | keys) as $packages |
47+
(($checks - $packages)[] | format_output($arch; "checks")),
48+
($packages[] | format_output($arch; "packages"))
49+
] |
50+
"derivations=\(.)"
51+
' >> $GITHUB_OUTPUT
52+
53+
outputs:
54+
derivations: ${{ steps.get-derivations.outputs.derivations }}
55+
56+
check:
57+
runs-on: ${{ matrix.check.os }}
58+
59+
name: ${{ matrix.check.key }} on ${{ matrix.check.arch }}
60+
needs: get-derivations
61+
62+
strategy:
63+
fail-fast: false
64+
matrix:
65+
check: ${{ fromJSON(needs.get-derivations.outputs.derivations) }}
66+
67+
steps:
68+
- uses: DeterminateSystems/nix-installer-action@v16
69+
- uses: DeterminateSystems/magic-nix-cache-action@v8
70+
71+
- run: |
72+
nix build --no-update-lock-file --print-build-logs \
73+
github:${{
74+
github.repository
75+
}}/${{
76+
github.event.pull_request.head.sha || github.sha
77+
}}#${{
78+
matrix.check.type
79+
}}.${{
80+
matrix.check.arch
81+
}}.${{
82+
matrix.check.key
83+
}}

.github/workflows/docs.yml

+19-40
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,36 @@
1+
---
12
name: Docs
23

3-
on:
4+
on: # yamllint disable-line rule:truthy
45
push:
56
branches:
67
- master
78

9+
concurrency:
10+
cancel-in-progress: true
11+
group: pages
12+
813
jobs:
9-
build:
10-
name: Build
14+
docs:
15+
runs-on: ubuntu-24.04
1116

1217
permissions:
1318
contents: read
14-
15-
runs-on: ubuntu-latest
16-
17-
steps:
18-
- name: Install Nix
19-
uses: DeterminateSystems/nix-installer-action@main
20-
with:
21-
github-token: ${{ secrets.GITHUB_TOKEN }}
22-
extra-conf: |
23-
extra-experimental-features = nix-command flakes
24-
25-
- name: Set up cache
26-
uses: DeterminateSystems/magic-nix-cache-action@main
27-
28-
- name: Build docs
29-
run: nix -L build github:${{ github.repository }}/${{ github.sha }}#docs
30-
31-
- name: Prepare docs for upload
32-
run: cp -r --dereference --no-preserve=mode,ownership result/ public/
33-
34-
- name: Upload artifact
35-
uses: actions/upload-pages-artifact@v3
36-
with:
37-
path: public/
38-
39-
deploy:
40-
name: Deploy
41-
42-
needs: build
43-
44-
permissions:
45-
pages: write
4619
id-token: write
20+
pages: write
4721

4822
environment:
4923
name: github-pages
5024
url: ${{ steps.deployment.outputs.page_url }}
5125

52-
runs-on: ubuntu-latest
53-
5426
steps:
55-
- name: Deploy docs to GitHub Pages
56-
id: deployment
57-
uses: actions/deploy-pages@v4
27+
- uses: actions/checkout@v4
28+
- uses: DeterminateSystems/nix-installer-action@v16
29+
- uses: DeterminateSystems/magic-nix-cache-action@v8
30+
- run: nix build .#docs
31+
32+
- uses: actions/upload-pages-artifact@v3
33+
with:
34+
path: result
35+
36+
- uses: actions/deploy-pages@v4

.github/workflows/lint.yml

-42
This file was deleted.

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
/.direnv/
2+
/.pre-commit-config.yaml
13
result
24
result-*

default.nix

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
(import (let lock = builtins.fromJSON (builtins.readFile ./flake.lock);
2-
in fetchTarball {
3-
url =
4-
"https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
5-
sha256 = lock.nodes.flake-compat.locked.narHash;
6-
}) { src = ./.; }).defaultNix
1+
(import (
2+
let
3+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
4+
in
5+
fetchTarball {
6+
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
7+
sha256 = lock.nodes.flake-compat.locked.narHash;
8+
}
9+
) { src = ./.; }).defaultNix

0 commit comments

Comments
 (0)