Skip to content

Commit 2b90cd3

Browse files
authored
Merge pull request #202 from cachix/feature/kvm
feat: enable KVM on Linux if available
2 parents a56e3a8 + fe19c91 commit 2b90cd3

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ To install Nix from any commit, go to [the corresponding installer_test action](
7373

7474
- `nix_path`: set `NIX_PATH` environment variable, for example `nixpkgs=channel:nixos-unstable`
7575

76+
- `enable_kvm`: whether to enable KVM for hardware-accelerated virtualization on Linux. Enabled by default if available.
77+
7678
---
7779

7880
## FAQ

action.yml

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ inputs:
1212
description: 'Additional installer flags passed to the installer script.'
1313
nix_path:
1414
description: 'Set NIX_PATH environment variable.'
15+
enable_kvm:
16+
description: 'Enable KVM for hardware-accelerated virtualization on Linux, if available.'
17+
required: false
18+
default: true
1519
branding:
1620
color: 'blue'
1721
icon: 'sun'
@@ -26,4 +30,5 @@ runs:
2630
INPUT_INSTALL_OPTIONS: ${{ inputs.install_options }}
2731
INPUT_INSTALL_URL: ${{ inputs.install_url }}
2832
INPUT_NIX_PATH: ${{ inputs.nix_path }}
33+
INPUT_ENABLE_KVM: ${{ inputs.enable_kvm }}
2934
GITHUB_TOKEN: ${{ github.token }}

install-nix.sh

+11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ if nix_path="$(type -p nix)" ; then
66
exit
77
fi
88

9+
if [[ ($OSTYPE =~ linux) && ($INPUT_ENABLE_KVM == 'true') ]]; then
10+
enable_kvm() {
11+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-install-nix-action-kvm.rules
12+
sudo udevadm control --reload-rules && sudo udevadm trigger --name-match=kvm
13+
}
14+
15+
echo '::group::Enabling KVM support'
16+
enable_kvm && echo 'Enabled KVM' || echo 'KVM is not available'
17+
echo '::endgroup::'
18+
fi
19+
920
# GitHub command to put the following log messages into a group which is collapsed by default
1021
echo "::group::Installing Nix"
1122

0 commit comments

Comments
 (0)