2024-04-30 02:37:24 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let cfg = config.nixGL;
|
|
|
|
in {
|
|
|
|
meta.maintainers = [ lib.maintainers.smona ];
|
|
|
|
|
|
|
|
options.nixGL.prefix = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "";
|
|
|
|
example = lib.literalExpression
|
|
|
|
''"''${inputs.nixGL.packages.x86_64-linux.nixGLIntel}/bin/nixGLIntel"'';
|
|
|
|
description = ''
|
|
|
|
The nixGL command that `lib.nixGL.wrap` should wrap packages with.
|
|
|
|
This can be used to provide libGL access to applications on non-NixOS systems.
|
|
|
|
|
2024-06-20 01:35:53 +02:00
|
|
|
Wrap individual packages like so: `(config.lib.nixGL.wrap <package>)`. The returned package
|
|
|
|
can be used just like the original one, but will have access to libGL. If this option is empty (the default),
|
|
|
|
then `lib.nixGL.wrap` is a no-op. This is useful on NixOS, where the wrappers are unnecessary.
|
2024-04-30 02:37:24 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
lib.nixGL.wrap = # Wrap a single package with the configured nixGL wrapper
|
|
|
|
pkg:
|
|
|
|
|
|
|
|
if cfg.prefix == "" then
|
|
|
|
pkg
|
|
|
|
else
|
|
|
|
# Wrap the package's binaries with nixGL, while preserving the rest of
|
|
|
|
# the outputs and derivation attributes.
|
|
|
|
(pkg.overrideAttrs (old: {
|
|
|
|
name = "nixGL-${pkg.name}";
|
|
|
|
|
|
|
|
# Make sure this is false for the wrapper derivation, so nix doesn't expect
|
|
|
|
# a new debug output to be produced. We won't be producing any debug info
|
|
|
|
# for the original package.
|
|
|
|
separateDebugInfo = false;
|
2024-06-27 04:16:22 +02:00
|
|
|
nativeBuildInputs = old.nativeBuildInputs or [ ] ++ [ pkgs.makeWrapper ];
|
2024-04-30 02:37:24 +02:00
|
|
|
buildCommand = ''
|
|
|
|
set -eo pipefail
|
|
|
|
|
|
|
|
${
|
|
|
|
# Heavily inspired by https://stackoverflow.com/a/68523368/6259505
|
|
|
|
pkgs.lib.concatStringsSep "\n" (map (outputName: ''
|
|
|
|
echo "Copying output ${outputName}"
|
|
|
|
set -x
|
|
|
|
cp -rs --no-preserve=mode "${
|
|
|
|
pkg.${outputName}
|
|
|
|
}" "''$${outputName}"
|
|
|
|
set +x
|
|
|
|
'') (old.outputs or [ "out" ]))}
|
|
|
|
|
|
|
|
rm -rf $out/bin/*
|
|
|
|
shopt -s nullglob # Prevent loop from running if no files
|
|
|
|
for file in ${pkg.out}/bin/*; do
|
2024-06-20 01:35:53 +02:00
|
|
|
local prog="$(basename "$file")"
|
|
|
|
makeWrapper \
|
|
|
|
"${cfg.prefix}" \
|
|
|
|
"$out/bin/$prog" \
|
|
|
|
--argv0 "$prog" \
|
|
|
|
--add-flags "$file"
|
2024-04-30 02:37:24 +02:00
|
|
|
done
|
2024-06-20 01:25:56 +02:00
|
|
|
|
|
|
|
# If .desktop files refer to the old package, replace the references
|
|
|
|
for dsk in "$out/share/applications"/*.desktop ; do
|
2024-06-27 04:14:08 +02:00
|
|
|
if ! grep -q "${pkg.out}" "$dsk"; then
|
2024-06-20 01:25:56 +02:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
src="$(readlink "$dsk")"
|
|
|
|
rm "$dsk"
|
|
|
|
sed "s|${pkg.out}|$out|g" "$src" > "$dsk"
|
|
|
|
done
|
|
|
|
|
2024-04-30 02:37:24 +02:00
|
|
|
shopt -u nullglob # Revert nullglob back to its normal default state
|
|
|
|
'';
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
}
|