1
0
Fork 0
mirror of https://git.madhouse-project.org/actions/nix.git synced 2024-11-23 12:09:16 +01:00
Thin Forgejo Actions to streamline common Nix tasks.
Find a file
Gergely Nagy 91686bf936
README.md: Update the CI badge URLs
Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
2024-03-20 21:50:09 +01:00
.forgejo/workflows ci: Fix the nix-shell workflow 2023-09-25 10:06:01 +02:00
build build: Allow setting the out link 2023-09-25 10:04:42 +02:00
develop ci: Add a shellcheck workflow, and fix SC2086 in develop 2023-09-22 22:44:04 +02:00
install Initial import 2023-09-22 19:37:47 +02:00
shell Add a nix/shell action 2023-09-22 21:43:51 +02:00
.gitignore Add a .gitignore file 2023-09-22 20:06:37 +02:00
COPYING.md Initial import 2023-09-22 19:37:47 +02:00
README.md README.md: Update the CI badge URLs 2024-03-20 21:50:09 +01:00

actions/nix

Build status

This repository provides a number of Forgejo Actions, all aimed at making it more pleasant to work with both Nix (either by running under NixOS, or using the Nix package manager on its own). The provided actions are listed below. All examples show the default inputs, unless otherwise specified. If the defaults are fine, those inputs can be safely omitted.

All of these actions assume that Nix is used with Flakes.

actions/nix/install

The actions/nix/install action's job is to install Nix on the host it is running on. It needs to be running as root.

The reason why it exists, and why I am not using Cachix's install-nix-action is because that requires sudo, even when running as root, and my base images do not have sudo - they run as root. At least for now.

Once I tweak my images to not run as root, I still don't want to set them up with sudo, but with doas - but for install-nix-action, that won't matter, because I can just add an alias sudo=doas, and it will work fine. At that point, this action will likely become obsolete.

Usage

- name: Install Nix on the host
  uses: actions/nix/install@main
  with:
    install-url: "https://nixos.org/nix/install"

actions/nix/build

A thin wrapper around nix build, to make it slightly easier to build flakes. While it pretty much just wraps a single nix build invocation, I felt it more appropriate to have it in an action, because the actions/nix/develop and actions/nix/shell actions below do a fair bit more. Having this in an action makes my workflows prettier.

Usage

- name: Build a Nix package
  uses: actions/nix/build@main
  with:
    flake: .
    package: # there's no default, Nix itself will fall back to "default"
    logs: false
    out-link: "result"

By default, it builds the default package in the flake at the root of the repository the action is used for, thus, if all you want to do is build the default package, and don't care about seeing full logs, you do not need to specify any parameters, the action will do the right thing out of the box.

actions/nix/develop

Something I found myself do often, is run commands within a Nix development environment. This action makes that a whole lot nicer, because I don't have to call nix develop -c bash -c "<imagine many lines of shell code here>", I can make it look almost like a regular run property in a workflow!

The script simply puts the contents of run into a shell script, and runs that in a Nix development environment.

Usage

- name: Run something in a development environment
  uses: actions/nix/develop@main
  with:
    flake: .
    package: # no default, see above
    run: |
      # No default here, either!      

The commands specified in the run input will be written to a shell script, and the shell script will be executed with bash -eo pipefail. Everything that is in the development environment, will be available for the script.

actions/nix/shell

Exactly the same as actions/nix/develop above, except it runs a shell with the given package available in it, rather than a development environment. Otherwise its behaviour is the same.

Usage

- name: Run something in a Nix shell
  uses: actions/nix/shell@main
  with:
    flake: .
    package: # no default, see above
    run: |
      # No default here, either!      

The commands specified in the run input will be written to a shell script, and the shell script will be executed with bash -eo pipefail.