out-of-tree nixGL without impurity
parent
5b2b04ee0b
commit
b84ad23b42
18
flake.lock
18
flake.lock
|
@ -89,11 +89,11 @@
|
||||||
"utils": "utils"
|
"utils": "utils"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1671966569,
|
"lastModified": 1672349765,
|
||||||
"narHash": "sha256-jbLgfSnmLchARBNFRvCic63CFQ9LAyvlXnBpc2kwjQc=",
|
"narHash": "sha256-Ul3lSGglgHXhgU3YNqsNeTlRH1pqxbR64h+2hM+HtnM=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "home-manager",
|
"repo": "home-manager",
|
||||||
"rev": "c55fa26ce05fee8e063db22918d05a73d430b2ea",
|
"rev": "dd99675ee81fef051809bc87d67eb07f5ba022e8",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -138,11 +138,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs_2": {
|
"nixpkgs_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1671983799,
|
"lastModified": 1672262501,
|
||||||
"narHash": "sha256-Z2Ro6hFPZHkBqkVXY5/aBUzxi5xizQGvuHQ9+T5B/ks=",
|
"narHash": "sha256-ZNXqX9lwYo1tOFAqrVtKTLcJ2QMKCr3WuIvpN8emp7I=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "fad51abd42ca17a60fc1d4cb9382e2d79ae31836",
|
"rev": "e182da8622a354d44c39b3d7a542dc12cd7baa5f",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -184,11 +184,11 @@
|
||||||
"nixpkgs": "nixpkgs_3"
|
"nixpkgs": "nixpkgs_3"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1672107670,
|
"lastModified": 1672367043,
|
||||||
"narHash": "sha256-m4kP+8k46JwSXYDugykIVvRyoNofZDG7atjbi5+sLoU=",
|
"narHash": "sha256-4/40kfJysfDEfSpXJ3inuMetn40czz5Mh73SjxsKTX0=",
|
||||||
"owner": "oxalica",
|
"owner": "oxalica",
|
||||||
"repo": "rust-overlay",
|
"repo": "rust-overlay",
|
||||||
"rev": "f4827ef0518463f31a52ab2e5c500c80558fdd78",
|
"rev": "e6b2214363f5e18576a3b2ca0e0483d8f42fe531",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1,46 @@
|
||||||
|
{ pkgs, config, lib, ... }:
|
||||||
|
let
|
||||||
|
cfg = config.base.graphics;
|
||||||
|
cfgEnable = cfg.enable or cfg.useNixGLPackage != null;
|
||||||
|
types = lib.types;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
imports = [ ./shells.nix ];
|
||||||
|
options.base.graphics = {
|
||||||
|
enable = lib.mkEnableOption "graphics";
|
||||||
|
_enable = lib.mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
description = "Whether the graphics is implicitly enabled (final)";
|
||||||
|
internal = true;
|
||||||
|
default = false;
|
||||||
|
};
|
||||||
|
useNixGL = {
|
||||||
|
package = lib.mkPackageOption pkgs "nixGL package" {
|
||||||
|
default = [
|
||||||
|
"nixgl"
|
||||||
|
"auto"
|
||||||
|
"nixGLDefault"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
defaultPackage = lib.mkOption {
|
||||||
|
type = types.nullOr (types.enum [ "nixGLIntel" "nixGLNvidia" "nixGLNvidiaBumblebee" ]);
|
||||||
|
description = "Which nixGL package to be aliased as `nixGL` on the shell";
|
||||||
|
default = null;
|
||||||
|
example = "nixGLIntel";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
# importing shells does not mean we're enabling everything, if we do mkDefault false
|
||||||
|
# but the dilemma is, if the user import BOTH graphics.nix and shells.nix
|
||||||
|
# they will also need to do `config.base.shells.enable`
|
||||||
|
# generally, we want the behavior: import means enable
|
||||||
|
config = lib.mkIf cfgEnable {
|
||||||
|
base.graphics._enable = cfgEnable;
|
||||||
|
base.shells = {
|
||||||
|
shellAliases = lib.mkIf (cfg.useNixGL.defaultPackage != null) {
|
||||||
|
nixGL = cfg.useNixGL.defaultPackage;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
home.packages = [ cfg.useNixGL.package ];
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
{ config, proj_root, pkgs, lib, ... }:
|
||||||
|
let
|
||||||
|
cfg = config.base.keepass;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.base.keepass = {
|
||||||
|
|
||||||
|
};
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
home.packages = [
|
||||||
|
pkgs.kpcli # kp but is in cli
|
||||||
|
] ++ (if cfg.use_gui or config.base.has_gui then [
|
||||||
|
pkgs.keepass # Personal secret management
|
||||||
|
] else [ ]);
|
||||||
|
xdg.dataFile."keepass.kdbx".path =
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,4 +1,9 @@
|
||||||
{ pkgs, lib, config, ... }:
|
# TODO: vim-plug and Mason supports laziness. Probably worth it to explore
|
||||||
|
# incremental dependencies based on the project
|
||||||
|
#
|
||||||
|
# One thing to consider, though, /nix/store of `nix-shell` or `nix-develop`
|
||||||
|
# might be different from `home-manager`'s
|
||||||
|
{ pkgs, lib, config, proj_root, ... }:
|
||||||
let
|
let
|
||||||
# NOTE: Failure 1: buildInputs is pretty much ignored
|
# NOTE: Failure 1: buildInputs is pretty much ignored
|
||||||
# my_neovim = pkgs.neovim-unwrapped.overrideDerivation (old: {
|
# my_neovim = pkgs.neovim-unwrapped.overrideDerivation (old: {
|
||||||
|
@ -83,6 +88,7 @@ in
|
||||||
# https://github.com/nix-community/home-manager/pull/3287
|
# https://github.com/nix-community/home-manager/pull/3287
|
||||||
# extraConfig = builtins.readFile "${proj_root}/neovim/init.lua";
|
# extraConfig = builtins.readFile "${proj_root}/neovim/init.lua";
|
||||||
};
|
};
|
||||||
home.packages = nvim_pkgs;
|
# home.packages = nvim_pkgs;
|
||||||
|
xdg.configFile."nvim/init.lua".source = "${proj_root.config.path}//neovim/init.lua";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,11 +69,11 @@
|
||||||
"utils": "utils"
|
"utils": "utils"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1670970889,
|
"lastModified": 1672349765,
|
||||||
"narHash": "sha256-TWJo3/X3Q3r+HeX16QN4FE6ddBpGtAboymSEF+4Nnc0=",
|
"narHash": "sha256-Ul3lSGglgHXhgU3YNqsNeTlRH1pqxbR64h+2hM+HtnM=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "home-manager",
|
"repo": "home-manager",
|
||||||
"rev": "e412025fffdcd6219ddd21c65d9a1b90005ce508",
|
"rev": "dd99675ee81fef051809bc87d67eb07f5ba022e8",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -88,17 +88,14 @@
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1661367362,
|
"lastModified": 1,
|
||||||
"narHash": "sha256-Qc8MXcV+YCPREu8kk6oggk23ZBKLqeQRAIsLbHEviPE=",
|
"narHash": "sha256-KP+2qdZlhmRkrafuuEofg7YnNdVmGV95ipvpuqmJneI=",
|
||||||
"owner": "guibou",
|
"path": "/nix/store/843qksh68zpgs3bx048k0h589ax1v90z-source/out-of-tree/nixGL",
|
||||||
"repo": "nixGL",
|
"type": "path"
|
||||||
"rev": "7165ffbccbd2cf4379b6cd6d2edd1620a427e5ae",
|
|
||||||
"type": "github"
|
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "guibou",
|
"path": "/nix/store/843qksh68zpgs3bx048k0h589ax1v90z-source/out-of-tree/nixGL",
|
||||||
"repo": "nixGL",
|
"type": "path"
|
||||||
"type": "github"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
|
@ -118,11 +115,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs_2": {
|
"nixpkgs_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1670929434,
|
"lastModified": 1672262501,
|
||||||
"narHash": "sha256-n5UBO6XBV4h3TB7FYu2yAuNQMEYOrQyKeODUwKe06ow=",
|
"narHash": "sha256-ZNXqX9lwYo1tOFAqrVtKTLcJ2QMKCr3WuIvpN8emp7I=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "1710ed1f6f8ceb75cf7d1cf55ee0cc21760e1c7a",
|
"rev": "e182da8622a354d44c39b3d7a542dc12cd7baa5f",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -164,11 +161,11 @@
|
||||||
"nixpkgs": "nixpkgs_3"
|
"nixpkgs": "nixpkgs_3"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1671071423,
|
"lastModified": 1672367043,
|
||||||
"narHash": "sha256-zUldhyWANdgko+lqQuB1Eee7TyYya1KiOS0SCd/Y268=",
|
"narHash": "sha256-4/40kfJysfDEfSpXJ3inuMetn40czz5Mh73SjxsKTX0=",
|
||||||
"owner": "oxalica",
|
"owner": "oxalica",
|
||||||
"repo": "rust-overlay",
|
"repo": "rust-overlay",
|
||||||
"rev": "684659b7ca903e512a421bc6ade689fb26e509b4",
|
"rev": "e6b2214363f5e18576a3b2ca0e0483d8f42fe531",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
flake-utils.url = "github:numtide/flake-utils";
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
nixgl.url = "github:guibou/nixGL";
|
nixgl.url = "./../../out-of-tree/nixGL";
|
||||||
rust-overlay.url = "github:oxalica/rust-overlay";
|
rust-overlay.url = "github:oxalica/rust-overlay";
|
||||||
# Allows default.nix to call onto flake.nix. Useful for nix eval and automations
|
# Allows default.nix to call onto flake.nix. Useful for nix eval and automations
|
||||||
flake-compat = {
|
flake-compat = {
|
||||||
|
@ -47,6 +47,9 @@
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
debug = {
|
||||||
|
inherit overlays pkgs base;
|
||||||
|
};
|
||||||
homeConfigurations =
|
homeConfigurations =
|
||||||
let x11_wsl = ''
|
let x11_wsl = ''
|
||||||
# x11 output for WSL
|
# x11 output for WSL
|
||||||
|
@ -133,13 +136,10 @@
|
||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
modules = base.modules ++ [
|
modules = base.modules ++ [
|
||||||
./home.nix
|
./home.nix
|
||||||
|
./base/graphics.nix
|
||||||
{
|
{
|
||||||
|
base.graphics.enable = true;
|
||||||
base.alacritty.font.family = "BitstreamVeraSansMono Nerd Font";
|
base.alacritty.font.family = "BitstreamVeraSansMono Nerd Font";
|
||||||
base.shells = {
|
|
||||||
shellAliases = {
|
|
||||||
nixGL = "nixGLIntel";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
extraSpecialArgs = mkModuleArgs {
|
extraSpecialArgs = mkModuleArgs {
|
||||||
|
@ -148,7 +148,6 @@
|
||||||
username = "hwtr";
|
username = "hwtr";
|
||||||
homeDirectory = "/home/hwtr";
|
homeDirectory = "/home/hwtr";
|
||||||
packages = [
|
packages = [
|
||||||
pkgs.nixgl.nixGLIntel
|
|
||||||
pkgs.postman
|
pkgs.postman
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,14 +33,12 @@ in
|
||||||
|
|
||||||
# cool utilities
|
# cool utilities
|
||||||
pkgs.yq # Yaml adaptor for jq (only pretty print, little query)
|
pkgs.yq # Yaml adaptor for jq (only pretty print, little query)
|
||||||
pkgs.xorg.xclock # TODO: only include if have GL # For testing GL installation
|
pkgs.xorg.xclock # TODO: only include if have gui # For testing GL installation
|
||||||
pkgs.logseq # TODO: only include if have GL # Obsidian alt
|
pkgs.logseq # TODO: only include if have GL # Obsidian alt
|
||||||
pkgs.mosh # Parsec for SSH
|
pkgs.mosh # Parsec for SSH
|
||||||
# pkgs.nixops_unstable # nixops v2 # insecure for now
|
# pkgs.nixops_unstable # nixops v2 # insecure for now
|
||||||
pkgs.lynx # Web browser at your local terminal
|
pkgs.lynx # Web browser at your local terminal
|
||||||
|
pkgs.zk
|
||||||
# Personal management
|
|
||||||
pkgs.keepass # password manager. wish there is a keepass-query
|
|
||||||
|
|
||||||
# pkgs.tailscale # VPC;; This should be installed in system-nix
|
# pkgs.tailscale # VPC;; This should be installed in system-nix
|
||||||
pkgs.python310 # dev packages should be in project
|
pkgs.python310 # dev packages should be in project
|
||||||
|
@ -51,7 +49,6 @@ in
|
||||||
);
|
);
|
||||||
|
|
||||||
## Configs ##
|
## Configs ##
|
||||||
xdg.configFile."nvim/init.lua".source = "${proj_root.config.path}//neovim/init.lua";
|
|
||||||
xdg.configFile."zk/config.toml".source = "${proj_root.config.path}//zk/config.toml";
|
xdg.configFile."zk/config.toml".source = "${proj_root.config.path}//zk/config.toml";
|
||||||
|
|
||||||
## Programs ##
|
## Programs ##
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
name: Test
|
||||||
|
|
||||||
|
on: [ push, pull_request ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
name: 'Test'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2.4.2
|
||||||
|
- uses: cachix/install-nix-action@v17
|
||||||
|
- uses: cachix/cachix-action@v10
|
||||||
|
with:
|
||||||
|
name: guibou
|
||||||
|
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
|
||||||
|
- name: Build all
|
||||||
|
run: nix-build all.nix
|
||||||
|
|
|
@ -0,0 +1,248 @@
|
||||||
|
# NixGL
|
||||||
|
|
||||||
|
NixGL solve the "OpenGL" problem with [nix](https://nixos.org/nix/). It works with all mesa drivers (Intel cards and "free" version for Nvidia or AMD cards), Nvidia proprietary drivers, and even with hybrid configuration via bumblebee. It works for Vulkan programs too.
|
||||||
|
|
||||||
|
# Motivation
|
||||||
|
|
||||||
|
Using Nix on non-NixOS distros, it's common to see GL application errors:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ program
|
||||||
|
libGL error: unable to load driver: i965_dri.so
|
||||||
|
libGL error: driver pointer missing
|
||||||
|
libGL error: failed to load driver: i965
|
||||||
|
libGL error: unable to load driver: i965_dri.so
|
||||||
|
libGL error: driver pointer missing
|
||||||
|
libGL error: failed to load driver: i965
|
||||||
|
libGL error: unable to load driver: swrast_dri.so
|
||||||
|
libGL error: failed to load driver: swrast
|
||||||
|
```
|
||||||
|
|
||||||
|
NixGL provides a set of wrappers able to launch GL or Vulkan applications:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ nixGL program
|
||||||
|
$ nixVulkan program
|
||||||
|
```
|
||||||
|
|
||||||
|
# Installation
|
||||||
|
|
||||||
|
## nix-channel (Recommended)
|
||||||
|
|
||||||
|
To get started,
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ nix-channel --add https://github.com/guibou/nixGL/archive/main.tar.gz nixgl && nix-channel --update
|
||||||
|
$ nix-env -iA nixgl.auto.nixGLDefault # or replace `nixGLDefault` with your desired wrapper
|
||||||
|
```
|
||||||
|
|
||||||
|
Many wrappers are available, depending on your hardware and the graphical API you want to use (i.e. Vulkan or OpenGL). You may want to install a few of them, for example if you want to support OpenGL and Vulkan on a laptop with an hybrid configuration.
|
||||||
|
|
||||||
|
OpenGL wrappers:
|
||||||
|
|
||||||
|
- `auto.nixGLDefault`: Tries to auto-detect and install Nvidia, if not, fallback to mesa. Recommended. Invoke with `nixGL program`.
|
||||||
|
- `auto.nixGLNvidia`: Proprietary Nvidia driver (auto detection of version)
|
||||||
|
- `auto.nixGLNvidiaBumblebee`: Proprietary Nvidia driver on hybrid hardware (auto detection).
|
||||||
|
- `nixGLIntel`: Mesa OpenGL implementation (intel, amd, nouveau, ...).
|
||||||
|
|
||||||
|
Vulkan wrappers:
|
||||||
|
|
||||||
|
- `auto.nixVulkanNvidia`: Proprietary Nvidia driver (auto detection).
|
||||||
|
- `nixVulkanIntel`: Mesa Vulkan implementation.
|
||||||
|
|
||||||
|
The Vulkan wrapper also sets `VK_LAYER_PATH` the validation layers in the nix store.
|
||||||
|
|
||||||
|
## Flakes
|
||||||
|
|
||||||
|
### Directly run nixGL
|
||||||
|
|
||||||
|
You need to specify the same version of `nixpkgs` that your `program` is using. For example, replace `nixos-21.11` with `nixos-21.05`.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nix run --override-input nixpkgs nixpkgs/nixos-21.11 --impure github:guibou/nixGL -- program
|
||||||
|
```
|
||||||
|
|
||||||
|
If you use the default `nixpkgs` channel (i.e. `nixpkgs-unstable`), you can ommit those arguments like so:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nix run --impure github:guibou/nixGL -- program
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also specify which wrapper to use instead of using the default auto detection:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nix run github:guibou/nixGL#nixGLIntel -- program
|
||||||
|
```
|
||||||
|
|
||||||
|
This will result in a lighter download and execution time. Also, this evaluation is pure.
|
||||||
|
|
||||||
|
|
||||||
|
#### Error about experimental features
|
||||||
|
|
||||||
|
You can directly use:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nix --extra-experimental-features "nix-command flakes" run --impure github:guibou/nixGL -- program
|
||||||
|
```
|
||||||
|
|
||||||
|
Or set the appropriate conf in `~/.config/nix/nix.conf` / `/etc/nix/nix.conf` / `nix.extraOptions`.
|
||||||
|
|
||||||
|
#### Error with GLIBC version
|
||||||
|
|
||||||
|
if you get errors with messages similar to
|
||||||
|
```
|
||||||
|
/nix/store/g02b1lpbddhymmcjb923kf0l7s9nww58-glibc-2.33-123/lib/libc.so.6: version `GLIBC_2.34' not found (required by /nix/store/hrl51nkr7dszlwcs29wmyxq0jsqlaszn-libglvnd-1.4.0/lib/libGLX.so.0)
|
||||||
|
```
|
||||||
|
|
||||||
|
It means that there's a mismatch between the versions of `nixpkgs` used by `nixGL` and `program`.
|
||||||
|
|
||||||
|
### Use an overlay
|
||||||
|
|
||||||
|
Add nixGL as a flake input:
|
||||||
|
|
||||||
|
|
||||||
|
```Nix
|
||||||
|
{
|
||||||
|
inputs = {
|
||||||
|
nixgl.url = "github:guibou/nixGL";
|
||||||
|
};
|
||||||
|
outputs = { nixgl, ... }: { };
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, use the flake's `overlay` attr:
|
||||||
|
|
||||||
|
```Nix
|
||||||
|
{
|
||||||
|
outputs = { nixgl, nixpkgs, ... }:
|
||||||
|
let
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
system = "x86_64-linux";
|
||||||
|
overlays = [ nixgl.overlay ];
|
||||||
|
};
|
||||||
|
in
|
||||||
|
# You can now reference pkgs.nixgl.nixGLIntel, etc.
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Installation from source
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ git clone https://github.com/guibou/nixGL
|
||||||
|
$ cd nixGL
|
||||||
|
$ nix-env -f ./ -iA <your desired wrapper name>
|
||||||
|
```
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
|
||||||
|
Just launch the program you want prefixed by the right wrapper.
|
||||||
|
|
||||||
|
For example, for OpenGL programs:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ nixGL program args # For the `nixGLDefault` wrapper, recommended.
|
||||||
|
$ nixGLNvidia program args
|
||||||
|
$ nixGLIntel program args
|
||||||
|
$ nixGLNvidiaBumblebee program args
|
||||||
|
```
|
||||||
|
|
||||||
|
For Vulkan programs:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ nixVulkanNvidia program args
|
||||||
|
$ nixVulkanIntel program args
|
||||||
|
```
|
||||||
|
|
||||||
|
# OpenGL - Hybrid Intel + Nvidia laptop
|
||||||
|
|
||||||
|
After installing `nixGLIntel` and `nixGLNvidiaBumblebee`.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ nixGLIntel $(nix run nixpkgs.glxinfo -c glxinfo) | grep -i 'OpenGL version string'
|
||||||
|
OpenGL version string: 3.0 Mesa 17.3.3
|
||||||
|
$ nixGLNvidiaBumblebee $(nix run nixpkgs.glxinfo -c glxinfo) | grep -i 'OpenGL version string'
|
||||||
|
OpenGL version string: 4.6.0 NVIDIA 390.25
|
||||||
|
```
|
||||||
|
|
||||||
|
If the program you'd like to run is already installed by nix in your current environment, you can simply run it with the wrapper, for example:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ nixGLIntel blender
|
||||||
|
```
|
||||||
|
|
||||||
|
# Vulkan - Intel GPU
|
||||||
|
|
||||||
|
After installing `nixVulkanIntel`.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo apt install mesa-vulkan-drivers
|
||||||
|
...
|
||||||
|
$ nixVulkanIntel $(nix-build '<nixpkgs>' --no-out-link -A vulkan-tools)/bin/vulkaninfo | grep VkPhysicalDeviceProperties -A 7
|
||||||
|
VkPhysicalDeviceProperties:
|
||||||
|
===========================
|
||||||
|
apiVersion = 0x400036 (1.0.54)
|
||||||
|
driverVersion = 71311368 (0x4402008)
|
||||||
|
vendorID = 0x8086
|
||||||
|
deviceID = 0x591b
|
||||||
|
deviceType = INTEGRATED_GPU
|
||||||
|
deviceName = Intel(R) HD Graphics 630 (Kaby Lake GT2)
|
||||||
|
```
|
||||||
|
|
||||||
|
# Troubleshooting
|
||||||
|
|
||||||
|
## Nvidia auto detection does not work
|
||||||
|
|
||||||
|
```bash
|
||||||
|
building '/nix/store/ijs5h6h07faai0k74diiy5b2xlxh891g-auto-detect-nvidia.drv'...
|
||||||
|
pcregrep: Failed to open /proc/driver/nvidia/version: No such file or directory
|
||||||
|
builder for '/nix/store/ijs5h6h07faai0k74diiy5b2xlxh891g-auto-detect-nvidia.drv' failed with exit code 2
|
||||||
|
error: build of '/nix/store/ijs5h6h07faai0k74diiy5b2xlxh891g-auto-detect-nvidia.drv' faile
|
||||||
|
```
|
||||||
|
|
||||||
|
You can run the Nvidia installer using an explicit version string instead of the automatic detection method:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nix-build -A auto.nixGLNvidia --argstr nvidiaVersion 440.82
|
||||||
|
```
|
||||||
|
|
||||||
|
(or `nixGLNvidiaBumblebee`, `nixVulkanNividia`)
|
||||||
|
|
||||||
|
|
||||||
|
The version of your driver can be found using `glxinfo` from your system default package manager, or `nvidia-settings`.
|
||||||
|
|
||||||
|
## On nixOS
|
||||||
|
|
||||||
|
`nixGL` can also be used on nixOS if the system is installed with a different
|
||||||
|
nixpkgs clone than the one your application are installed with. Override the
|
||||||
|
`pkgs` argument of the script with the correct nixpkgs clone:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nix-build ./default.nix -A nixGLIntel --arg pkgs "import path_to_your_nixpkgs {}".
|
||||||
|
```
|
||||||
|
|
||||||
|
## Old nvidia drivers
|
||||||
|
|
||||||
|
Users of Nvidia legacy driver should use the `backport/noGLVND` branch. This branch is not tested and may not work well, please open a bug report, it will be taken care of as soon as possible.
|
||||||
|
|
||||||
|
# `nixGLCommon`
|
||||||
|
|
||||||
|
`nixGLCommon nixGLXXX` can be used to get `nixGL` executable which fallback to `nixGLXXX`. It is a shorter name for people with only one OpenGL configuration.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```
|
||||||
|
nix-build -E "with import ./default.nix {}; nixGLCommon nixGLIntel"
|
||||||
|
```
|
||||||
|
|
||||||
|
# Limitations
|
||||||
|
|
||||||
|
`nixGL` is badly tested, mostly because it is difficult to test automatically in a continuous integration context because you need access to different type of hardware.
|
||||||
|
|
||||||
|
Some OpenGL configurations may not work, for example AMD proprietary drivers. There is no fundamental limitation, so if you want support for theses configurations, open an issue.
|
||||||
|
|
||||||
|
# Hacking
|
||||||
|
|
||||||
|
One great way to contribute to nixGL is to run the test suite. Just run
|
||||||
|
`./Test.hs` in the main directory and check that all the test relevant to your
|
||||||
|
hardware are green.
|
|
@ -0,0 +1,110 @@
|
||||||
|
#!/usr/bin/env nix-shell
|
||||||
|
#!nix-shell -i runhaskell -p "haskellPackages.ghcWithPackages(p: with p; [hspec process])" -p nix
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
import Test.Hspec
|
||||||
|
import System.Process
|
||||||
|
import qualified Data.Text as Text
|
||||||
|
import Data.Text (Text)
|
||||||
|
import Control.Monad.IO.Class (liftIO)
|
||||||
|
import Data.List (find)
|
||||||
|
|
||||||
|
-- nixos-19-09 is used so hopefully it will have a different libc than
|
||||||
|
-- the current `<nixpkgs>` used in a current nixOS system, so it will trigger the
|
||||||
|
-- driver failure.
|
||||||
|
-- Run `./Test.hs --match "/Sanity/"` to ensure that non wrapped
|
||||||
|
-- binaries fails on NixOS.
|
||||||
|
|
||||||
|
currentChannel = "channel:nixos-19.09-small"
|
||||||
|
|
||||||
|
-- | Utils function: run a command and returns its output.
|
||||||
|
processOutput p args = Text.strip . Text.pack <$> readCreateProcess ((proc (Text.unpack p) (Text.unpack <$> args)) { std_err = Inherit }) ""
|
||||||
|
|
||||||
|
-- * OpenGL
|
||||||
|
|
||||||
|
-- | Returns the path to the nixGLXXX binary.
|
||||||
|
getNixGLBin version = (<>("/bin/"<>version)) <$> processOutput "nix-build" ["./", "-A", version, "-I", "nixpkgs=" <> currentChannel]
|
||||||
|
|
||||||
|
-- | Returns the vendor string associated with a glxinfo wrapped by a nixGL.
|
||||||
|
getVendorString io = do
|
||||||
|
output <- Text.lines <$> io
|
||||||
|
pure $ Text.unpack <$> find ("OpenGL version string"`Text.isPrefixOf`) output
|
||||||
|
|
||||||
|
-- | Checks that a nixGL wrapper works with glxinfo 32 & 64 bits.
|
||||||
|
checkOpenGL_32_64 glxinfo32 glxinfo64 vendorName nixGLName = do
|
||||||
|
beforeAll (getNixGLBin nixGLName) $ do
|
||||||
|
it "32 bits" $ \nixGLBin -> do
|
||||||
|
Just vendorString <- getVendorString (processOutput nixGLBin [glxinfo32, "-B"])
|
||||||
|
vendorString `shouldContain` vendorName
|
||||||
|
|
||||||
|
it "64 bits" $ \nixGLBin -> do
|
||||||
|
Just vendorString <- getVendorString (processOutput nixGLBin [glxinfo64, "-B"])
|
||||||
|
vendorString `shouldContain` vendorName
|
||||||
|
|
||||||
|
-- * Vulkan
|
||||||
|
|
||||||
|
-- | Heuristic to detect if vulkan work. `driverName` must appears in the output
|
||||||
|
checkVulkanIsWorking io = do
|
||||||
|
res <- io
|
||||||
|
res `shouldSatisfy` ("driverName"`Text.isInfixOf`)
|
||||||
|
|
||||||
|
-- | Checks that a nixGL wrapper works with glxinfo 32 & 64 bits.
|
||||||
|
checkVulkan_32_64 vulkaninfo32 vulkaninfo64 vendorName nixGLName = do
|
||||||
|
beforeAll (getNixGLBin nixGLName) $ do
|
||||||
|
it "32 bits" $ \nixGLBin -> do
|
||||||
|
checkVulkanIsWorking (processOutput nixGLBin [vulkaninfo32])
|
||||||
|
|
||||||
|
it "64 bits" $ \nixGLBin -> do
|
||||||
|
checkVulkanIsWorking (processOutput nixGLBin [vulkaninfo64])
|
||||||
|
|
||||||
|
|
||||||
|
main = do
|
||||||
|
putStrLn "Running tests for nixGL"
|
||||||
|
putStrLn "It can take a while, this will build and test all drivers in the background"
|
||||||
|
glxinfo64 <- (<>"/bin/glxinfo") <$> processOutput "nix-build" [currentChannel, "-A", "glxinfo"]
|
||||||
|
glxinfo32 <- (<>"/bin/glxinfo") <$> processOutput "nix-build" [currentChannel, "-A", "pkgsi686Linux.glxinfo"]
|
||||||
|
|
||||||
|
vulkaninfo64 <- (<>"/bin/vulkaninfo") <$> processOutput "nix-build" [currentChannel, "-A", "vulkan-tools"]
|
||||||
|
vulkaninfo32 <- (<>"/bin/vulkaninfo") <$> processOutput "nix-build" [currentChannel, "-A", "pkgsi686Linux.vulkan-tools"]
|
||||||
|
|
||||||
|
let checkOpenGL = checkOpenGL_32_64 glxinfo32 glxinfo64
|
||||||
|
checkVulkan = checkVulkan_32_64 vulkaninfo32 vulkaninfo64
|
||||||
|
|
||||||
|
hspec $ do
|
||||||
|
-- This category ensure that tests are failing if not run with nixGL
|
||||||
|
-- This allows testing on nixOS
|
||||||
|
describe "Sanity" $ do
|
||||||
|
describe "OpenGL" $ do
|
||||||
|
it "fails with unwrapped glxinfo64" $ do
|
||||||
|
vendorString <- getVendorString (processOutput glxinfo64 ["-B"])
|
||||||
|
vendorString `shouldBe` Nothing
|
||||||
|
|
||||||
|
it "fails with unwrapped glxinfo32" $ do
|
||||||
|
vendorString <- getVendorString (processOutput glxinfo32 ["-B"])
|
||||||
|
vendorString `shouldBe` Nothing
|
||||||
|
describe "Vulkan" $ do
|
||||||
|
it "fails with unwrapped vulkaninfo64" $ do
|
||||||
|
processOutput vulkaninfo64 [] `shouldThrow` anyIOException
|
||||||
|
|
||||||
|
it "fails with unwrapped vulkaninfo32" $ do
|
||||||
|
processOutput vulkaninfo32 [] `shouldThrow` anyIOException
|
||||||
|
|
||||||
|
describe "NixGL" $ do
|
||||||
|
describe "Mesa" $ do
|
||||||
|
describe "OpenGL" $ do
|
||||||
|
checkOpenGL "Mesa" "nixGLIntel"
|
||||||
|
describe "Vulkan" $ do
|
||||||
|
checkVulkan "Mesa" "nixVulkanIntel"
|
||||||
|
|
||||||
|
describe "Nvidia - Bumblebee" $ do
|
||||||
|
describe "OpenGL" $ do
|
||||||
|
checkOpenGL "NVIDIA" "nixGLNvidiaBumblebee"
|
||||||
|
xdescribe "Vulkan" $ do
|
||||||
|
-- Not tested: I don't have the hardware (@guibou)
|
||||||
|
checkVulkan "NVIDIA" "nixVulkanNvidiaBumblebee"
|
||||||
|
|
||||||
|
-- TODO: check Nvidia (I don't have this hardware)
|
||||||
|
describe "Nvidia" $ do
|
||||||
|
describe "OpenGL" $ do
|
||||||
|
checkOpenGL "NVIDIA" "nixGLNvidia"
|
||||||
|
describe "Vulkan" $ do
|
||||||
|
checkVulkan "NVIDIA" "nixVulkanNvidia"
|
|
@ -0,0 +1,25 @@
|
||||||
|
let
|
||||||
|
pkgs = import ./nixpkgs.nix { config = { allowUnfree = true; }; };
|
||||||
|
|
||||||
|
pure = pkgs.recurseIntoAttrs (pkgs.callPackage ./nixGL.nix {
|
||||||
|
nvidiaVersion = "440.82";
|
||||||
|
nvidiaHash = "edd415acf2f75a659e0f3b4f27c1fab770cf21614e84a18152d94f0d004a758e";
|
||||||
|
});
|
||||||
|
|
||||||
|
versionFile440 = (pkgs.callPackage ./nixGL.nix {
|
||||||
|
nvidiaVersionFile = pkgs.writeText "nvidia-version-440.82" ''
|
||||||
|
NVRM version: NVIDIA UNIX x86_64 Kernel Module 440.82 Wed Apr 1 20:04:33 UTC 2020
|
||||||
|
GCC version: gcc version 9.3.0 (Arch Linux 9.3.0-1)
|
||||||
|
'';
|
||||||
|
});
|
||||||
|
|
||||||
|
versionFile510 = (pkgs.callPackage ./nixGL.nix {
|
||||||
|
nvidiaVersionFile = pkgs.writeText "nvidia-version-510.54" ''
|
||||||
|
NVRM version: NVIDIA UNIX x86_64 Kernel Module 510.54 Wed Apr 1 20:04:33 UTC 2020
|
||||||
|
GCC version: gcc version 9.3.0 (Arch Linux 9.3.0-1)
|
||||||
|
'';
|
||||||
|
});
|
||||||
|
in
|
||||||
|
(with pure; [nixGLIntel nixVulkanNvidia nixGLNvidia nixVulkanIntel])
|
||||||
|
++ (with versionFile440.auto; [nixGLNvidia nixGLDefault nixVulkanNvidia])
|
||||||
|
++ (with versionFile510.auto; [nixGLNvidia nixGLDefault nixVulkanNvidia])
|
|
@ -0,0 +1,35 @@
|
||||||
|
{ ## Nvidia informations.
|
||||||
|
# Version of the system kernel module. Let it to null to enable auto-detection.
|
||||||
|
nvidiaVersion ? null,
|
||||||
|
# Hash of the Nvidia driver .run file. null is fine, but fixing a value here
|
||||||
|
# will be more reproducible and more efficient.
|
||||||
|
nvidiaHash ? null,
|
||||||
|
# Alternatively, you can pass a path that points to a nvidia version file
|
||||||
|
# and let nixGL extract the version from it. That file must be a copy of
|
||||||
|
# /proc/driver/nvidia/version. Nix doesn't like zero-sized files (see
|
||||||
|
# https://github.com/NixOS/nix/issues/3539 ).
|
||||||
|
nvidiaVersionFile ? null,
|
||||||
|
# Enable 32 bits driver
|
||||||
|
# This is on by default, you can switch it to off if you want to reduce a
|
||||||
|
# bit the size of nixGL closure.
|
||||||
|
enable32bits ? true,
|
||||||
|
# Make sure to enable config.allowUnfree to the instance of nixpkgs to be
|
||||||
|
# able to access the nvidia drivers.
|
||||||
|
pkgs ? import <nixpkgs> {
|
||||||
|
config = { allowUnfree = true; };
|
||||||
|
},
|
||||||
|
# Enable all Intel specific extensions which only works on x86_64
|
||||||
|
enableIntelX86Extensions ? true
|
||||||
|
}:
|
||||||
|
pkgs.callPackage ./nixGL.nix ({
|
||||||
|
inherit
|
||||||
|
nvidiaVersion
|
||||||
|
nvidiaVersionFile
|
||||||
|
nvidiaHash
|
||||||
|
enable32bits
|
||||||
|
;
|
||||||
|
} // (if enableIntelX86Extensions then {}
|
||||||
|
else {
|
||||||
|
intel-media-driver = null;
|
||||||
|
vaapiIntel = null;
|
||||||
|
}))
|
|
@ -0,0 +1,42 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1659877975,
|
||||||
|
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1660551188,
|
||||||
|
"narHash": "sha256-a1LARMMYQ8DPx1BgoI/UN4bXe12hhZkCNqdxNi6uS0g=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "441dc5d512153039f19ef198e662e4f3dbb9fd65",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
{
|
||||||
|
description = "A wrapper tool for nix OpenGL applications";
|
||||||
|
|
||||||
|
inputs.flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
inputs.nixpkgs.url = "github:nixos/nixpkgs";
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, flake-utils }:
|
||||||
|
(flake-utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
isIntelX86Platform = system == "x86_64-linux";
|
||||||
|
pkgs = import ./default.nix {
|
||||||
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
enable32bits = isIntelX86Platform;
|
||||||
|
enableIntelX86Extensions = isIntelX86Platform;
|
||||||
|
};
|
||||||
|
in rec {
|
||||||
|
|
||||||
|
packages = {
|
||||||
|
# makes it easy to use "nix run nixGL --impure -- program"
|
||||||
|
default = pkgs.auto.nixGLDefault;
|
||||||
|
|
||||||
|
nixGLDefault = pkgs.auto.nixGLDefault;
|
||||||
|
nixGLNvidia = pkgs.auto.nixGLNvidia;
|
||||||
|
nixGLNvidiaBumblebee = pkgs.auto.nixGLNvidiaBumblebee;
|
||||||
|
nixGLIntel = pkgs.nixGLIntel;
|
||||||
|
nixVulkanNvidia = pkgs.auto.nixVulkanNvidia;
|
||||||
|
nixVulkanIntel = pkgs.nixVulkanIntel;
|
||||||
|
};
|
||||||
|
|
||||||
|
# deprecated attributes for retro compatibility
|
||||||
|
defaultPackage = packages;
|
||||||
|
})) // rec {
|
||||||
|
# deprecated attributes for retro compatibility
|
||||||
|
overlay = overlays.default;
|
||||||
|
overlays.default = final: _:
|
||||||
|
let isIntelX86Platform = final.system == "x86_64-linux";
|
||||||
|
in {
|
||||||
|
nixgl = import ./default.nix {
|
||||||
|
pkgs = final;
|
||||||
|
enable32bits = isIntelX86Platform;
|
||||||
|
enableIntelX86Extensions = isIntelX86Platform;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,248 @@
|
||||||
|
{ # # Nvidia informations.
|
||||||
|
# Version of the system kernel module. Let it to null to enable auto-detection.
|
||||||
|
nvidiaVersion ? null,
|
||||||
|
# Hash of the Nvidia driver .run file. null is fine, but fixing a value here
|
||||||
|
# will be more reproducible and more efficient.
|
||||||
|
nvidiaHash ? null,
|
||||||
|
# Alternatively, you can pass a path that points to a nvidia version file
|
||||||
|
# and let nixGL extract the version from it. That file must be a copy of
|
||||||
|
# /proc/driver/nvidia/version. Nix doesn't like zero-sized files (see
|
||||||
|
# https://github.com/NixOS/nix/issues/3539 ).
|
||||||
|
nvidiaVersionFile ? null,
|
||||||
|
# Enable 32 bits driver
|
||||||
|
# This is one by default, you can switch it to off if you want to reduce a
|
||||||
|
# bit the size of nixGL closure.
|
||||||
|
enable32bits ? true
|
||||||
|
, writeTextFile, shellcheck, pcre, runCommand, linuxPackages
|
||||||
|
, fetchurl, lib, runtimeShell, bumblebee, libglvnd, vulkan-validation-layers
|
||||||
|
, mesa, libvdpau-va-gl, intel-media-driver, vaapiIntel, pkgsi686Linux, driversi686Linux
|
||||||
|
, zlib, libdrm, xorg, wayland, gcc }:
|
||||||
|
|
||||||
|
let
|
||||||
|
writeExecutable = { name, text }:
|
||||||
|
writeTextFile {
|
||||||
|
inherit name text;
|
||||||
|
|
||||||
|
executable = true;
|
||||||
|
destination = "/bin/${name}";
|
||||||
|
|
||||||
|
checkPhase = ''
|
||||||
|
${shellcheck}/bin/shellcheck "$out/bin/${name}"
|
||||||
|
|
||||||
|
# Check that all the files listed in the output binary exists
|
||||||
|
for i in $(${pcre}/bin/pcregrep -o0 '/nix/store/.*?/[^ ":]+' $out/bin/${name})
|
||||||
|
do
|
||||||
|
ls $i > /dev/null || (echo "File $i, referenced in $out/bin/${name} does not exists."; exit -1)
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
top = rec {
|
||||||
|
/*
|
||||||
|
It contains the builder for different nvidia configuration, parametrized by
|
||||||
|
the version of the driver and sha256 sum of the driver installer file.
|
||||||
|
*/
|
||||||
|
nvidiaPackages = { version, sha256 ? null }: rec {
|
||||||
|
nvidiaDrivers = (linuxPackages.nvidia_x11.override { }).overrideAttrs
|
||||||
|
(oldAttrs: rec {
|
||||||
|
pname = "nvidia";
|
||||||
|
name = "nvidia-x11-${version}-nixGL";
|
||||||
|
inherit version;
|
||||||
|
src = let
|
||||||
|
url =
|
||||||
|
"https://download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}.run";
|
||||||
|
in if sha256 != null then
|
||||||
|
fetchurl { inherit url sha256; }
|
||||||
|
else
|
||||||
|
builtins.fetchurl url;
|
||||||
|
useGLVND = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
nvidiaLibsOnly = nvidiaDrivers.override {
|
||||||
|
libsOnly = true;
|
||||||
|
kernel = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
nixGLNvidiaBumblebee = writeExecutable {
|
||||||
|
name = "nixGLNvidiaBumblebee-${version}";
|
||||||
|
text = ''
|
||||||
|
#!${runtimeShell}
|
||||||
|
export LD_LIBRARY_PATH=${
|
||||||
|
lib.makeLibraryPath [ nvidiaDrivers ]
|
||||||
|
}"''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
|
||||||
|
${
|
||||||
|
bumblebee.override {
|
||||||
|
nvidia_x11 = nvidiaDrivers;
|
||||||
|
nvidia_x11_i686 = nvidiaDrivers.lib32;
|
||||||
|
}
|
||||||
|
}/bin/optirun --ldpath ${
|
||||||
|
lib.makeLibraryPath ([ libglvnd nvidiaDrivers ]
|
||||||
|
++ lib.optionals enable32bits [
|
||||||
|
nvidiaDrivers.lib32
|
||||||
|
pkgsi686Linux.libglvnd
|
||||||
|
])
|
||||||
|
} "$@"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
# TODO: 32bit version? Not tested.
|
||||||
|
nixNvidiaWrapper = api:
|
||||||
|
writeExecutable {
|
||||||
|
name = "nix${api}Nvidia-${version}";
|
||||||
|
text = ''
|
||||||
|
#!${runtimeShell}
|
||||||
|
${lib.optionalString (api == "Vulkan")
|
||||||
|
"export VK_LAYER_PATH=${vulkan-validation-layers}/share/vulkan/explicit_layer.d"}
|
||||||
|
NVIDIA_JSON=(${nvidiaLibsOnly}/share/glvnd/egl_vendor.d/*nvidia.json)
|
||||||
|
${lib.optionalString enable32bits "NVIDIA_JSON32=(${nvidiaLibsOnly.lib32}/share/glvnd/egl_vendor.d/*nvidia.json)"}
|
||||||
|
|
||||||
|
${''export __EGL_VENDOR_LIBRARY_FILENAMES=''${NVIDIA_JSON[*]}${
|
||||||
|
lib.optionalString enable32bits
|
||||||
|
'':''${NVIDIA_JSON32[*]}''
|
||||||
|
}"''${__EGL_VENDOR_LIBRARY_FILENAMES:+:$__EGL_VENDOR_LIBRARY_FILENAMES}"''
|
||||||
|
}
|
||||||
|
|
||||||
|
${
|
||||||
|
lib.optionalString (api == "Vulkan")
|
||||||
|
''export VK_ICD_FILENAMES=${nvidiaLibsOnly}/share/vulkan/icd.d/nvidia_icd.json${
|
||||||
|
lib.optionalString enable32bits
|
||||||
|
":${nvidiaLibsOnly.lib32}/share/vulkan/icd.d/nvidia_icd.json"
|
||||||
|
}"''${VK_ICD_FILENAMES:+:$VK_ICD_FILENAMES}"''
|
||||||
|
}
|
||||||
|
export LD_LIBRARY_PATH=${
|
||||||
|
lib.makeLibraryPath ([ libglvnd nvidiaLibsOnly ]
|
||||||
|
++ lib.optional (api == "Vulkan") vulkan-validation-layers
|
||||||
|
++ lib.optionals enable32bits [
|
||||||
|
nvidiaLibsOnly.lib32
|
||||||
|
pkgsi686Linux.libglvnd
|
||||||
|
])
|
||||||
|
}"''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
|
||||||
|
exec "$@"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
# TODO: 32bit version? Not tested.
|
||||||
|
nixGLNvidia = nixNvidiaWrapper "GL";
|
||||||
|
|
||||||
|
# TODO: 32bit version? Not tested.
|
||||||
|
nixVulkanNvidia = nixNvidiaWrapper "Vulkan";
|
||||||
|
};
|
||||||
|
|
||||||
|
nixGLIntel = writeExecutable {
|
||||||
|
name = "nixGLIntel";
|
||||||
|
# add the 32 bits drivers if needed
|
||||||
|
text = let
|
||||||
|
mesa-drivers = [ mesa.drivers ]
|
||||||
|
++ lib.optional enable32bits pkgsi686Linux.mesa.drivers;
|
||||||
|
intel-driver = [ intel-media-driver vaapiIntel ]
|
||||||
|
# Note: intel-media-driver is disabled for i686 until https://github.com/NixOS/nixpkgs/issues/140471 is fixed
|
||||||
|
++ lib.optionals enable32bits [ /* pkgsi686Linux.intel-media-driver */ driversi686Linux.vaapiIntel ];
|
||||||
|
libvdpau = [ libvdpau-va-gl ]
|
||||||
|
++ lib.optional enable32bits pkgsi686Linux.libvdpau-va-gl;
|
||||||
|
glxindirect = runCommand "mesa_glxindirect" { } (''
|
||||||
|
mkdir -p $out/lib
|
||||||
|
ln -s ${mesa.drivers}/lib/libGLX_mesa.so.0 $out/lib/libGLX_indirect.so.0
|
||||||
|
'');
|
||||||
|
in ''
|
||||||
|
#!${runtimeShell}
|
||||||
|
export LIBGL_DRIVERS_PATH=${lib.makeSearchPathOutput "lib" "lib/dri" mesa-drivers}
|
||||||
|
export LIBVA_DRIVERS_PATH=${lib.makeSearchPathOutput "out" "lib/dri" intel-driver}
|
||||||
|
${''export __EGL_VENDOR_LIBRARY_FILENAMES=${mesa.drivers}/share/glvnd/egl_vendor.d/50_mesa.json${
|
||||||
|
lib.optionalString enable32bits
|
||||||
|
":${pkgsi686Linux.mesa.drivers}/share/glvnd/egl_vendor.d/50_mesa.json"
|
||||||
|
}"''${__EGL_VENDOR_LIBRARY_FILENAMES:+:$__EGL_VENDOR_LIBRARY_FILENAMES}"''
|
||||||
|
}
|
||||||
|
export LD_LIBRARY_PATH=${lib.makeLibraryPath mesa-drivers}:${lib.makeSearchPathOutput "lib" "lib/vdpau" libvdpau}:${glxindirect}/lib:${lib.makeLibraryPath [libglvnd]}"''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
|
||||||
|
exec "$@"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
nixVulkanIntel = writeExecutable {
|
||||||
|
name = "nixVulkanIntel";
|
||||||
|
text = let
|
||||||
|
# generate a file with the listing of all the icd files
|
||||||
|
icd = runCommand "mesa_icd" { } (
|
||||||
|
# 64 bits icd
|
||||||
|
''
|
||||||
|
ls ${mesa.drivers}/share/vulkan/icd.d/*.json > f
|
||||||
|
''
|
||||||
|
# 32 bits ones
|
||||||
|
+ lib.optionalString enable32bits ''
|
||||||
|
ls ${pkgsi686Linux.mesa.drivers}/share/vulkan/icd.d/*.json >> f
|
||||||
|
''
|
||||||
|
# concat everything as a one line string with ":" as seperator
|
||||||
|
+ ''cat f | xargs | sed "s/ /:/g" > $out'');
|
||||||
|
in ''
|
||||||
|
#!${runtimeShell}
|
||||||
|
if [ -n "$LD_LIBRARY_PATH" ]; then
|
||||||
|
echo "Warning, nixVulkanIntel overwriting existing LD_LIBRARY_PATH" 1>&2
|
||||||
|
fi
|
||||||
|
export VK_LAYER_PATH=${vulkan-validation-layers}/share/vulkan/explicit_layer.d
|
||||||
|
ICDS=$(cat ${icd})
|
||||||
|
export VK_ICD_FILENAMES=$ICDS"''${VK_ICD_FILENAMES:+:$VK_ICD_FILENAMES}"
|
||||||
|
export LD_LIBRARY_PATH=${
|
||||||
|
lib.makeLibraryPath [
|
||||||
|
zlib
|
||||||
|
libdrm
|
||||||
|
xorg.libX11
|
||||||
|
xorg.libxcb
|
||||||
|
xorg.libxshmfence
|
||||||
|
wayland
|
||||||
|
gcc.cc
|
||||||
|
]
|
||||||
|
}"''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
|
||||||
|
exec "$@"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
nixGLCommon = nixGL:
|
||||||
|
runCommand "nixGL" { } ''
|
||||||
|
mkdir -p "$out/bin"
|
||||||
|
# star because nixGLNvidia... have version prefixed name
|
||||||
|
cp ${nixGL}/bin/* "$out/bin/nixGL";
|
||||||
|
'';
|
||||||
|
|
||||||
|
auto = let
|
||||||
|
_nvidiaVersionFile = if nvidiaVersionFile != null then
|
||||||
|
nvidiaVersionFile
|
||||||
|
else
|
||||||
|
# HACK: Get the version from /proc. It turns out that /proc is mounted
|
||||||
|
# inside of the build sandbox and varies from machine to machine.
|
||||||
|
#
|
||||||
|
# builtins.readFile is not able to read /proc files. See
|
||||||
|
# https://github.com/NixOS/nix/issues/3539.
|
||||||
|
runCommand "impure-nvidia-version-file" {
|
||||||
|
# To avoid sharing the build result over time or between machine,
|
||||||
|
# Add an impure parameter to force the rebuild on each access.
|
||||||
|
# time = builtins.currentTime;
|
||||||
|
preferLocalBuild = true;
|
||||||
|
allowSubstitutes = false;
|
||||||
|
} "cp /proc/driver/nvidia/version $out 2> /dev/null || touch $out";
|
||||||
|
|
||||||
|
# The nvidia version. Either fixed by the `nvidiaVersion` argument, or
|
||||||
|
# auto-detected. Auto-detection is impure.
|
||||||
|
nvidiaVersionAuto = if nvidiaVersion != null then
|
||||||
|
nvidiaVersion
|
||||||
|
else
|
||||||
|
# Get if from the nvidiaVersionFile
|
||||||
|
let
|
||||||
|
data = builtins.readFile _nvidiaVersionFile;
|
||||||
|
versionMatch = builtins.match ".*Module ([0-9.]+) .*" data;
|
||||||
|
in if versionMatch != null then builtins.head versionMatch else null;
|
||||||
|
|
||||||
|
autoNvidia = nvidiaPackages {version = nvidiaVersionAuto; };
|
||||||
|
in rec {
|
||||||
|
# The output derivation contains nixGL which point either to
|
||||||
|
# nixGLNvidia or nixGLIntel using an heuristic.
|
||||||
|
nixGLDefault = if nvidiaVersionAuto != null then
|
||||||
|
nixGLCommon autoNvidia.nixGLNvidia
|
||||||
|
else
|
||||||
|
nixGLCommon nixGLIntel;
|
||||||
|
} // autoNvidia;
|
||||||
|
};
|
||||||
|
in top // (if nvidiaVersion != null then
|
||||||
|
top.nvidiaPackages {
|
||||||
|
version = nvidiaVersion;
|
||||||
|
sha256 = nvidiaHash;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ })
|
|
@ -0,0 +1,6 @@
|
||||||
|
let
|
||||||
|
rev = "4f6d8095fd51";
|
||||||
|
in
|
||||||
|
import (fetchTarball {
|
||||||
|
url = "https://github.com/nixos/nixpkgs/archive/${rev}.tar.gz";
|
||||||
|
})
|
Loading…
Reference in New Issue