Skip to content

Commit

Permalink
nixgl: add support for channel-based configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
exzombie authored and Smona committed Oct 20, 2024
1 parent f4deb4a commit dd25d79
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
15 changes: 13 additions & 2 deletions docs/manual/usage/gpu-non-nixos.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" ];
Expand All @@ -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 <nixgl> { inherit pkgs; };
# The rest is the same as above
...
```
23 changes: 21 additions & 2 deletions modules/misc/nixgl.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}";

Expand Down

0 comments on commit dd25d79

Please sign in to comment.