-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnix_actions.qmd
executable file
·72 lines (56 loc) · 2.57 KB
/
nix_actions.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Building on Github Actions with Nix
## Setup
Just like when building using the usual approches, you first need to build the
book locally, on your computer, once. For this, after having generated the
`default.nix` file, you can build the environment using `nix-build`, and then
drop in a shell with `nix-shell` (if this previous sentence is confusing, make
sure you read the vignette linked at the end of the previous chapter).
Once in that shell, run `quarto publish gh-pages`. This will render the book,
and make sure that everything gets setup properly. If the book does not render,
this could mean that you're missing some dependency. Make sure to specify all
the requirements in the `define_env.R` script and that you re-generated the
`default.nix` file. If the `quarto publish gh-pages` command succeeds, you're
all set. Editing the book and pushing will build the book on Github Actions.
## The Github Actions workflow file
Here is what the workflow file looks like:
```
name: Build book using Nix
on:
push:
branches:
- main
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
with:
logger: pretty
log-directives: nix_installer=trace
backtrace: full
- name: Nix cache
uses: DeterminateSystems/magic-nix-cache-action@main
- name: Build development environment
run: |
nix-build
- name: Publish to GitHub Pages (and render)
uses: b-rodrigues/quarto-nix-actions/publish@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
The first step *Checkout code* makes the code available to the rest of the
steps. I then install Nix on this runner using the Determinate Systems
`nix-installer-action` and then I use another action from Determinate Systems, the
`magic-nix-cache-action`. This action caches all the packages so that they don't
need to get re-built each time a change gets pushed, speeding up the
process by a lot. The development environment gets then built using `nix-build`.
Finally, an action I defined runs, `quarto-nix-actions/publish`. This is a fork
of the `quarto-actions/publish` action which you can find
[here](https://github.com/quarto-dev/quarto-actions/blob/main/publish/action.yml).
My fork simply makes sure that the `quarto render` and `quarto publish` commands
run in the [Nix environment defined for the
project](https://github.com/b-rodrigues/quarto-nix-actions/blob/f48f5a7813eb4978a2f557ff45bcc854526fb80b/publish/action.yml#L58).