Skip to content

Run any command you like in a deterministic Nix shell on Linux and macOS.

License

Notifications You must be signed in to change notification settings

dx-oss/nix-shell-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace
 
 

Repository files navigation

nix-shell-action

build-test

Run any command you like in a deterministic Nix shell.

Usage

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.

Options with: ...

  • interpreter: Interpreter to use in the script, defaults to bash.

  • file: nix-shell file, Defaults to shell.nix.

  • script: The actual script to execute in your shell. Will be passed to the interpreter.

  • options: Other options to pass along to the nix-shell command, like --pure or --packages hello or multiple options combined.


About

Run any command you like in a deterministic Nix shell on Linux and macOS.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 60.5%
  • Nix 32.1%
  • JavaScript 4.0%
  • Shell 3.4%