Testing the Nix installer
Using Cachix and GitHub Actions
Based on NixOS/nix#6652.
Testing the install scripts has traditionally been tedious, but you can now do this much more easily via the GitHub Actions CI runs (at least for platforms that Github Actions supports).
If you've already pushed to a fork of Nix on GitHub before, you may have noticed that the CI workflows in your fork list skipped installer
and installer_test
jobs. Once your Nix fork is set up correctly, pushing to it will also run these jobs.
The
installer
job will generate installers for these platforms:x86_64-linux
armv6l-linux
armv7l-linux
x86_64-darwin
.
While this installer is in your Cachix cache, you can use it for manual testing on any of these platforms.
the
installer_test
job will try to use this installer and run a trivial Nix command onubuntu-latest
andmacos-latest
.
One-time setup
- Have a GitHub account with a fork of the Nix repo.
- At cachix.org:
- Create or log in to an account.
- Create a Cachix cache using the format
<github-username>-nix-install-tests
. - Navigate to the new cache > Settings > Auth Tokens.
- Generate a new cachix auth token and copy the generated value.
- At github.com:
- Navigate to your Nix fork > Settings > Secrets > Actions > New repository secret.
- Name the secret
CACHIX_AUTH_TOKEN
- Paste the copied value of the Cachix cache auth token.
Using the CI-generated installer for manual testing
After the CI run completes, you can check the output to extract the installer url:
Click into the detailed view of the CI run.
Click into any
installer_test
run (the URL you're here to extract will be the same in all of them).Click into the
Run cachix/install-nix-action@v...
step and click the detail triangle next to the first log line (it will also beRun cachix/install-nix-action@v...
)Copy the
install_url
To generate an install command, plug this
install_url
and your github username into this template:sh <(curl -L <install_url>) --tarball-url-prefix https://<github-username>-nix-install-tests.cachix.org/serve
Additional resources
- Anton-Latukha/nix-tests-terraform
- installer tests based on Terraform
- grahamc/nix-install-matrix
- installer tests based on Vagrant and Virtualbox VMs
- updates: flox/install-matrix
Manually generating test installers
Notes from NixOS/nix#6652:
There's obviously a manual way to do this, and it's still the only way for platforms that lack GitHub Actions runners. I did do this back in Fall 2020 (before the GitHub Actions approach encouraged here). I'll sketch what I recall in case it encourages someone to fill in detail, but: didn't know what I was doing at the time and had to fumble/ask around a lot – so I don't want to uphold any of it as "right". It may have been dumb or the hard way from the getgo. Fundamentals may have changed since. Here's the build command I used to do this on and for x86_64-darwin
:
nix build --out-link /tmp/foo ".#checks.x86_64-darwin.binaryTarball"
I used the stable out-link to make it easier to script the next steps:
link=$(readlink /tmp/foo)
cp $link/*-darwin.tar.xz ~/somewheres
I've lost the last steps and am just going from memory: From here, I think I had to extract and modify the install
script to point it at this tarball (which I scped to my own site, but it might make more sense to just share them locally).
I extracted this script once and then just search/replaced in it for each new build. The installer now supports a --tarball-url-prefix
flag which may have solved this need?