mirror of
https://codeberg.org/icewind/attic-action.git
synced 2026-06-04 01:54:08 +02:00
Install Nix via the action
This commit is contained in:
parent
a6de7cd0c2
commit
4db446a512
7 changed files with 131 additions and 46 deletions
49
src/main.ts
49
src/main.ts
|
|
@ -1,26 +1,47 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import {homedir} from 'os';
|
||||
import {existsSync} from 'fs';
|
||||
import {extrasperse} from './utils';
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
// inputs
|
||||
const file = core.getInput('file');
|
||||
const attributes = core.getInput('attributes');
|
||||
const cachixPush = core.getInput('cachixPush', { required: true });
|
||||
const signingKey = core.getInput('signingKey', { required: true });
|
||||
|
||||
// required for macos
|
||||
core.exportVariable('NIX_SSL_CERT_FILE', '/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt');
|
||||
// rest of the constants
|
||||
const home = homedir();
|
||||
const PATH = process.env.PATH;
|
||||
const CERTS_PATH = home + '/.nix-profile/etc/ssl/certs/ca-bundle.crt';
|
||||
|
||||
console.log(`Installing Cachix ...`);
|
||||
await exec.exec(homedir() + '/.nix-profile/bin/nix-env', ['-iA', 'cachix', '-f', 'https://cachix.org/api/v1/install']);
|
||||
core.startGroup('Installing Nix')
|
||||
// TODO: retry due to all the things that go wrong
|
||||
const nixInstall = await tc.downloadTool('https://nixos.org/nix/install');
|
||||
await exec.exec("sh", [nixInstall]);
|
||||
core.exportVariable('PATH', `${PATH}:${home}/.nix-profile/bin`)
|
||||
core.endGroup()
|
||||
|
||||
// macOS needs certificates hints
|
||||
if (existsSync(CERTS_PATH)) {
|
||||
core.exportVariable('NIX_SSL_CERT_FILE', CERTS_PATH);
|
||||
}
|
||||
|
||||
core.startGroup('Installing Cachix')
|
||||
await exec.exec('nix-env', ['-iA', 'cachix', '-f', 'https://cachix.org/api/v1/install']);
|
||||
core.endGroup()
|
||||
|
||||
core.startGroup(`Using Cachix ` + cachixPush);
|
||||
await exec.exec('cachix', ['use', cachixPush]);
|
||||
core.endGroup()
|
||||
|
||||
core.exportVariable('CACHIX_SIGNING_KEY', signingKey)
|
||||
// TODO: cachix use --watch-store
|
||||
|
||||
console.log(`Setting up cache ` + cachixPush + `...`);
|
||||
await exec.exec(homedir() + '/.nix-profile/bin/cachix', ['use', cachixPush]);
|
||||
|
||||
console.log(`Invoking nix-build...`);
|
||||
core.startGroup(`Invoking nix-build`);
|
||||
let paths = '';
|
||||
const options = {
|
||||
listeners: {
|
||||
|
|
@ -29,13 +50,15 @@ async function run() {
|
|||
},
|
||||
}
|
||||
};
|
||||
const args = ['-f', file || "default.nix"].concat(extrasperse('-A', attributes.split(/\s/)));
|
||||
await exec.exec(homedir() + '/.nix-profile/bin/nix-build', args, options);
|
||||
const args = extrasperse('-A', attributes.split(/\s/)).concat([file || "default.nix"]);
|
||||
await exec.exec('nix-build', args, options);
|
||||
core.endGroup()
|
||||
|
||||
console.log(`Pushing to cache ` + cachixPush + `...`);
|
||||
await exec.exec(homedir() + '/.nix-profile/bin/cachix', ['push', cachixPush].concat(paths.split(/\s/).join(' ')));
|
||||
core.startGroup(`Pushing to Cachix ` + cachixPush);
|
||||
await exec.exec('cachix', ['push', cachixPush].concat(paths.split(/\s/).join(' ')));
|
||||
core.endGroup()
|
||||
} catch (error) {
|
||||
core.setFailed(`Action faield with error: ${error}`);
|
||||
core.setFailed(`Action failed with error: ${error}`);
|
||||
throw(error);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue