-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The option allows packages to be wrapped by nixgl in order to make GUI applications work when installed with home-manager
- Loading branch information
Michael Vogel
committed
Apr 25, 2024
1 parent
bfa7c06
commit 2fc2d54
Showing
2 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
{ config, pkgs, lib, ... }: | ||
|
||
let | ||
cfg = config.workarounds.nixgl; | ||
|
||
# Expects a PackageConfiguration hashset | ||
# Adapted from https://nixos.wiki/wiki/Nix_Cookbook | ||
wrapWithNixGL = { binary, pkg, ... }: | ||
(let | ||
bin = if binary == null then pkg.pname else binary; | ||
nixGL = import cfg.src { inherit pkgs; }; | ||
wrapperPkg = lib.attrsets.getAttrFromPath cfg.wrapperPkgPath nixGL; | ||
wrapperBinPath = "${wrapperPkg}/bin/${cfg.wrapperBinName}"; | ||
in pkgs.runCommand "nixgl-${pkg.pname}" { | ||
buildInputs = [ pkgs.makeWrapper ]; | ||
} '' | ||
mkdir $out | ||
# Link every top-level folder from pkgs.hello to our new target | ||
ln -s ${pkg}/* $out | ||
# Except the bin folder | ||
rm $out/bin | ||
mkdir $out/bin | ||
# We create the bin folder ourselves and link every binary in it | ||
ln -s ${pkg}/bin/* $out/bin | ||
# Except the target binary | ||
rm $out/bin/${bin} | ||
# Because we create this ourself, by creating a wrapper | ||
makeWrapper ${wrapperBinPath} $out/bin/${bin} \ | ||
--add-flags ${pkg}/bin/${bin} | ||
''); | ||
PackageConfiguration = with lib; | ||
types.submodule { | ||
options = { | ||
binary = mkOption { | ||
type = types.nullOr types.str; | ||
example = "alacritty"; | ||
default = null; | ||
description = '' | ||
Name of the binary in bin/ of the package. | ||
By default this uses `package.pname`. | ||
''; | ||
}; | ||
pkg = mkOption { | ||
type = types.package; | ||
example = "pkgs.alacritty"; | ||
description = '' | ||
The package to be wrapped. | ||
It's expected to have a `pname` attribute. | ||
''; | ||
}; | ||
}; | ||
}; | ||
in { | ||
meta.maintainers = with lib.maintainers; [ michaelCTS ]; | ||
options.workarounds.nixgl = { | ||
src = lib.mkOption { | ||
type = lib.types.package; | ||
default = builtins.fetchTarball | ||
"https://github.com/nix-community/nixGL/archive/main.tar.gz"; | ||
example = '' | ||
pkgs.fetchFromGithub { | ||
owner = "nix-community"; | ||
repo = "nixGL"; | ||
rev = "v1.3"; | ||
hash = "SOMEHASH-HERE"; | ||
} | ||
''; | ||
description = '' | ||
Path to a downloaded source of nixGL. | ||
You can download the nixGL version of your choice and point to it here. | ||
''; | ||
}; | ||
wrapperBinName = lib.mkOption { | ||
type = lib.types.str; | ||
example = "nixGL"; | ||
default = "nixGL"; | ||
description = | ||
"Name of the nixGL binary to be called from within the wrapper package"; | ||
}; | ||
wrapperPkgPath = lib.mkOption { | ||
type = lib.types.listOf lib.types.str; | ||
example = ''["auto" "nixGLNvidia"]''; | ||
default = [ "auto" "nixGLDefault" ]; | ||
description = "Attribute path within `src` attrset to the nixGL package"; | ||
}; | ||
packages = lib.mkOption { | ||
type = lib.types.listOf PackageConfiguration; | ||
default = [ ]; | ||
example = "[{ pkg = pkgs.alacritty; }]"; | ||
description = '' | ||
List of packages that will be wrapped with nixGL in order to be able to use nixgl. | ||
Without the wrapper, graphical applications cannot access nixgl and thus have no | ||
graphical acceleration. | ||
''; | ||
}; | ||
}; | ||
|
||
config = { | ||
home.packages = | ||
builtins.map wrapWithNixGL config.workarounds.nixgl.packages; | ||
}; | ||
} | ||
|