mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-01 07:01:54 +00:00
nixos/docker: add enableNvidia option
This commit is contained in:
parent
d6c2fe76ed
commit
7f7209ef9a
@ -172,6 +172,11 @@ in
|
|||||||
environment.systemPackages = [ nvidia_x11.bin nvidia_x11.settings ]
|
environment.systemPackages = [ nvidia_x11.bin nvidia_x11.settings ]
|
||||||
++ lib.filter (p: p != null) [ nvidia_x11.persistenced ];
|
++ lib.filter (p: p != null) [ nvidia_x11.persistenced ];
|
||||||
|
|
||||||
|
systemd.tmpfiles.rules = optional config.virtualisation.docker.enableNvidia
|
||||||
|
"L+ /run/nvidia-docker/bin - - - - ${nvidia_x11.bin}/origBin"
|
||||||
|
++ optional (nvidia_x11.persistenced != null && config.virtualisation.docker.enableNvidia)
|
||||||
|
"L+ /run/nvidia-docker/extras/bin/nvidia-persistenced - - - - ${nvidia_x11.persistenced}/origBin/nvidia-persistenced";
|
||||||
|
|
||||||
boot.extraModulePackages = [ nvidia_x11.bin ];
|
boot.extraModulePackages = [ nvidia_x11.bin ];
|
||||||
|
|
||||||
# nvidia-uvm is required by CUDA applications.
|
# nvidia-uvm is required by CUDA applications.
|
||||||
|
@ -52,6 +52,15 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enableNvidia =
|
||||||
|
mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Enable nvidia-docker wrapper, supporting NVIDIA GPUs inside docker containers.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
liveRestore =
|
liveRestore =
|
||||||
mkOption {
|
mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
@ -140,7 +149,8 @@ in
|
|||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = mkIf cfg.enable (mkMerge [{
|
config = mkIf cfg.enable (mkMerge [{
|
||||||
environment.systemPackages = [ cfg.package ];
|
environment.systemPackages = [ cfg.package ]
|
||||||
|
++ optional cfg.enableNvidia pkgs.nvidia-docker;
|
||||||
users.groups.docker.gid = config.ids.gids.docker;
|
users.groups.docker.gid = config.ids.gids.docker;
|
||||||
systemd.packages = [ cfg.package ];
|
systemd.packages = [ cfg.package ];
|
||||||
|
|
||||||
@ -157,6 +167,7 @@ in
|
|||||||
--log-driver=${cfg.logDriver} \
|
--log-driver=${cfg.logDriver} \
|
||||||
${optionalString (cfg.storageDriver != null) "--storage-driver=${cfg.storageDriver}"} \
|
${optionalString (cfg.storageDriver != null) "--storage-driver=${cfg.storageDriver}"} \
|
||||||
${optionalString cfg.liveRestore "--live-restore" } \
|
${optionalString cfg.liveRestore "--live-restore" } \
|
||||||
|
${optionalString cfg.enableNvidia "--add-runtime nvidia=${pkgs.nvidia-docker}/bin/nvidia-container-runtime" } \
|
||||||
${cfg.extraOptions}
|
${cfg.extraOptions}
|
||||||
''];
|
''];
|
||||||
ExecReload=[
|
ExecReload=[
|
||||||
@ -165,7 +176,8 @@ in
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
path = [ pkgs.kmod ] ++ (optional (cfg.storageDriver == "zfs") pkgs.zfs);
|
path = [ pkgs.kmod ] ++ optional (cfg.storageDriver == "zfs") pkgs.zfs
|
||||||
|
++ optional cfg.enableNvidia pkgs.nvidia-docker;
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.sockets.docker = {
|
systemd.sockets.docker = {
|
||||||
@ -179,7 +191,6 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
systemd.services.docker-prune = {
|
systemd.services.docker-prune = {
|
||||||
description = "Prune docker resources";
|
description = "Prune docker resources";
|
||||||
|
|
||||||
@ -194,7 +205,15 @@ in
|
|||||||
|
|
||||||
startAt = optional cfg.autoPrune.enable cfg.autoPrune.dates;
|
startAt = optional cfg.autoPrune.enable cfg.autoPrune.dates;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
assertions = [
|
||||||
|
{ assertion = cfg.enableNvidia -> config.hardware.opengl.driSupport32Bit or false;
|
||||||
|
message = "Option enableNvidia requires 32bit support libraries";
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
(mkIf cfg.enableNvidia {
|
||||||
|
environment.etc."nvidia-container-runtime/config.toml".source = "${pkgs.nvidia-docker}/etc/config.toml";
|
||||||
|
})
|
||||||
]);
|
]);
|
||||||
|
|
||||||
imports = [
|
imports = [
|
||||||
|
Loading…
Reference in New Issue
Block a user