Merge pull request #47 from cachix/prepare-v10

Support self-hosted runners and always skip adding a channel
This commit is contained in:
Domen Kožar 2020-09-21 14:58:38 +02:00 committed by GitHub
commit 97465807a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 35 deletions

View file

@ -15,28 +15,14 @@ jobs:
- run: yarn build - run: yarn build
- name: Install Nix - name: Install Nix
uses: ./ uses: ./
with:
nix_path: nixpkgs=channel:nixos-20.03
- run: nix-env -iA cachix -f https://cachix.org/api/v1/install - run: nix-env -iA cachix -f https://cachix.org/api/v1/install
- run: cat /etc/nix/nix.conf - run: cat /etc/nix/nix.conf
# cachix should be available and be able to configure a cache # cachix should be available and be able to configure a cache
- run: cachix use cachix - run: cachix use cachix
- run: nix-build test.nix - run: nix-build test.nix
no-channel:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- run: yarn install --frozen-lockfile
- run: yarn build
- name: Install Nix
uses: ./
with:
skip_adding_nixpkgs_channel: true
- run: nix-build test.nix && exit 1 || echo "OK"
- run: NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/tarball/ab5863afada3c1b50fc43bf774b75ea71b287cde nix-build test.nix
custom-nix-path: custom-nix-path:
strategy: strategy:
matrix: matrix:
@ -64,7 +50,8 @@ jobs:
- run: yarn build - run: yarn build
- name: Install Nix - name: Install Nix
uses: ./ uses: ./
with: with:
nix_path: nixpkgs=channel:nixos-20.03
extra_nix_config: | extra_nix_config: |
sandbox = relaxed sandbox = relaxed
- run: cat /etc/nix/nix.conf - run: cat /etc/nix/nix.conf

View file

@ -4,6 +4,19 @@
Installs [Nix](https://nixos.org/nix/) on GitHub Actions for the supported platforms: Linux and macOS. Installs [Nix](https://nixos.org/nix/) on GitHub Actions for the supported platforms: Linux and macOS.
By default it has no channels configured, you have to set `nix_path`
by [picking a channel](https://status.nixos.org/)
or [pin nixpkgs yourself](https://nix.dev/tutorials/towards-reproducibility-pinning-nixpkgs.html).
# Features
- Quick installation (~4s on Linux, ~20s on macOS)
- Multi-User mode with sandboxing enabled on Linux
- [Self-hosted github runner](https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners) support
- Allows specifying Nix installation URL
- Allows specifying extra Nix configration options
- Allows specifying `$NIX_PATH` and channels
## Usage ## Usage
Create `.github/workflows/test.yml` in your repo with the following contents: Create `.github/workflows/test.yml` in your repo with the following contents:
@ -28,14 +41,36 @@ See also [cachix-action](https://github.com/cachix/cachix-action) for
simple binary cache setup to speed up your builds and share binaries simple binary cache setup to speed up your builds and share binaries
with developers. with developers.
## Options `with: ...` # Usage with Flakes
- `install_url`: specify URL to install Nix from (mostly useful for testing non-stable releases) ```
name: "Test"
on:
pull_request:
push:
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
# Nix Flakes doesn't work on shallow clones
fetch-depth: 0
- uses: cachix/install-nix-action@v11
with:
install_url: https://github.com/numtide/nix-flakes-installer/releases/download/nix-3.0pre20200820_4d77513/install
extra_nix_config: |
experimental-features = nix-command flakes
- run: nix-build
```
- `nix_path`: set `NIX_PATH` environment variable (if set `skip_adding_nixpkgs_channel` will be implicitly enabled) ## Inputs (specify using `with:`)
- `skip_adding_nixpkgs_channel`: set to `true` to skip adding nixpkgs-unstable channel (and save ~5s for each job build) - `install_url`: specify URL to install Nix from (useful for testing non-stable releases)
- `extra_nix_config`: gets appended to `/etc/nix/nix.conf` if passed.
- `nix_path`: set `NIX_PATH` environment variable, for example `nixpkgs=channel:nixos-unstable`
- `extra_nix_config`: append to `/etc/nix/nix.conf`
--- ---

View file

@ -5,9 +5,7 @@ inputs:
install_url: install_url:
description: 'Installation URL that will contain a script to install Nix' description: 'Installation URL that will contain a script to install Nix'
nix_path: nix_path:
description: 'Set NIX_PATH environment variable. If set "skip_adding_nixpkgs_channel" will be implicitly enabled' description: 'Set NIX_PATH environment variable.'
skip_adding_nixpkgs_channel:
description: 'Skip adding nixpkgs-unstable channel'
extra_nix_config: extra_nix_config:
description: 'gets appended to `/etc/nix/nix.conf` if passed.' description: 'gets appended to `/etc/nix/nix.conf` if passed.'
branding: branding:

View file

@ -7,8 +7,8 @@ add_config() {
} }
# Set jobs to number of cores # Set jobs to number of cores
add_config "max-jobs = auto" add_config "max-jobs = auto"
# Allow binary caches for runner user # Allow binary caches for user
add_config "trusted-users = root runner" add_config "trusted-users = root $USER"
# Append extra nix configuration if provided # Append extra nix configuration if provided
if [[ $INPUT_EXTRA_NIX_CONFIG != "" ]]; then if [[ $INPUT_EXTRA_NIX_CONFIG != "" ]]; then
add_config "$INPUT_EXTRA_NIX_CONFIG" add_config "$INPUT_EXTRA_NIX_CONFIG"
@ -18,19 +18,17 @@ fi
installer_options=( installer_options=(
--daemon --daemon
--daemon-user-count 4 --daemon-user-count 4
--no-channel-add
--darwin-use-unencrypted-nix-store-volume --darwin-use-unencrypted-nix-store-volume
--nix-extra-conf-file /tmp/nix.conf --nix-extra-conf-file /tmp/nix.conf
) )
if [[ $INPUT_SKIP_ADDING_NIXPKGS_CHANNEL = "true" || $INPUT_NIX_PATH != "" ]]; then # On self-hosted runners we don't need to install more than once
installer_options+=(--no-channel-add) if [[ ! -d /nix/store ]]
else then
INPUT_NIX_PATH="/nix/var/nix/profiles/per-user/root/channels" sh <(curl --retry 5 --retry-connrefused -L "${INPUT_INSTALL_URL:-https://nixos.org/nix/install}") "${installer_options[@]}"
fi fi
sh <(curl --retry 5 --retry-connrefused -L "${INPUT_INSTALL_URL:-https://nixos.org/nix/install}") \
"${installer_options[@]}"
if [[ $OSTYPE =~ darwin ]]; then if [[ $OSTYPE =~ darwin ]]; then
# Disable spotlight indexing of /nix to speed up performance # Disable spotlight indexing of /nix to speed up performance
sudo mdutil -i off /nix sudo mdutil -i off /nix
@ -43,7 +41,7 @@ if [[ $OSTYPE =~ darwin ]]; then
fi fi
# Set paths # Set paths
echo "::add-path::/nix/var/nix/profiles/per-user/runner/profile/bin" echo "::add-path::/nix/var/nix/profiles/per-user/$USER/profile/bin"
echo "::add-path::/nix/var/nix/profiles/default/bin" echo "::add-path::/nix/var/nix/profiles/default/bin"
if [[ $INPUT_NIX_PATH != "" ]]; then if [[ $INPUT_NIX_PATH != "" ]]; then