Skip to content

Commit 1ea11fd

Browse files
committed
feat(flake): add hardware acceleration support for Linux in dev shell
Adds conditional dependencies for hardware acceleration on Linux including: - Vulkan loader for Vulkan-accelerated encoders - Intel media drivers for VA-API support - oneVPL runtime for Intel QuickSync Configures environment variables in shellHook to properly expose GPU drivers, Vulkan loaders, and Intel media components when running on Linux systems.
1 parent 0b6a959 commit 1ea11fd

1 file changed

Lines changed: 63 additions & 32 deletions

File tree

flake.nix

Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,75 @@
2020
in
2121
{
2222
devShells.default = pkgs.mkShell {
23-
packages = with pkgs; [
24-
# Build tools
25-
autoconf
26-
automake
27-
libtool
28-
cmake
29-
curl
30-
ffmpeg
31-
file
32-
gcc
33-
git-filter-repo
34-
gnumake
35-
go
36-
gperf
37-
just
38-
meson
39-
nasm
40-
ninja
41-
# LLVM/Clang for code generator (go-clang requires libclang)
42-
# llvmPackages.libclang provides: clang compiler + libclang library
43-
# llvmPackages.llvm provides: llvm-config command
44-
llvmPackages_18.libclang
45-
llvmPackages_18.llvm
46-
pkg-config
47-
python3
48-
yasm
49-
# Rust toolchain for rav1e AV1 encoder
50-
cargo
51-
cargo-c
52-
rustc
53-
];
23+
packages =
24+
with pkgs;
25+
[
26+
# Build tools
27+
autoconf
28+
automake
29+
libtool
30+
cmake
31+
curl
32+
ffmpeg
33+
file
34+
gcc
35+
git-filter-repo
36+
gnumake
37+
go
38+
gperf
39+
just
40+
meson
41+
nasm
42+
ninja
43+
# LLVM/Clang for code generator (go-clang requires libclang)
44+
# llvmPackages.libclang provides: clang compiler + libclang library
45+
# llvmPackages.llvm provides: llvm-config command
46+
llvmPackages_18.libclang
47+
llvmPackages_18.llvm
48+
pkg-config
49+
python3
50+
yasm
51+
# Rust toolchain for rav1e AV1 encoder
52+
cargo
53+
cargo-c
54+
rustc
55+
]
56+
++ pkgs.lib.optionals pkgs.stdenv.isLinux [
57+
# Hardware acceleration runtime (Linux only)
58+
vulkan-loader # Required for Vulkan accelerated encoders
59+
intel-media-driver # VA-API driver for Intel GPUs (iHD_drv_video.so)
60+
vpl-gpu-rt # oneVPL runtime for Intel GPUs (QSV backend)
61+
];
5462

55-
# Environment for go-clang CGO compilation
63+
# Environment for go-clang CGO compilation and hardware acceleration
5664
shellHook = ''
5765
export CGO_LDFLAGS="-L${pkgs.llvmPackages.libclang.lib}/lib"
5866
export CPATH="${pkgs.llvmPackages.libclang.dev}/include"
5967
# Ensure vpx build finds yasm
6068
export PATH="${pkgs.yasm}/bin:${pkgs.nasm}/bin:$PATH"
69+
''
70+
+ pkgs.lib.optionalString pkgs.stdenv.isLinux ''
71+
# Hardware acceleration: Make GPU drivers visible
72+
# NixOS mounts GPU drivers under /run/opengl-driver/lib
73+
if [ -d "/run/opengl-driver/lib" ]; then
74+
if [ -z "$LD_LIBRARY_PATH" ]; then
75+
export LD_LIBRARY_PATH="/run/opengl-driver/lib"
76+
else
77+
export LD_LIBRARY_PATH="/run/opengl-driver/lib:$LD_LIBRARY_PATH"
78+
fi
79+
fi
80+
# Vulkan loader for h264_vulkan, hevc_vulkan, av1_vulkan encoders
81+
export LD_LIBRARY_PATH="${pkgs.vulkan-loader}/lib:$LD_LIBRARY_PATH"
82+
# Intel media driver and oneVPL runtime for QuickSync
83+
export LD_LIBRARY_PATH="${pkgs.intel-media-driver}/lib:$LD_LIBRARY_PATH"
84+
export LD_LIBRARY_PATH="${pkgs.vpl-gpu-rt}/lib:$LD_LIBRARY_PATH"
85+
export ONEVPL_SEARCH_PATH="${pkgs.vpl-gpu-rt}/lib"
86+
87+
# Vulkan ICD discovery: tell vulkan-loader where to find GPU drivers
88+
# NixOS installs ICDs under /run/opengl-driver/share/vulkan/icd.d/
89+
if [ -d "/run/opengl-driver/share/vulkan/icd.d" ]; then
90+
export VK_DRIVER_FILES=$(find /run/opengl-driver/share/vulkan/icd.d -name '*.json' 2>/dev/null | tr '\n' ':' | sed 's/:$//')
91+
fi
6192
'';
6293
};
6394
}

0 commit comments

Comments
 (0)