Skip to content

Commit b669a07

Browse files
Merge pull request #141 from JTKBowers/main
Check whether the current user has access to KVM before attempting to add udev rule
2 parents 47a2223 + 520fb5e commit b669a07

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

dist/index.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,12 +1078,27 @@ class NixInstallerAction extends DetSysAction {
10781078
return false;
10791079
}
10801080

1081+
private async canAccessKvm(): Promise<boolean> {
1082+
try {
1083+
await access("/dev/kvm", fs.constants.R_OK | fs.constants.W_OK);
1084+
return true;
1085+
} catch {
1086+
return false;
1087+
}
1088+
}
1089+
10811090
private async setupKvm(): Promise<boolean> {
10821091
this.recordEvent(EVENT_SETUP_KVM);
10831092
const currentUser = userInfo();
10841093
const isRoot = currentUser.uid === 0;
10851094
const maybeSudo = isRoot ? "" : "sudo";
10861095

1096+
// First check to see whether the current user can open the KVM device node
1097+
if (await this.canAccessKvm()) {
1098+
return true;
1099+
}
1100+
1101+
// The current user can't access KVM, so try adding a udev rule to allow access to all users and groups
10871102
const kvmRules = "/etc/udev/rules.d/99-determinate-nix-installer-kvm.rules";
10881103
try {
10891104
const writeFileExitCode = await actionsExec.exec(

0 commit comments

Comments
 (0)