programs.nix-required-mounts: presets.cuda -> nvidia-gpu
This hopefully clarifies that the preset configures the hook to expose "nvidia devices", which includse both the userspace driver and the device nodes. The derivations still declare requiredSystemFeatures = [ "cuda" ] to explicitly indicate they need to use the CUDA functionality and expect a libcuda.so and a CUDA-capable device. Ideally, we'd also include the specific CUDA architectures (sm_86, etc) in feature names. Derivations that use a co-processor but do not care about the vendor or even the particular interface may ask for the more generic "opengl", "vulkan", or "gpu" features. It is then responsibility of the host declaring the support for this feature to ensure the drivers and hardware are appropriately set up.
This commit is contained in:
@@ -31,10 +31,8 @@ let
|
|||||||
] ++ config.hardware.opengl.extraPackages; # nvidia_x11
|
] ++ config.hardware.opengl.extraPackages; # nvidia_x11
|
||||||
|
|
||||||
defaults = {
|
defaults = {
|
||||||
opengl.onFeatures = package.allowedPatterns.opengl.onFeatures;
|
nvidia-gpu.onFeatures = package.allowedPatterns.nvidia-gpu.onFeatures;
|
||||||
opengl.paths = package.allowedPatterns.opengl.paths ++ driverPaths;
|
nvidia-gpu.paths = package.allowedPatterns.nvidia-gpu.paths ++ driverPaths;
|
||||||
cuda.onFeatures = package.allowedPatterns.cuda.onFeatures;
|
|
||||||
cuda.paths = package.allowedPatterns.cuda.paths ++ driverPaths;
|
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
@@ -42,23 +40,21 @@ in
|
|||||||
options.programs.nix-required-mounts = {
|
options.programs.nix-required-mounts = {
|
||||||
enable = lib.mkEnableOption
|
enable = lib.mkEnableOption
|
||||||
"Expose extra paths to the sandbox depending on derivations' requiredSystemFeatures";
|
"Expose extra paths to the sandbox depending on derivations' requiredSystemFeatures";
|
||||||
presets.opengl.enable = lib.mkOption {
|
presets.nvidia-gpu.enable = lib.mkEnableOption ''
|
||||||
type = lib.types.bool;
|
Declare the support for derivations that require an Nvidia GPU to be
|
||||||
default = config.hardware.opengl.enable;
|
available, e.g. derivations with `requiredSystemFeatures = [ "cuda" ]`.
|
||||||
defaultText = lib.literalExpression "hardware.opengl.enable";
|
This mounts the corresponding userspace drivers and device nodes in the
|
||||||
description = ''
|
sandbox, but only for derivations that request these special features.
|
||||||
Expose OpenGL drivers to derivations marked with requiredSystemFeatures = [ "opengl" ]
|
|
||||||
'';
|
You may extend or override the exposed paths via the
|
||||||
};
|
`programs.nix-required-mounts.allowedPatterns.nvidia-gpu.paths` option.
|
||||||
presets.cuda.enable = lib.mkEnableOption ''
|
|
||||||
Expose CUDA drivers and GPUs to derivations marked with requiredSystemFeatures = [ "cuda" ]
|
|
||||||
'';
|
'';
|
||||||
allowedPatterns = with lib.types;
|
allowedPatterns = with lib.types;
|
||||||
lib.mkOption rec {
|
lib.mkOption rec {
|
||||||
type = attrsOf Pattern;
|
type = attrsOf Pattern;
|
||||||
description =
|
description =
|
||||||
"The hook config, describing which paths to mount for which system features";
|
"The hook config, describing which paths to mount for which system features";
|
||||||
default = { inherit (defaults) opengl; };
|
default = { };
|
||||||
defaultText = lib.literalExpression ''
|
defaultText = lib.literalExpression ''
|
||||||
{
|
{
|
||||||
opengl.paths = config.hardware.opengl.extraPackages ++ [
|
opengl.paths = config.hardware.opengl.extraPackages ++ [
|
||||||
@@ -75,16 +71,10 @@ in
|
|||||||
};
|
};
|
||||||
config = lib.mkIf cfg.enable (lib.mkMerge [
|
config = lib.mkIf cfg.enable (lib.mkMerge [
|
||||||
{ nix.settings.pre-build-hook = lib.getExe overridenPackage; }
|
{ nix.settings.pre-build-hook = lib.getExe overridenPackage; }
|
||||||
(lib.mkIf cfg.presets.opengl.enable {
|
(lib.mkIf cfg.presets.nvidia-gpu.enable {
|
||||||
nix.settings.system-features = [ "opengl" ];
|
nix.settings.system-features = cfg.allowedPatterns.nvidia-gpu.onFeatures;
|
||||||
programs.nix-required-mounts.allowedPatterns = {
|
programs.nix-required-mounts.allowedPatterns = {
|
||||||
inherit (defaults) opengl;
|
inherit (defaults) nvidia-gpu;
|
||||||
};
|
|
||||||
})
|
|
||||||
(lib.mkIf cfg.presets.cuda.enable {
|
|
||||||
nix.settings.system-features = [ "cuda" ];
|
|
||||||
programs.nix-required-mounts.allowedPatterns = {
|
|
||||||
inherit (defaults) cuda;
|
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
{ addOpenGLRunpath
|
{ addOpenGLRunpath
|
||||||
, cmake
|
, cmake
|
||||||
, allowedPatterns ? rec {
|
, allowedPatterns ? rec {
|
||||||
opengl.onFeatures = [ "opengl" ];
|
# This config is just an example.
|
||||||
opengl.paths = [
|
# When the hook observes either of the following requiredSystemFeatures:
|
||||||
|
nvidia-gpu.onFeatures = [ "gpu" "opengl" "vulkan" "cuda" ];
|
||||||
|
# It exposes these paths in the sandbox:
|
||||||
|
nvidia-gpu.paths = [
|
||||||
|
# Note that mounting /run/opengl-driver/lib actually isn't sufficient,
|
||||||
|
# because it's populated with symlinks. One most also mount their
|
||||||
|
# targets, which is what the NixOS module additionaly does.
|
||||||
addOpenGLRunpath.driverLink
|
addOpenGLRunpath.driverLink
|
||||||
"/dev/video*"
|
|
||||||
"/dev/dri"
|
"/dev/dri"
|
||||||
];
|
|
||||||
cuda.onFeatures = [ "cuda" ];
|
|
||||||
cuda.paths = opengl.paths ++ [
|
|
||||||
"/dev/nvidia*"
|
"/dev/nvidia*"
|
||||||
|
"/dev/video*"
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
, buildPackages
|
, buildPackages
|
||||||
|
|||||||
Reference in New Issue
Block a user