diff --git a/docs/manual/usage/gpu-non-nixos.md b/docs/manual/usage/gpu-non-nixos.md index 7b7cfbaea..0aefa4ae3 100644 --- a/docs/manual/usage/gpu-non-nixos.md +++ b/docs/manual/usage/gpu-non-nixos.md @@ -50,9 +50,9 @@ Xonotic to run on the dGPU, but uses the wrapper function directly for demonstration purposes. ```nix -{ config, lib, pkgs, nixGL, ... }: +{ config, lib, pkgs, nixgl, ... }: { - nixGL.packages = nixGL.packages; + nixGL.packages = nixgl.packages; nixGL.defaultWrapper = "mesa"; nixGL.offloadWrapper = "nvidiaPrime"; nixGL.installScripts = [ "mesa" "nvidiaPrime" ]; @@ -68,3 +68,14 @@ demonstration purposes. ]; } ``` + +The above example assumes a flake-based setup where `nixgl` was passed from the +flake. When using channels, the example would instead begin with + +```nix +{ config, lib, pkgs, ... }: +{ + nixGL.packages = import { inherit pkgs; }; + # The rest is the same as above + ... +``` diff --git a/modules/misc/nixgl.nix b/modules/misc/nixgl.nix index f45c483bc..2c7fcaffc 100644 --- a/modules/misc/nixgl.nix +++ b/modules/misc/nixgl.nix @@ -138,11 +138,30 @@ in { }; config = let + findWrapperPackage = packageAttr: + # NixGL has wrapper packages in different places depending on how you + # access it. We want HM configuration to be the same, regardless of how + # NixGL is imported. + # + # First, let's see if we have a flake. + if builtins.hasAttr pkgs.system cfg.packages then + cfg.packages.${pkgs.system}.${packageAttr} + else + # Next, let's see if we have a channel. + if builtins.hasAttr packageAttr cfg.packages then + cfg.packages.${packageAttr} + else + # Lastly, with channels, some wrappers are grouped under "auto". + if builtins.hasAttr "auto" cfg.packages then + cfg.packages.auto.${packageAttr} + else + throw "Incompatible NixGL package layout"; + getWrapperExe = vendor: let - glPackage = cfg.packages.${pkgs.system}."nixGL${vendor}"; + glPackage = findWrapperPackage "nixGL${vendor}"; glExe = lib.getExe glPackage; - vulkanPackage = cfg.packages.${pkgs.system}."nixVulkan${vendor}"; + vulkanPackage = findWrapperPackage "nixVulkan${vendor}"; vulkanExe = if cfg.vulkan.enable then lib.getExe vulkanPackage else ""; in "${glExe} ${vulkanExe}";