Skip to content

Commit

Permalink
treewide: add developer shell and pre-commit hooks and improve workfl…
Browse files Browse the repository at this point in the history
…ows (#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]>
  • Loading branch information
trueNAHO authored Jan 4, 2025
2 parents 7c8874b + ad64260 commit 7dfcdb4
Show file tree
Hide file tree
Showing 124 changed files with 3,415 additions and 2,550 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
25 changes: 12 additions & 13 deletions .github/workflows/backport.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
# Derived from https://github.com/NixOS/nixpkgs/blob/2ab6f6d61630889491f86396b27a76ffb6fbc7bb/.github/workflows/backport.yml

---
# Derived from
# https://github.com/NixOS/nixpkgs/blob/2ab6f6d61630889491f86396b27a76ffb6fbc7bb/.github/workflows/backport.yml
name: Backport

on:
on: # yamllint disable-line rule:truthy
pull_request_target:
types: [closed, labeled]

permissions: {}

jobs:
backport:
name: Backport
runs-on: ubuntu-latest

if: >
(
github.repository_owner == 'danth' &&
github.event.pull_request.merged == true &&
(github.event_name != 'labeled' || startsWith('backport', github.event.label.name))
(
github.event_name != 'labeled' ||
startsWith('backport', github.event.label.name)
)
)
steps:
# Use a GitHub App rather than the default token so that GitHub Actions
# workflows may run on the created pull request.
- name: Create GitHub access token
uses: actions/create-github-app-token@v1
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.BACKPORT_APP_ID }}
private-key: ${{ secrets.BACKPORT_PRIVATE_KEY }}

- name: Checkout original pull request
uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
token: ${{ steps.app-token.outputs.token }}

- name: Create backport pull request
uses: korthout/backport-action@v3
- uses: korthout/backport-action@v3
with:
github_token: ${{ steps.app-token.outputs.token }}
pull_title: "[${target_branch}] ${pull_title}"
pull_description: |-
This is an automated backport of #${pull_number}.
pull_description: "This is an automated backport of #${pull_number}."
61 changes: 0 additions & 61 deletions .github/workflows/build.yml

This file was deleted.

83 changes: 83 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
name: Check

on: # yamllint disable-line rule:truthy
push:

permissions:
contents: read

jobs:
get-derivations:
runs-on: ubuntu-24.04

steps:
- uses: DeterminateSystems/nix-installer-action@v16
- uses: DeterminateSystems/magic-nix-cache-action@v8

- id: get-derivations
run: |
nix flake show --json \
github:${{
github.repository
}}/${{
github.event.pull_request.head.sha || github.sha
}} |
jq --raw-output '
def format_output($arch; $type):
{
arch: $arch,
key: .,
os: (
if $arch == "x86_64-linux" then
"ubuntu-24.04"
else
"macos-14"
end
),
type: $type
};
[
["x86_64-linux", "x86_64-darwin"][] as $arch |
(.checks[$arch] | keys) as $checks |
(.packages[$arch] | keys) as $packages |
(($checks - $packages)[] | format_output($arch; "checks")),
($packages[] | format_output($arch; "packages"))
] |
"derivations=\(.)"
' >> $GITHUB_OUTPUT
outputs:
derivations: ${{ steps.get-derivations.outputs.derivations }}

check:
runs-on: ${{ matrix.check.os }}

name: ${{ matrix.check.key }} on ${{ matrix.check.arch }}
needs: get-derivations

strategy:
fail-fast: false
matrix:
check: ${{ fromJSON(needs.get-derivations.outputs.derivations) }}

steps:
- uses: DeterminateSystems/nix-installer-action@v16
- uses: DeterminateSystems/magic-nix-cache-action@v8

- run: |
nix build --no-update-lock-file --print-build-logs \
github:${{
github.repository
}}/${{
github.event.pull_request.head.sha || github.sha
}}#${{
matrix.check.type
}}.${{
matrix.check.arch
}}.${{
matrix.check.key
}}
59 changes: 19 additions & 40 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,36 @@
---
name: Docs

on:
on: # yamllint disable-line rule:truthy
push:
branches:
- master

concurrency:
cancel-in-progress: true
group: pages

jobs:
build:
name: Build
docs:
runs-on: ubuntu-24.04

permissions:
contents: read

runs-on: ubuntu-latest

steps:
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
extra-conf: |
extra-experimental-features = nix-command flakes
- name: Set up cache
uses: DeterminateSystems/magic-nix-cache-action@main

- name: Build docs
run: nix -L build github:${{ github.repository }}/${{ github.sha }}#docs

- name: Prepare docs for upload
run: cp -r --dereference --no-preserve=mode,ownership result/ public/

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: public/

deploy:
name: Deploy

needs: build

permissions:
pages: write
id-token: write
pages: write

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest

steps:
- name: Deploy docs to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@v16
- uses: DeterminateSystems/magic-nix-cache-action@v8
- run: nix build .#docs

- uses: actions/upload-pages-artifact@v3
with:
path: result

- uses: actions/deploy-pages@v4
42 changes: 0 additions & 42 deletions .github/workflows/lint.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/.direnv/
/.pre-commit-config.yaml
result
result-*
15 changes: 9 additions & 6 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
(import (let lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in fetchTarball {
url =
"https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}) { src = ./.; }).defaultNix
(import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
) { src = ./.; }).defaultNix
Loading

0 comments on commit 7dfcdb4

Please sign in to comment.