From bcfc38c504f0b12dbc54fb5150cdb296faccc143 Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Tue, 5 May 2026 16:00:16 +0100 Subject: [PATCH] infra: replace nixGL with a host GL wrapper Change-Id: I61144c78e6b4b661d346307de2f51c7e6a6a6964 --- flake.lock | 67 +++-------------------------- flake.nix | 10 +---- modules/home/auto-upgrade.nix | 3 +- modules/home/gl.nix | 79 ++++++++++++++++++++++++----------- modules/home/niri/default.nix | 2 +- 5 files changed, 64 insertions(+), 97 deletions(-) diff --git a/flake.lock b/flake.lock index 46f7f48..cdc7bd2 100644 --- a/flake.lock +++ b/flake.lock @@ -302,24 +302,6 @@ } }, "flake-utils": { - "inputs": { - "systems": "systems_5" - }, - "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_2": { "inputs": { "systems": [ "starship-jj", @@ -340,9 +322,9 @@ "type": "github" } }, - "flake-utils_3": { + "flake-utils_2": { "inputs": { - "systems": "systems_8" + "systems": "systems_7" }, "locked": { "lastModified": 1681202837, @@ -628,27 +610,6 @@ "type": "github" } }, - "nixgl": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1762090880, - "narHash": "sha256-fbRQzIGPkjZa83MowjbD2ALaJf9y6KMDdJBQMKFeY/8=", - "owner": "nix-community", - "repo": "nixGL", - "rev": "b6105297e6f0cd041670c3e8628394d4ee247ed5", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "nixGL", - "type": "github" - } - }, "nixpkgs": { "locked": { "lastModified": 1772173633, @@ -765,7 +726,7 @@ "nixpkgs": [ "nixpkgs" ], - "systems": "systems_6" + "systems": "systems_5" }, "locked": { "lastModified": 1772402258, @@ -835,7 +796,6 @@ "niri": "niri", "nix-darwin": "nix-darwin", "nix-minecraft": "nix-minecraft", - "nixgl": "nixgl", "nixpkgs": "nixpkgs_3", "nixpkgs-watchman": "nixpkgs-watchman", "nixvim": "nixvim", @@ -865,11 +825,11 @@ "starship-jj": { "inputs": { "fenix": "fenix", - "flake-utils": "flake-utils_2", + "flake-utils": "flake-utils", "nixpkgs": [ "nixpkgs" ], - "systems": "systems_7" + "systems": "systems_6" }, "locked": { "lastModified": 1771062192, @@ -990,21 +950,6 @@ "type": "github" } }, - "systems_8": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, "treefmt-nix": { "inputs": { "nixpkgs": [ @@ -1049,7 +994,7 @@ }, "vscode-server": { "inputs": { - "flake-utils": "flake-utils_3", + "flake-utils": "flake-utils_2", "nixpkgs": [ "nixpkgs" ] diff --git a/flake.nix b/flake.nix index 00f0031..e412b65 100644 --- a/flake.nix +++ b/flake.nix @@ -37,9 +37,6 @@ vscode-server.url = "github:nix-community/nixos-vscode-server"; vscode-server.inputs.nixpkgs.follows = "nixpkgs"; - nixgl.url = "github:nix-community/nixGL"; - nixgl.inputs.nixpkgs.follows = "nixpkgs"; - disko.url = "github:nix-community/disko/latest"; disko.inputs.nixpkgs.follows = "nixpkgs"; @@ -73,7 +70,7 @@ inputs.nixpkgs.follows = "nixpkgs"; }; nixpkgs-watchman.url = "github:NixOS/nixpkgs/09061f748ee21f68a089cd5d91ec1859cd93d0be"; -}; + }; outputs = { @@ -83,17 +80,12 @@ ... }@inputs: let - overlays = [ - inputs.nixgl.overlay - ]; pkgs-x86_64 = import nixpkgs { system = "x86_64-linux"; - inherit overlays; config.allowUnfree = true; }; pkgs-aarch64-darwin = import nixpkgs { system = "aarch64-darwin"; - inherit overlays; config.allowUnfree = true; }; in diff --git a/modules/home/auto-upgrade.nix b/modules/home/auto-upgrade.nix index e900aa9..897be29 100644 --- a/modules/home/auto-upgrade.nix +++ b/modules/home/auto-upgrade.nix @@ -16,10 +16,9 @@ services.home-manager-auto-upgrade = { Unit.Description = "Home Manager upgrade"; - # --impure and NIXPKGS_ALLOW_UNFRAME=1 are required due to nixGL; see https://github.com/nix-community/nixGL/issues/90 Service.ExecStart = toString ( pkgs.writeShellScript "home-manager-auto-upgrade" '' - PATH=$PATH:${pkgs.nix}/bin NIXPKGS_ALLOW_UNFREE=1 ${pkgs.home-manager}/bin/home-manager switch --flake git+ssh://git@knot.starhaven.dev/bates64.com/infra --impure + PATH=$PATH:${pkgs.nix}/bin ${pkgs.home-manager}/bin/home-manager switch --flake git+ssh://git@knot.starhaven.dev/bates64.com/infra '' ); }; diff --git a/modules/home/gl.nix b/modules/home/gl.nix index 0955370..dc3c80e 100644 --- a/modules/home/gl.nix +++ b/modules/home/gl.nix @@ -1,32 +1,63 @@ -{ config, osConfig ? null, pkgs, lib, ... }: +{ + config, + osConfig ? null, + pkgs, + lib, + ... +}: let - # https://github.com/nix-community/nixGL # Only wrap when running standalone home-manager on a non-NixOS Linux distro; # NixOS and nix-darwin provide working GL drivers natively. - useNixGL = osConfig == null && !config.isMacOS; - wrapGL = { name, package }: # wrap a package's bins with nixGL - if useNixGL - then pkgs.runCommand "${name}-wrapped" { - meta.mainProgram = name; - } '' - mkdir -p $out - cp -r ${package}/* $out - - # wrap every binary with nixGL - mv $out/bin $out/oldbin - mkdir $out/bin - for file in "$out/oldbin"/*; do - filename=$(basename "$file") - newfile="$out/bin/$filename" + useHostGL = osConfig == null && !config.isMacOS; + glWrapperPackage = + if useHostGL then + pkgs.writeShellScriptBin "host-gl" '' + if [ -f /usr/share/glvnd/egl_vendor.d/10_nvidia.json ]; then + export __EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/10_nvidia.json + fi - echo "#!${pkgs.runtimeShell}" > "$newfile" - echo "exec ${pkgs.nixgl.auto.nixGLDefault}/bin/nixGL \"$file\" \"\$@\"" >> "$newfile" - chmod +x "$newfile" - done - '' - else package; -in { + if [ -f /usr/share/vulkan/icd.d/nvidia_icd.json ]; then + export VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/nvidia_icd.json + elif [ -f /etc/vulkan/icd.d/nvidia_icd.json ]; then + export VK_ICD_FILENAMES=/etc/vulkan/icd.d/nvidia_icd.json + fi + + exec "$@" + '' + else + null; + wrapGL = + { name, package }: # wrap a package's bins with the host GL stack + if useHostGL then + pkgs.runCommand "${name}-wrapped" + { + meta.mainProgram = name; + } + '' + mkdir -p $out + cp -r ${package}/* $out + + # wrap every binary with the host GL launcher + mv $out/bin $out/oldbin + mkdir $out/bin + for file in "$out/oldbin"/*; do + filename=$(basename "$file") + newfile="$out/bin/$filename" + + echo "#!${pkgs.runtimeShell}" > "$newfile" + echo "exec ${glWrapperPackage}/bin/host-gl \"$file\" \"\$@\"" >> "$newfile" + chmod +x "$newfile" + done + '' + else + package; +in +{ options = { + glWrapperPackage = lib.mkOption { + type = with lib.types; nullOr package; + default = glWrapperPackage; + }; wrapGL = lib.mkOption { type = lib.types.functionTo lib.types.package; default = wrapGL; diff --git a/modules/home/niri/default.nix b/modules/home/niri/default.nix index 9eb0d2c..c08ec4f 100644 --- a/modules/home/niri/default.nix +++ b/modules/home/niri/default.nix @@ -42,7 +42,7 @@ in }; systemd.user.services.noctalia-shell = lib.mkIf (!isNixOS) { - Service.ExecStart = lib.mkForce "${pkgs.nixgl.auto.nixGLDefault}/bin/nixGL ${config.programs.noctalia-shell.package}/bin/noctalia-shell"; + Service.ExecStart = lib.mkForce "${config.glWrapperPackage}/bin/host-gl ${config.programs.noctalia-shell.package}/bin/noctalia-shell"; }; }; } -- 2.51.2