Difference between revisions of "Testing the Nix installer"

From NixOS Wiki
Jump to: navigation, search
(Created page with "= Using Cachix and GitHub Actions = Based on [https://github.com/NixOS/nix/pull/6652 NixOS/nix#6652]. Testing the install scripts has traditionally been tedious, but you can...")
 
(link to the now merged doc)
Line 1: Line 1:
= Using Cachix and GitHub Actions =
+
See [https://nixos.org/manual/nix/stable/contributing/testing.html testing] in the nix manual
 
 
Based on [https://github.com/NixOS/nix/pull/6652 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 <code>installer</code> and <code>installer_test</code> jobs. Once your Nix fork is set up correctly, pushing to it will also run these jobs.
 
 
 
<ul>
 
<li><p>The <code>installer</code> job will generate installers for these platforms:</p>
 
<ul>
 
<li><code>x86_64-linux</code></li>
 
<li><code>armv6l-linux</code></li>
 
<li><code>armv7l-linux</code></li>
 
<li><code>x86_64-darwin</code>.</li></ul>
 
 
 
<p>While this installer is in your Cachix cache, you can use it for manual testing on any of these platforms.</p></li>
 
<li><p>the <code>installer_test</code> job will try to use this installer and run a trivial Nix command on <code>ubuntu-latest</code> and <code>macos-latest</code>.</p></li></ul>
 
 
 
== One-time setup ==
 
 
 
# Have a GitHub account with a fork of the Nix repo.
 
# At [https://cachix.org cachix.org]:
 
#* Create or log in to an account.
 
#* Create a Cachix cache using the format <code>&lt;github-username&gt;-nix-install-tests</code>.
 
#* Navigate to the new cache &gt; Settings &gt; Auth Tokens.
 
#* Generate a new cachix auth token and copy the generated value.
 
# At [https://github.com github.com]:
 
#* Navigate to your ''Nix fork &gt; Settings &gt; Secrets &gt; Actions &gt; New repository secret''.
 
#* Name the secret <code>CACHIX_AUTH_TOKEN</code>
 
#* 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:
 
 
 
<ol>
 
<li><p>Click into the detailed view of the CI run.</p></li>
 
<li><p>Click into any <code>installer_test</code> run (the URL you're here to extract will be the same in all of them).</p></li>
 
<li><p>Click into the <code>Run cachix/install-nix-action@v...</code> step and click the detail triangle next to the first log line (it will also be <code>Run cachix/install-nix-action@v...</code>)</p></li>
 
<li><p>Copy the <code>install_url</code></p></li>
 
<li><p>To generate an install command, plug this <code>install_url</code> and your github username into this template:</p>
 
<source lang="console">sh <(curl -L <install_url>) --tarball-url-prefix https://<github-username>-nix-install-tests.cachix.org/serve
 
</source></li></ol>
 
 
 
= Additional resources =
 
 
 
* [https://github.com/Anton-Latukha/nix-tests-terraform Anton-Latukha/nix-tests-terraform]
 
** installer tests based on Terraform
 
* [https://github.com/grahamc/nix-install-matrix grahamc/nix-install-matrix]
 
** installer tests based on Vagrant and Virtualbox VMs
 
** updates: [https://github.com/flox/install-matrix flox/install-matrix]
 
 
 
= Manually generating test installers =
 
 
 
Notes from [https://github.com/NixOS/nix/pull/6652 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 &quot;right&quot;. 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 <code>x86_64-darwin</code>:
 
 
 
<source lang="console">nix build --out-link /tmp/foo ".#checks.x86_64-darwin.binaryTarball"
 
</source>
 
I used the stable out-link to make it easier to script the next steps:
 
 
 
<source lang="console">link=$(readlink /tmp/foo)
 
cp $link/*-darwin.tar.xz ~/somewheres
 
</source>
 
I've lost the last steps and am just going from memory: From here, I think I had to extract and modify the <code>install</code> 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 <code>--tarball-url-prefix</code> flag which ''may'' have solved this need?
 
 
 
[[Category:Nix]]
 
[[Category:Development]]
 

Revision as of 03:44, 10 October 2023

See testing in the nix manual