Skip to content

Commit

Permalink
Merge branch 'main' into hoverbear/fh-160-action-should-work-under-ne…
Browse files Browse the repository at this point in the history
…ktosact-in-the-absence-of-systemd
  • Loading branch information
Hoverbear committed Jan 9, 2024
2 parents 81ee88f + 0f8fa3d commit 4126bb8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
24 changes: 17 additions & 7 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

24 changes: 17 additions & 7 deletions src/main.ts
Expand Up @@ -637,14 +637,18 @@ class NixInstallerAction {
}

private async setup_kvm(): Promise<boolean> {
const current_user = userInfo();
const is_root = current_user.uid === 0;
const maybe_sudo = is_root ? "" : "sudo";

const kvm_rules =
"/etc/udev/rules.d/99-determinate-nix-installer-kvm.rules";
try {
const write_file_exit_code = await actions_exec.exec(
"sh",
[
"-c",
`echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee ${kvm_rules} > /dev/null`,
`echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | ${maybe_sudo} tee ${kvm_rules} > /dev/null`,
],
{
silent: true,
Expand All @@ -671,11 +675,15 @@ class NixInstallerAction {
);
}

const debug_run_throw = async (
const debug_root_run_throw = async (
action: string,
command: string,
args: string[],
): Promise<void> => {
if (!is_root) {
args = [command, ...args];
command = "sudo";
}
const reload_exit_code = await actions_exec.exec(command, args, {
silent: true,
listeners: {
Expand All @@ -701,21 +709,23 @@ class NixInstallerAction {
}
};

await debug_run_throw("reloading udev rules", `sudo`, [
"udevadm",
await debug_root_run_throw("reloading udev rules", "udevadm", [
"control",
"--reload-rules",
]);

await debug_run_throw("triggering udev against kvm", `sudo`, [
"udevadm",
await debug_root_run_throw("triggering udev against kvm", "udevadm", [
"trigger",
"--name-match=kvm",
]);

return true;
} catch (error) {
await actions_exec.exec("sudo", ["rm", "-f", kvm_rules]);
if (is_root) {
await actions_exec.exec("rm", ["-f", kvm_rules]);
} else {
await actions_exec.exec("sudo", ["rm", "-f", kvm_rules]);
}

return false;
}
Expand Down

0 comments on commit 4126bb8

Please sign in to comment.