Skip to content

Commit

Permalink
feat: support fully qualified flakes
Browse files Browse the repository at this point in the history
  • Loading branch information
workflow committed Jan 2, 2023
1 parent 09ea1df commit a1f11a5
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 11 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,27 @@ jobs:
script: |
echo The future is $FUTURE
[[ -z "${ANSWER}" ]] && exit 1 || exit 0
test-flakes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Nix
uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:release-21.05
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- name: Test Basic Bash Shell with Local Flake
uses: ./
with:
flakes: .#hello
script: |
hello
- name: Test Bash Shell with Local and External Flakes
uses: ./
with:
flakes: .#hello,nixpkgs#docker
script: |
hello
command -v docker
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,35 @@ For now, this action implicitly depends on having [Nix] installed and set up cor
See also [cachix-action](https://github.com/cachix/cachix-action) for a simple binary cache setup to speed up your builds and share binaries with developers.
## Use with Flakes
Instead of specifying packages, you can use `flakes` to specify fully qualified flakes to be available in your script.
This can be used for both local flakes in a `flake.nix` in your repo, as well as external flakes.

```yaml
name: "Test"
on:
pull_request:
push:
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Nix
uses: cachix/install-nix-action@v18
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: workflow/nix-shell-action@v3
with:
flakes: .#hello,nixpkgs#docker
script: |
# Runs hello from a local flake.nix
hello
# Uses docker from the nixpkgs registry (see https://github.com/NixOS/flake-registry/master/flake-registry.json)
command -v docker
```

## Options `with: ...`

- `interpreter`: Interpreter to use in the nix shell shebang, defaults to `bash`. (This is passed to `nix run -c`, used to be `-i` in a nix shell shebang)
Expand Down
12 changes: 7 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
description = "A very basic flake";

outputs = { self, nixpkgs }: {

packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;

packages.x86_64-linux.default = self.packages.x86_64-linux.hello;

};
}
13 changes: 8 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function run(): void {
try {
const interpreter: string = core.getInput('interpreter')
const packages: string = core.getInput('packages')
const flakes: string = core.getInput('flakes')
const script: string = core.getInput('script')

const nixWrapperPath = `${__dirname}/wrapper.sh`
Expand All @@ -16,10 +17,12 @@ function run(): void {
.map(pkg => `nixpkgs.${pkg.trim()}`)
.join(' ')

const flakeWrappedPackages = packages
.split(',')
.map(pkg => `nixpkgs#${pkg.trim()}`)
.join(' ')
const flakeWrappedPackages =
flakes.split(',').join(' ') ||
packages
.split(',')
.map(pkg => `nixpkgs#${pkg.trim()}`)
.join(' ')

const nixWrapper = `
set -euo pipefail
Expand All @@ -40,7 +43,7 @@ then
nix run ${wrappedPackages} -c ${interpreter} ${scriptPath}
else
# nix 2.4 and later: nix shell
nix --experimental-features 'nix-command flakes' shell ${flakeWrappedPackages} -c ${interpreter} ${scriptPath}
nix --experimental-features 'nix-command flakes' shell ${flakeWrappedPackages} -c ${interpreter} ${scriptPath}
fi
`

Expand Down

0 comments on commit a1f11a5

Please sign in to comment.