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

feat: enable KVM on Linux if available #202

Merged
merged 1 commit into from Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -73,6 +73,8 @@ To install Nix from any commit, go to [the corresponding installer_test action](

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

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

---

## FAQ
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Expand Up @@ -12,6 +12,10 @@ inputs:
description: 'Additional installer flags passed to the installer script.'
nix_path:
description: 'Set NIX_PATH environment variable.'
enable_kvm:
description: 'Enable KVM for hardware-accelerated virtualization on Linux, if available.'
required: false
default: true
branding:
color: 'blue'
icon: 'sun'
Expand All @@ -26,4 +30,5 @@ runs:
INPUT_INSTALL_OPTIONS: ${{ inputs.install_options }}
INPUT_INSTALL_URL: ${{ inputs.install_url }}
INPUT_NIX_PATH: ${{ inputs.nix_path }}
INPUT_ENABLE_KVM: ${{ inputs.enable_kvm }}
GITHUB_TOKEN: ${{ github.token }}
11 changes: 11 additions & 0 deletions install-nix.sh
Expand Up @@ -6,6 +6,17 @@ if nix_path="$(type -p nix)" ; then
exit
fi

if [[ ($OSTYPE =~ linux) && ($INPUT_ENABLE_KVM == 'true') ]]; then
enable_kvm() {
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-install-nix-action-kvm.rules
sudo udevadm control --reload-rules && sudo udevadm trigger --name-match=kvm
}

echo '::group::Enabling KVM support'
enable_kvm && echo 'Enabled KVM' || echo 'KVM is not available'
echo '::endgroup::'
fi

# GitHub command to put the following log messages into a group which is collapsed by default
echo "::group::Installing Nix"

Expand Down