Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer require sudo #64

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -630,14 +630,18 @@ class NixInstallerAction {
}

private async setup_kvm(): Promise<boolean> {
const current_user = userInfo();
const is_root = current_user.username === "root";
Hoverbear marked this conversation as resolved.
Show resolved Hide resolved
const maybe_sudo = is_root ? "sudo" : "";
Hoverbear marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -664,11 +668,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 @@ -694,21 +702,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