diff options
author | Jörg Thalheim <Mic92@users.noreply.github.com> | 2021-01-09 10:37:29 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-09 10:37:29 +0000 |
commit | ce9a7356a33dcf97611abeeef5b97d467917d8de (patch) | |
tree | 1d642da5433ec1b562a52e3e57038afb97d183ba /nixos | |
parent | f1a316b4fc4e511e15fbac01adc4e2e23865dbcb (diff) | |
parent | 7115e5ac8d7e7743989207e8947827dce02af8af (diff) |
Merge pull request #108547 from cpcloud/podman-nvidia
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/virtualisation/podman.nix | 58 |
1 files changed, 42 insertions, 16 deletions
diff --git a/nixos/modules/virtualisation/podman.nix b/nixos/modules/virtualisation/podman.nix index f554aeffb451..36c0ca8dfea3 100644 --- a/nixos/modules/virtualisation/podman.nix +++ b/nixos/modules/virtualisation/podman.nix @@ -1,6 +1,8 @@ { config, lib, pkgs, utils, ... }: let cfg = config.virtualisation.podman; + toml = pkgs.formats.toml { }; + nvidia-docker = pkgs.nvidia-docker.override { containerRuntimePath = "${pkgs.runc}/bin/runc"; }; inherit (lib) mkOption types; @@ -53,6 +55,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 +88,37 @@ in }; - config = lib.mkIf cfg.enable { - - 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"; - - # Enable common /etc/containers configuration - virtualisation.containers.enable = true; - - assertions = [{ - assertion = cfg.dockerCompat -> !config.virtualisation.docker.enable; - message = "Option dockerCompat conflicts with docker"; - }]; - - }; + config = lib.mkIf cfg.enable (lib.mkMerge [ + { + 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"; + + 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 [ nvidia-docker ]}" ]; + runtimes.nvidia = [ "${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 = "${nvidia-docker}/etc/podman-config.toml"; + }) + ]); } |