GitHub Action
nix-shell(2)
v12
Latest version
Run any command you like in a deterministic Nix shell.
Create shell.nix
in your repo, for example
{ pkgs ? import
(builtins.fetchTarball {
name = "nixpkgs-unstable-2024-09-27";
url = "https://github.com/nixos/nixpkgs/archive/28b5b8af91ffd2623e995e20aee56510db49001a.tar.gz";
sha256 = "09zhy7bj0bd72r8dqpbrnpgapfkg5h91samrv1v8j0qxvv5kgv6n";
})
{ }
}:
pkgs.mkShell {
nativeBuildInputs = with pkgs; [ which nodejs python39 perl ];
}
Create .github/workflows/test.yml
in your repo with the following contents:
name: 'Test'
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: nixbuild/nix-quick-install-action@v27
- uses: dx-oss/nix-shell-action@v12
env:
NIX_BUILD_SHELL: bash # if using nix-quick-install-action, and not using flakes, you need to specify NIX_BUILD_SHELL
with:
file: shell.nix
script: which node
This action depends on having Nix installed and set up correctly, such as through the install-nix-action or nix-quick-install-action as demonstrated in the examples above.
-
interpreter
: Interpreter to use in the script, defaults tobash
. -
file
: nix-shell file, Defaults toshell.nix
. -
script
: The actual script to execute in your shell. Will be passed to theinterpreter
. -
options
: Other options to pass along to thenix-shell
command, like--pure
or--packages hello
or multiple options combined.