91686bf936
Signed-off-by: Gergely Nagy <me@gergo.csillger.hu> |
||
---|---|---|
.forgejo/workflows | ||
build | ||
develop | ||
install | ||
shell | ||
.gitignore | ||
COPYING.md | ||
README.md |
actions/nix
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
.