macos: fix two issues

This commit is contained in:
Domen Kožar 2020-02-24 09:50:50 +01:00
parent 8b315ca141
commit 39c9ce7c86
No known key found for this signature in database
GPG key ID: C2FFBCAFD2C24246
3 changed files with 110 additions and 28 deletions

View file

@ -1,6 +1,7 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as tc from '@actions/tool-cache';
import {execFileSync} from 'child_process';
import {type} from 'os';
async function nixConf() {
@ -17,28 +18,19 @@ async function nixConf() {
async function run() {
try {
const PATH = process.env.PATH;
const INSTALL_PATH = '/opt/nix';
const PATH = process.env.PATH;
await nixConf();
// Catalina workaround https://github.com/NixOS/nix/issues/2925
if (type() == "Darwin") {
await exec.exec("sudo", ["sh", "-c", `echo \"nix\t${INSTALL_PATH}\" >> /etc/synthetic.conf`]);
await exec.exec("sudo", ["sh", "-c", `mkdir -m 0755 ${INSTALL_PATH} && chown runner ${INSTALL_PATH}`]);
await exec.exec("/System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util", ["-B"]);
// Needed for sudo to pass NIX_IGNORE_SYMLINK_STORE
await exec.exec("sudo", ["sh", "-c", "echo 'Defaults env_keep += NIX_IGNORE_SYMLINK_STORE' >> /etc/sudoers"]);
core.exportVariable('NIX_IGNORE_SYMLINK_STORE', "1");
// Needed for nix-daemon installation
await exec.exec("sudo", ["launchctl", "setenv", "NIX_IGNORE_SYMLINK_STORE", "1"]);
execFileSync(`${__dirname}/create-darwin-volume.sh`, { stdio: 'inherit' });
}
// Needed due to multi-user being too defensive
core.exportVariable('ALLOW_PREEXISTING_INSTALLATION', "1");
// TODO: retry due to all the things that go wrong
// TODO: retry due to all the things that can go wrong
const nixInstall = await tc.downloadTool('https://nixos.org/nix/install');
await exec.exec("sh", [nixInstall, "--daemon"]);
@ -54,15 +46,12 @@ async function run() {
core.exportVariable('NIX_SSL_CERT_FILE', '/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt');
// TODO: nc doesn't work correctly on macOS :(
//await exec.exec("sh", ["-c", "while ! nc -zU /nix/var/nix/daemon-socket/socket; do sleep 0.5; done"]);
// macOS needs time to reload the daemon :(
await exec.exec("sleep", ["10"]);
}
} catch (error) {
core.setFailed(`Action failed with error: ${error}`);
throw(error);
}
}
}
run();