Skip to content

Commit

Permalink
Add NIX_PATH action input
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerschtli committed Feb 19, 2020
1 parent af5929c commit 1659319
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/test.yml
Expand Up @@ -2,12 +2,20 @@ name: "install-nix-action test"
on:
pull_request:
push:

jobs:
tests:
strategy:
fail-fast: false
matrix:
os: [ubuntu-18.04, macos-latest]
nixPath:
-
- nixpkgs=channel:nixos-unstable
- nixpkgs=https://github.com/NixOS/nixpkgs/archive/master.tar.gz

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v1
- run: yarn install --frozen-lockfile
Expand All @@ -17,8 +25,10 @@ jobs:
- run: yarn test
- name: Install Nix
uses: ./
with:
NIX_PATH: ${{ matrix.nixPath }}
- run: nix-env -iA cachix -f https://github.com/NixOS/nixpkgs/tarball/ab5863afada3c1b50fc43bf774b75ea71b287cde
- run: cat /etc/nix/nix.conf
# cachix should be available and be able to configure a cache
- run: cachix use cachix
- run: nix-build test.nix
- run: nix-build test.nix
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -19,6 +19,8 @@ jobs:
steps:
- uses: actions/checkout@v1
- uses: cachix/install-nix-action@v6
with:
NIX_PATH: nixpkgs=channel:nixos-unstable
- run: nix-build
```

Expand Down
4 changes: 4 additions & 0 deletions action.yml
@@ -1,6 +1,10 @@
name: 'Install Nix'
description: 'Installs Nix on GitHub Actions for the supported platforms: Linux and macOS.'
author: 'Domen Kožar'
inputs:
NIX_PATH:
description: 'Set NIX_PATH environment variable'
required: false
branding:
color: 'blue'
icon: 'sun'
Expand Down
6 changes: 5 additions & 1 deletion lib/main.js
Expand Up @@ -57,8 +57,12 @@ function run() {
yield nixConf();
yield exec.exec("sudo", ["pkill", "-HUP", "nix-daemon"]);
// setup env
let nixPath = core.getInput('NIX_PATH');
if (typeof nixPath === "undefined" || nixPath === "") {
nixPath = '/nix/var/nix/profiles/per-user/root/channels';
}
core.exportVariable('PATH', `${PATH}:/nix/var/nix/profiles/default/bin:/nix/var/nix/profiles/per-user/runner/profile/bin`);
core.exportVariable('NIX_PATH', `/nix/var/nix/profiles/per-user/root/channels`);
core.exportVariable('NIX_PATH', nixPath);
if (os_1.type() == "Darwin") {
// macOS needs certificates hints
core.exportVariable('NIX_SSL_CERT_FILE', '/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt');
Expand Down
11 changes: 8 additions & 3 deletions src/main.ts
Expand Up @@ -47,8 +47,14 @@ async function run() {
await exec.exec("sudo", ["pkill", "-HUP", "nix-daemon"]);

// setup env
core.exportVariable('PATH', `${PATH}:/nix/var/nix/profiles/default/bin:/nix/var/nix/profiles/per-user/runner/profile/bin`)
core.exportVariable('NIX_PATH', `/nix/var/nix/profiles/per-user/root/channels`)
let nixPath: string | undefined = core.getInput('NIX_PATH');
if (typeof nixPath === "undefined" || nixPath === "") {
nixPath = '/nix/var/nix/profiles/per-user/root/channels';
}

core.exportVariable('PATH', `${PATH}:/nix/var/nix/profiles/default/bin:/nix/var/nix/profiles/per-user/runner/profile/bin`);
core.exportVariable('NIX_PATH', nixPath);

if (type() == "Darwin") {
// macOS needs certificates hints
core.exportVariable('NIX_SSL_CERT_FILE', '/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt');
Expand All @@ -58,7 +64,6 @@ async function run() {
// macOS needs time to reload the daemon :(
await exec.exec("sleep", ["10"]);
}

} catch (error) {
core.setFailed(`Action failed with error: ${error}`);
throw error;
Expand Down

0 comments on commit 1659319

Please sign in to comment.