mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-03 12:23:02 +00:00
nixos/podman: add nvidia runtime support
This commit is contained in:
parent
f621108dbc
commit
c9955d06be
@ -1,6 +1,7 @@
|
||||
{ config, lib, pkgs, utils, ... }:
|
||||
let
|
||||
cfg = config.virtualisation.podman;
|
||||
toml = pkgs.formats.toml { };
|
||||
|
||||
inherit (lib) mkOption types;
|
||||
|
||||
@ -53,6 +54,14 @@ in
|
||||
'';
|
||||
};
|
||||
|
||||
enableNvidia = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Enable use of NVidia GPUs from within podman containers.
|
||||
'';
|
||||
};
|
||||
|
||||
extraPackages = mkOption {
|
||||
type = with types; listOf package;
|
||||
default = [ ];
|
||||
@ -78,21 +87,37 @@ in
|
||||
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
config = lib.mkIf cfg.enable (lib.mkMerge [
|
||||
{
|
||||
environment.systemPackages = [ cfg.package ]
|
||||
++ lib.optional cfg.dockerCompat dockerCompat;
|
||||
|
||||
environment.systemPackages = [ cfg.package ]
|
||||
++ lib.optional cfg.dockerCompat dockerCompat;
|
||||
environment.etc."cni/net.d/87-podman-bridge.conflist".source = utils.copyFile "${pkgs.podman-unwrapped.src}/cni/87-podman-bridge.conflist";
|
||||
|
||||
environment.etc."cni/net.d/87-podman-bridge.conflist".source = utils.copyFile "${pkgs.podman-unwrapped.src}/cni/87-podman-bridge.conflist";
|
||||
|
||||
# Enable common /etc/containers configuration
|
||||
virtualisation.containers.enable = true;
|
||||
|
||||
assertions = [{
|
||||
assertion = cfg.dockerCompat -> !config.virtualisation.docker.enable;
|
||||
message = "Option dockerCompat conflicts with docker";
|
||||
}];
|
||||
|
||||
};
|
||||
virtualisation.containers = {
|
||||
enable = true; # Enable common /etc/containers configuration
|
||||
containersConf.extraConfig = lib.optionalString cfg.enableNvidia
|
||||
(builtins.readFile (toml.generate "podman.nvidia.containers.conf" {
|
||||
engine = {
|
||||
conmon_env_vars = [ "PATH=${lib.makeBinPath [ pkgs.nvidia-docker ]}" ];
|
||||
runtimes.nvidia = [ "${pkgs.nvidia-docker}/bin/nvidia-container-runtime" ];
|
||||
};
|
||||
}));
|
||||
};
|
||||
|
||||
assertions = [
|
||||
{
|
||||
assertion = cfg.dockerCompat -> !config.virtualisation.docker.enable;
|
||||
message = "Option dockerCompat conflicts with docker";
|
||||
}
|
||||
{
|
||||
assertion = cfg.enableNvidia -> !config.virtualisation.docker.enableNvidia;
|
||||
message = "Option enableNvidia conflicts with docker.enableNvidia";
|
||||
}
|
||||
];
|
||||
}
|
||||
(lib.mkIf cfg.enableNvidia {
|
||||
environment.etc."nvidia-container-runtime/config.toml".source = "${pkgs.nvidia-docker}/etc/podman-config.toml";
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user