Testing the Nix installer

From NixOS Wiki
Jump to: navigation, search

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 on ubuntu-latest and macos-latest.

One-time setup

  1. Have a GitHub account with a fork of the Nix repo.
  2. 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.
  3. 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:

  1. Click into the detailed view of the CI run.

  2. Click into any installer_test run (the URL you're here to extract will be the same in all of them).

  3. Click into the Run cachix/install-nix-action@v... step and click the detail triangle next to the first log line (it will also be Run cachix/install-nix-action@v...)

  4. Copy the install_url

  5. 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

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?