A GitHub Action to install Nix packages into an ephemeral profile.
The action is particularly useful if you use a self-hosted GitHub Actions Runner on NixOS. Third-party actions frequently require certain tools to be installed which are by default not available to the runner. With this action, you can install Nix packages easily making them available to following actions.
As soon as the action terminates—no matter if successfully or unsuccessfully—the profile is purged to allow garbage collection of all installed derivations.
The action supports installing derivations from Flake packages and by evaluating a given expression.
Installation happens through nix profile.
You may call this action multiple times within the same job. Following steps will reuse the profile.
The path of the profile is also available with the step output nix_profile_path.
Install packages by giving a comma-separated string of packages from a flake.
If no flake reference is given, nixpkgs is assumed. Example:
name: 'nix-install-pkgs-action packages'
on:
- pull_request
- push
jobs:
tests:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- uses: yaxitech/nix-install-pkgs-action@v7
with:
packages: "nixpkgs#hello, figlet"
- run: |
hello
figlet "Hello nix-install-pkgs-action!"
When installing flakes which reference a registry entry, the action resolves them as follows:
- If the input
inputs-fromis given, the action invokesnix profile install --inputs-from. As a result,nixpkgs#hellowill look upnixpkgsusing the inputs of the flake given ininputs-from. inputs-fromdefaults to., i.e., the current working directory of the process. If this directory (or a parent) contains a valid flake,nix profile installis invoked with this flake.- If
inputs-fromis unset (i.e.,""),nix profileresolves tokens using the registry.
On some occasions, you need to compose a custom derivation from a Nix expression, for example,
to install Python 3 with specific packages. This can be done with the expr input.
The action evaluates the passed string through nix profile install --expr.
Within your expression, the actions provides an imported nixpkgs as pkgs using the same
resolution strategy as outlined for the packages input.
In the following example, pkgs references inputs.nixpkgs from the flake github:yaxitech/ragenix:
name: 'nix-install-pkgs-action expr'
on:
- pull_request
- push
jobs:
tests:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- uses: yaxitech/nix-install-pkgs-action@v7
with:
expr: 'pkgs.python3.withPackages(ps: with ps; [toml pyyaml])'
inputs-from: 'github:yaxitech/ragenix'
- run: |
python3 ...Within your expression, the action also introduces let bindings for a flake in the current
working directory (repoFlake) and for the flake referenced by inputs-from (inputsFromFlake).
To install nixpkgs packages with an unfree license, either through packages or expr,
set the input allow-unfree to true. Note that this will only allow installing unfree packages
from nixpkgs. If a flake uses an unfree license you're on your own.
Sometimes, a GitHub action will check whether certain binaries are in the $PATH environment variable
before running the action, even if the binary will not actually be executed as part of your workflow configuration.
To satisfy these workflows, the dummy-bins input accepts a list of binary names that will be installed
as executables.
This action requires a Flake-enabled Nix with support for profiles.
{
nix.settings.experimental-features = [ "nix-command" "flakes" ];
}Use cachix/install-nix-action
to install Nix with flake support.
After you changed package.json, you also need to update npmDepsHash in flake.nix.
You can acquire the hash by running: nix develop -c prefetch-npm-deps package-lock.json.
Some of the TypeScript tests invoke nix during test execution. That means if
you invoke the tests through nix, for example as part of nix build, a nix
that has the recursive-nix feature enabled is required. You can put the
following snippet into your configuration.nix:
{
nix.settings = {
experimental-features = [ "nix-command" "flakes" "recursive-nix" ];
system-features = [ "recursive-nix" ];
};
}