Skip to content

Commit a1f11a5

Browse files
committed
feat: support fully qualified flakes
1 parent 09ea1df commit a1f11a5

7 files changed

Lines changed: 105 additions & 11 deletions

File tree

.github/workflows/test.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,27 @@ jobs:
8181
script: |
8282
echo The future is $FUTURE
8383
[[ -z "${ANSWER}" ]] && exit 1 || exit 0
84+
85+
test-flakes:
86+
runs-on: ubuntu-latest
87+
steps:
88+
- uses: actions/checkout@v3
89+
- name: Install Nix
90+
uses: cachix/install-nix-action@v18
91+
with:
92+
nix_path: nixpkgs=channel:release-21.05
93+
extra_nix_config: |
94+
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
95+
- name: Test Basic Bash Shell with Local Flake
96+
uses: ./
97+
with:
98+
flakes: .#hello
99+
script: |
100+
hello
101+
- name: Test Bash Shell with Local and External Flakes
102+
uses: ./
103+
with:
104+
flakes: .#hello,nixpkgs#docker
105+
script: |
106+
hello
107+
command -v docker

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,35 @@ For now, this action implicitly depends on having [Nix] installed and set up cor
4646
4747
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.
4848
49+
## Use with Flakes
50+
Instead of specifying packages, you can use `flakes` to specify fully qualified flakes to be available in your script.
51+
This can be used for both local flakes in a `flake.nix` in your repo, as well as external flakes.
52+
53+
```yaml
54+
name: "Test"
55+
on:
56+
pull_request:
57+
push:
58+
jobs:
59+
tests:
60+
runs-on: ubuntu-latest
61+
steps:
62+
- uses: actions/checkout@v3
63+
- name: Install Nix
64+
uses: cachix/install-nix-action@v18
65+
with:
66+
extra_nix_config: |
67+
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
68+
- uses: workflow/nix-shell-action@v3
69+
with:
70+
flakes: .#hello,nixpkgs#docker
71+
script: |
72+
# Runs hello from a local flake.nix
73+
hello
74+
# Uses docker from the nixpkgs registry (see https://raw.githubusercontent.com/NixOS/flake-registry/master/flake-registry.json)
75+
command -v docker
76+
```
77+
4978
## Options `with: ...`
5079

5180
- `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)

dist/index.js

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.lock

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
description = "A very basic flake";
3+
4+
outputs = { self, nixpkgs }: {
5+
6+
packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;
7+
8+
packages.x86_64-linux.default = self.packages.x86_64-linux.hello;
9+
10+
};
11+
}

src/main.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function run(): void {
66
try {
77
const interpreter: string = core.getInput('interpreter')
88
const packages: string = core.getInput('packages')
9+
const flakes: string = core.getInput('flakes')
910
const script: string = core.getInput('script')
1011

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

19-
const flakeWrappedPackages = packages
20-
.split(',')
21-
.map(pkg => `nixpkgs#${pkg.trim()}`)
22-
.join(' ')
20+
const flakeWrappedPackages =
21+
flakes.split(',').join(' ') ||
22+
packages
23+
.split(',')
24+
.map(pkg => `nixpkgs#${pkg.trim()}`)
25+
.join(' ')
2326

2427
const nixWrapper = `
2528
set -euo pipefail
@@ -40,7 +43,7 @@ then
4043
nix run ${wrappedPackages} -c ${interpreter} ${scriptPath}
4144
else
4245
# nix 2.4 and later: nix shell
43-
nix --experimental-features 'nix-command flakes' shell ${flakeWrappedPackages} -c ${interpreter} ${scriptPath}
46+
nix --experimental-features 'nix-command flakes' shell ${flakeWrappedPackages} -c ${interpreter} ${scriptPath}
4447
fi
4548
`
4649

0 commit comments

Comments
 (0)