mirror of
https://github.com/NixOS/nix.dev.git
synced 2024-10-18 14:32:43 -04:00
Add the Magic Nix Cache as an option to the GitHub Actions page
Not sure if this is the right place for it, but it seemed like the most direct place to add it. I'm open to other suggestions as well.
This commit is contained in:
parent
31bc7f39f0
commit
3fbc19b874
|
@ -296,7 +296,7 @@ hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically link
|
|||
|
||||
## Next steps
|
||||
|
||||
- The [official binary cache](https://cache.nixos.org) has a limited number of binaries for packages that are cross compiled, so to save time recompiling, configure {ref}`a binary cache and CI (GitHub Actions and Cachix) <github-actions>`.
|
||||
- The [official binary cache](https://cache.nixos.org) has a limited number of binaries for packages that are cross compiled, so to save time recompiling, configure {ref}`a binary cache and CI (GitHub Actions and a cache) <github-actions>`.
|
||||
|
||||
- While many compilers in Nixpkgs support cross compilation, not all of them do.
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
---
|
||||
myst:
|
||||
html_meta:
|
||||
"description lang=en": "Continuous Integration with GitHub Actions and Cachix"
|
||||
"keywords": "CI, Continuous Integration, GitHub Actions, Cachix, Binary Cache, Nix"
|
||||
"description lang=en": "Continuous Integration with GitHub Actions and a cache"
|
||||
"keywords": "CI, Continuous Integration, GitHub Actions, Binary Cache, Nix"
|
||||
---
|
||||
|
||||
(github-actions)=
|
||||
|
@ -11,12 +11,14 @@ myst:
|
|||
|
||||
In this tutorial, we'll show you **a few short steps** to get started using [GitHub Actions](https://github.com/features/actions) as your continuous integration (CI) workflow for commits and pull requests.
|
||||
|
||||
## Caching builds using Cachix
|
||||
|
||||
One benefit of Nix is that **CI can build and cache developer environments for every project** on every branch using binary caches.
|
||||
|
||||
An important aspect of CI is the feedback loop of, **how many minutes does the build take to finish?**
|
||||
|
||||
There are a several good options, but Cachix (below) and integrating with GitHub's built in cache (at the end) are the most straightforward.
|
||||
|
||||
## Caching builds using Cachix
|
||||
|
||||
Using [Cachix](https://cachix.org/) you'll never have to waste time building a derivation twice, and you'll share built derivations with all your developers.
|
||||
|
||||
After each job, just-built derivations are pushed to your binary cache.
|
||||
|
@ -39,7 +41,7 @@ On your GitHub repository or organization (for use across all repositories):
|
|||
2. Click on `Secrets`.
|
||||
3. Add your previously generated secrets (`CACHIX_SIGNING_KEY` and/or `CACHIX_AUTH_TOKEN`).
|
||||
|
||||
## Setting up GitHub Actions
|
||||
### 3. Setting up GitHub Actions
|
||||
|
||||
Create `.github/workflows/test.yml` with:
|
||||
|
||||
|
@ -70,8 +72,40 @@ jobs:
|
|||
Once you commit and push to your GitHub repository,
|
||||
you should see status checks appearing on commits and PRs.
|
||||
|
||||
## Caching builds using GitHub's Cache Service
|
||||
|
||||
A quick and easy way to speed up CI on any GitHub repository is to use the [Magic Nix Cache][magic-nix-cache].
|
||||
The Magic Nix Cache doesn't require any configuration, secrets, or credentials.
|
||||
This means the caching benefits automatically work for anyone who forks the repository.
|
||||
|
||||
One down side to the Magic Nix Cache is it only works inide GitHub Actions.
|
||||
For more details, check out [the readme][magic-nix-cache] and the [limits of GitHub Actions caching][github-actions-caching-limits].
|
||||
|
||||
Create `.github/workflows/test.yml` with:
|
||||
|
||||
```yaml
|
||||
name: "Test"
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
jobs:
|
||||
tests:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: cachix/install-nix-action@v20
|
||||
with:
|
||||
nix_path: nixpkgs=channel:nixos-unstable
|
||||
- uses: DeterminateSystems/magic-nix-cache-action@v2
|
||||
- run: nix-build
|
||||
- run: nix-shell --run "echo OK"
|
||||
```
|
||||
|
||||
## Next steps
|
||||
|
||||
- See [GitHub Actions workflow syntax](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions)
|
||||
- To quickly setup a Nix project read through
|
||||
[Getting started Nix template](https://github.com/nix-dot-dev/getting-started-nix-template).
|
||||
|
||||
[magic-nix-cache]: https://github.com/DeterminateSystems/magic-nix-cache-action/
|
||||
[github-actions-caching-limits]: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows
|
Loading…
Reference in a new issue