Use NVIDIA vGPU on NixOS (both host and guest). Also supports vGPU-Unlock-patcher (VUP for short) to unlock vGPU capabilities on consumer cards
Currently these vGPU releases are selectable (you still can use your own version, see Custom vGPU version):
- With unlock support: 17.3, 16.5, 16.2
- Without unlock: 17.5, 17.4, 16.9, 16.8
flake.nix:
{
inputs = {
/* ... */
vgpu4nixos.url = "github:mrzenc/vgpu4nixos";
};
outputs = { self, nixpkgs, vgpu4nixos, ... }@inputs: {
nixosConfigurations.mrzenc = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./configuration.nix
/* ... */
vgpu4nixos.nixosModules.host # Use nixosModules.guest for VMs
];
/* ... */
};
};
}
configuration.nix:
{ pkgs, lib, config }:
{
imports = [
./hardware-configuration.nix
/* ... */
(import (builtins.fetchGit {
url = "https://github.com/mrzenc/vgpu4nixos.git";
# Pin to specific commit (example value)
# rev = "b6ddaeb51b1575c6c8ec05b117c3a8bfa3539e92";
}) { guest = false; }) # Use { guest = true; } for VMs
];
/* ... */
}
Now more packages will be available in config.boot.kernelPackages.nvidiaPackages
, for example vgpu_16_2
for the host or grid_16_2
for the guest. Specify the package in your configuration as follows:
{ config, pkgs, lib, ... }:
{
/* ... */
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.vgpu_16_2;
/* ... */
}
After that (during the first nixos-rebuild
), the module will require you to add the GRID .zip archive (it must be Linux-KVM
one, for example NVIDIA-GRID-Linux-KVM-535.129.03-537.70.zip
) to the Nix store on the host. This does not apply to the guest
New options should appear in hardware.nvidia.vgpu
after you specify the vGPU package
VUP-related options. Please read the repository's README if you don't know how to use it. Most likely, you will only need to specify hardware.nvidia.vgpu.patcher.enable = true
and in some cases hardware.nvidia.vgpu.patcher.copyVGPUProfiles
Note
The target for the vGPU patcher is determined automatically. For a guest, it will always be grid
. For the host, if services.xserver.videoDrivers = ["nvidia"];
is specified, it will be general-merge
(merged), otherwise vgpu-kvm
.
hardware.nvidia.vgpu.patcher.enable
(bool) - enable VUPhardware.nvidia.vgpu.patcher.options.doNotForceGPLLicense
(bool)- if set to
false
, then the--enable-nvidia-gpl-for-experimenting --force-nvidia-gpl-I-know-it-is-wrong
options will be applied, which allows using the driver with slightly newer kernels
- if set to
hardware.nvidia.vgpu.patcher.options.remapP40ProfilesToV100D
(bool; only for host) - applies the--remap-p2v
option. Only for 17.x releaseshardware.nvidia.vgpu.patcher.options.extra
(list of strings) - additionalpatch.sh
command optionshardware.nvidia.vgpu.patcher.copyVGPUProfiles
(attrset; only for host) - additionalvcfgclone
lines (see VUP's README)- For example,
{"AAAA:BBBB" = "CCCC:DDDD"}
is the same asvcfgclone ${TARGET}/vgpuConfig.xml 0xCCCC 0xDDDD 0xAAAA 0xBBBB
- For example,
hardware.nvidia.vgpu.patcher.enablePatcherCmd
(bool; only for host) - add a patcher to system packages (which will be available asnvidia-vup
) for conveniencehardware.nvidia.vgpu.patcher.profileOverrides
(only for host) - custom properties for vGPU profiles
Replace *
in the following options with your profile ID ("333"
in case of nvidia-333
, also referred to as GeForce RTX 2070-3
). Multiple overrides can be specified
profileOverrides.*.vramAllocation
(integer) - vRAM allocation in megabytesprofileOverrides.*.heads
(integer) - the maximum number of virtual monitors for one VMprofileOverrides.*.enableCuda
(bool)profileOverrides.*.display.width
(integer) - maximum display width in pixelsprofileOverrides.*.display.height
(integer) - maximum display height in pixelsprofileOverrides.*.framerateLimit
(integer) - limits FPS to a certain value (0
to disable limit)profileOverrides.*.xmlConfig
(attrset) - additional configuration
An example of a profile override:
hardware.nvidia.vgpu.patcher.profileOverrides = {
"333" = {
vramAllocation = 3584; # 3.5GiB
heads = 1;
display.width = 1920;
display.height = 1080;
framerateLimit = 144;
};
};
Manages the driver source. It can be used, for example, to download the driver from your HTTP(s) server. You can use a .run or GRID .zip file. You can also use a previously patched file.
The module makes some assumptions about what file to retrieve and from where:
- by default, the host tries to fetch the GRID .zip from the Nix store, the guest fetches the driver online
- if
sha256
is specified, a .run file is always expected url = null
will force the driver to be fetched from the Nix store (useful for guests)- if
name
ends with the extension.run
, then the .run file will be expected, the same with .zip (useful for guests)
To calculate sha256
(not necessary when fetching from url, set it to ""
to find out) you can use nix-hash
:
nix-hash --flat --base64 --type sha256 /path/to/file.zip
hardware.nvidia.vgpu.driverSource.name
(string) - driver filenamehardware.nvidia.vgpu.driverSource.url
(string)hardware.nvidia.vgpu.driverSource.sha256
(string)hardware.nvidia.vgpu.driverSource.curlOptsList
(list of strings) - a list of arguments to pass tocurl
- For example,
["-u" "admin:some nice password"]
- For example,
The mkVgpuDriver
and mkVgpuPatcher
allow you to create your own driver derivation that can be passed to hardware.nvidia.package
. This way you can use a version of the vGPU that is not available by default (yet)
version
(string) - version of the host driversha256
(string) - SHA-256 for GRID .zip, not .runguestVersion
(string) - version of the guest driverguestSha256
(string) - SHA-256 of the guest .runuseSettings
(bool; optional) - whether to use nVidia X Server settingssettingVersion
(string; optional) - the version of the settings app. Not required ifuseSettings = false
settingsSha256
(string; optional) - SHA-256 of the settings app. Not required ifuseSettings = false
usePersistenced
(bool; optional) - whether to usenvidia-persistenced
persistencedVersion
(string; optional) - the version ofnvidia-persistenced
. Not required ifusePersistenced = false
persistencedSha256
(string; optional) - SHA-256 ofnvidia-persistenced
. Not required ifusePersistenced = false
generalVersion
(string) - The closest version of consumer nVidia graphics drivers to the vGPU version (usually with the same major and minor versions). Used to buildnvidia-settings
andnvidia-persistenced
gridVersion
(string) - vGPU release (for example, 16.7, 17.2...)zipFilename
(string) - the full name of the GRID .zip file (including extension)vgpuPatcher
- a patcher derivation obtained frommkVgpuPatcher
(set tonull
to disable patching)prePatch
,postPatch
,patchFlags
,patches
,preInstall
,postInstall
,broken
are passed directly tostdenv.mkDerivation
Important
The patcher created by mkVgpuPatcher
cannot be overridden directly, because it returns a function that returns the derivation, not the derivation itself. You can still override it as follows:
hardware.nvidia.package = (config.boot.kernelPackages.nvidiaPackages.mkVgpuDriver {
version = "555.44.33";
vgpuPatcher = config.boot.kernelPackages.nvidiaPackages.mkVgpuPatcher { /* ... */ };
# ...
}).overrideAttrs (self: super: {
patcher = self.patcher.override {
# your overrides
};
});
version
(string; optional) - the branch of the patcher, for visual appearance onlyrev
(string) - git revision of the patcher (usually a specific commit orrefs/heads/your-branch
)sha256
(string) - SHA-256 of the patcher source codegeneralVersion
(string) - version of the consumer (general) drivergeneralSha256
(string) - SHA-256 of the general driverlinuxGuest
(string) - version of the Linux guest driverslinuxSha256
(string) - SHA-256 of Linux guest driverswindowsGuestFilename
(string) - the full name of the Windows guest driver file (including extension)windowsSha256
(string) - SHA-256 of Windows guest driversgridVersion
(string) - vGPU release (for example, 16.7, 17.2...). Useless ifvgpuUrl
is specified.generalUrl
(string; optional) - URL where general drivers can be obtainedvgpuUrl
(string; optional) - URL where guest drivers can be obtained
The files in the nvidia-vgpu
directory are modified versions of those from the nvidia-x11
package of Nixpkgs, which is distributed under the MIT license