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 Apr 25, 2020
1 parent 5ab66ea commit 4a3097b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .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,6 +25,8 @@ 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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -19,6 +19,8 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v8
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
4 changes: 3 additions & 1 deletion lib/install-nix.sh
@@ -1,6 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail

nixPath="${1:-/nix/var/nix/profiles/per-user/root/channels}"

export here=$(dirname "${BASH_SOURCE[0]}")

nixConf() {
Expand Down Expand Up @@ -45,4 +47,4 @@ sudo pkill -HUP nix-daemon
# Set paths
echo "::add-path::/nix/var/nix/profiles/per-user/runner/profile/bin"
echo "::add-path::/nix/var/nix/profiles/default/bin"
echo "::set-env name=NIX_PATH::/nix/var/nix/profiles/per-user/root/channels"
echo "::set-env name=NIX_PATH::${nixPath}"
3 changes: 2 additions & 1 deletion lib/main.js
Expand Up @@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const child_process_1 = require("child_process");
const process_1 = require("process");
const net_1 = require("net");
const core_1 = require("@actions/core");
function awaitSocket() {
return __awaiter(this, void 0, void 0, function* () {
const daemonSocket = net_1.createConnection({ path: '/nix/var/nix/daemon-socket/socket' });
Expand All @@ -25,6 +26,6 @@ function awaitSocket() {
});
});
}
child_process_1.execFileSync(`${__dirname}/install-nix.sh`, { stdio: 'inherit' });
child_process_1.execFileSync(`${__dirname}/install-nix.sh`, [core_1.getInput('NIX_PATH')], { stdio: 'inherit' });
// nc doesn't work correctly on macOS :(
awaitSocket();
3 changes: 2 additions & 1 deletion src/main.ts
@@ -1,6 +1,7 @@
import { execFileSync } from 'child_process';
import { exit } from 'process';
import { createConnection } from 'net';
import { getInput } from '@actions/core';

async function awaitSocket() {
const daemonSocket = createConnection({ path: '/nix/var/nix/daemon-socket/socket' });
Expand All @@ -14,7 +15,7 @@ async function awaitSocket() {
});
}

execFileSync(`${__dirname}/install-nix.sh`, { stdio: 'inherit' });
execFileSync(`${__dirname}/install-nix.sh`, [getInput('NIX_PATH')], { stdio: 'inherit' });

// nc doesn't work correctly on macOS :(
awaitSocket();

0 comments on commit 4a3097b

Please sign in to comment.