From 82e202287f4f25afe411d93d2f437f0977c52570 Mon Sep 17 00:00:00 2001 From: seth Date: Tue, 27 Feb 2024 10:35:28 -0500 Subject: nixos/containers: use new option for nvidia-container-toolkit when possible --- modules/nixos/traits/containers.nix | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'modules') diff --git a/modules/nixos/traits/containers.nix b/modules/nixos/traits/containers.nix index 43c748c..e309a89 100644 --- a/modules/nixos/traits/containers.nix +++ b/modules/nixos/traits/containers.nix @@ -1,6 +1,7 @@ { config, lib, + options, pkgs, ... }: let @@ -10,14 +11,28 @@ in { enable = lib.mkEnableOption "containers support"; }; - config.virtualisation = lib.mkIf cfg.enable { - podman = { - enable = true; - enableNvidia = lib.mkDefault (builtins.elem "nvidia" (config.services.xserver.videoDrivers or [])); - extraPackages = with pkgs; [podman-compose]; - autoPrune.enable = true; - }; + config.virtualisation = lib.mkMerge [ + (lib.mkIf cfg.enable { + podman = { + enable = true; + extraPackages = with pkgs; [podman-compose]; + autoPrune.enable = true; + }; - oci-containers.backend = "podman"; - }; + oci-containers.backend = "podman"; + }) + + (let + enable = lib.mkDefault ( + lib.elem "nvidia" (config.services.xserver.videoDrivers or []) + ); + in + if (options.virtualisation.containers ? cdi) + then { + containers.cdi.dynamic.nvidia = {inherit enable;}; + } + else { + podman.enableNvidia = enable; + }) + ]; } -- cgit v1.2.3