Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Introduction

nix-actions is a collection of tools to create a Nix based CI workflow on Forgejo (e.g. Codeberg).

Container

Image: codeberg.org/nix-actions/container:latest-<architecture>

Note: Currently, only aarch64 images are available.

The nix-actions container provides an environment for CI tasks to be run. It can be used as an image for the Forgejo runner.

Actions

Forgejo actions can compose multiple actions.

  • checkout

Container

A minimal Nix container for usage with Forgejo Actions

This is the environment the actions are meant to be run in.

Installation

Note: Currently, only aarch64 images are available.

A Forgejo runner is required. It can be configured to use the nixos-actions image:

runner:
  labels:
    - 'nixos:docker://codeberg.org/nix-actions/container:latest-<architecture>'

Usage

Now, jobs with run-on: nixos will run inside the container:

name: MyWorkflow

on:
  - push

jobs:
  Check:
    runs-on: nixos
    steps:
      - name: Hello
        run: nix run nixpkgs#hello

checkout

Checks out a Git repository

This aciton checks out the Git repository of the current workflow. No configuration is possible, all values are taken from the environment.

Usage

In your workflow, add the follwing step (usually this will be the first step):

steps:
  - name: Checkout
    uses: https://codeberg.org/nix-actions/checkout@main

cachix

Sets up the Cachix daemon for Nix caching

Usage

As composite steps do not provide a method to automatically add post-workflow steps, this action consists of two seperate ones. One for initializing Cachix and one for stopping it.

To use this action, you will need a Cachix cache and an auth token for this cache.

Add the CACHIX_AUTH_TOKEN action secret. Then add the follwing step to your workflow:

steps:
  - name: Cache
    uses: https://codeberg.org/nix-actions/cachix@main
    with:
      - name: my-cachix-cache

name defaults to the CACHIX_CACHE_NAME repository variable, so it is possible to set this variable and leave out name.

At the end of your workflow, also add the post-worflow step:

  - name: Cache (post)
    uses: https://codeberg.org/nix-actions/cachix/post@main

deploy-pages

Deploys a directory to Codeberg pages

This action is not depending on Nix and could be used in any other enviornment. The only dependency are Git and SSH.

Usage

Warning: This action uses a Git force-push overwriting the Git history as it is generally not needed for a pages deployment. Be careful when using this on a repository which contains more than a pages branch.

In your workflow, add the following step:

steps:
  - name: Deploy
    uses: https://codeberg.org/nix-actions/deploy-pages@main
    with:
      directory: dir-to-deploy
      repository: git@codeberg.org:my-user/my-repo.git
      ssh-key: ${{ secrets.MY_DEPLOY_KEY }}

Inputs

InputRequiredDefaultDescription
directorytrueresultDirectory to deploy
repositorytrueGit repository to deploy to
branchtruepagesGit branch to deploy to
ssh-keytrueSSH key for pushing the repository
git-authortrueActionGit author name
git-emailtrue(empty string)Git author email
git-commit-messagetrueautomated deploymentGit commit message

nix-daemon

Starts the Nix daemon

The nix-actions container does not have a Nix daemon runnning by default. It is not required for a simple build, but might be for things like caching using Cachix.

Note: nix-actions actions will already include this action when required, so there might not be the need to call this action (again).

Caution: This action restarts the daemon in case it is already running.

This actions will stop a possibly running Nix daemon, start it and set the NIX_REMOTE environment variable to daemon, telling other Nix tools about it.

Usage

To use this action, add the follwing step to your workflow:

steps:
  - name: Nix
    uses: https://codeberg.org/nix-actions/nix-daemon@main