diff --git a/configs/fedora/home.nix b/configs/fedora/home.nix index 47e5a03..8b8a7e7 100644 --- a/configs/fedora/home.nix +++ b/configs/fedora/home.nix @@ -1,6 +1,8 @@ -{ ... }: +{ pkgs, config, lib, inputs, ... }: -{ +let + nixGL = import ./../../home-manager/utils/nixGLWrap.nix { inherit pkgs config; }; +in { imports = [ ./../../home-manager/modules/machine.nix ]; machine = { @@ -14,4 +16,11 @@ fonts.fontconfig.enable = true; nixpkgs.config.allowUnfree = true; + + nixGLPrefix = lib.getExe pkgs.nixgl.nixGLIntel; + + home.packages = with pkgs; [ + (nixGL insomnia) + (nixGL inputs.muse-sounds-manager.packages.x86_64-linux.muse-sounds-manager) + ]; } diff --git a/home-manager/modules/machine.nix b/home-manager/modules/machine.nix index 7a40cfc..0083974 100644 --- a/home-manager/modules/machine.nix +++ b/home-manager/modules/machine.nix @@ -55,6 +55,15 @@ with lib; { description = "Whether to enable noise suppression or not"; }; }; + nixGLPrefix = lib.mkOption { + type = lib.types.str; + default = ""; + description = '' + Will be prepended to commands which require working OpenGL. + + This needs to be set to the right nixGL package on non-NixOS systems. + ''; + }; }; config = { diff --git a/home-manager/utils/nixGLWrap.nix b/home-manager/utils/nixGLWrap.nix index 59556f5..ae3f199 100644 --- a/home-manager/utils/nixGLWrap.nix +++ b/home-manager/utils/nixGLWrap.nix @@ -1,17 +1,37 @@ -{ pkgs, lib, ... }: +# Call once on import to load global context +{ + pkgs, + config, +}: +# Wrap a single package +pkg: +if config.nixGLPrefix == "" +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}"; + buildCommand = '' + set -eo pipefail -let nixgl = import { }; -in pkg: -pkgs.runCommand "${pkg.name}-nixgl-wrapper" { } '' - mkdir $out - ln -s ${pkg}/* $out - rm $out/bin - mkdir $out/bin - for bin in ${pkg}/bin/*; do - wrapped_bin=$out/bin/$(basename $bin) - echo -e "#!/bin/bash\nexec ${ - lib.getExe nixgl.auto.nixGLDefault - } $bin \$@" > $wrapped_bin - chmod +x $wrapped_bin - done -'' + ${ + # 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 + echo "#!${pkgs.bash}/bin/bash" > "$out/bin/$(basename $file)" + echo "exec -a \"\$0\" ${config.nixGLPrefix} $file \"\$@\"" >> "$out/bin/$(basename $file)" + chmod +x "$out/bin/$(basename $file)" + done + shopt -u nullglob # Revert nullglob back to its normal default state + ''; + })) \ No newline at end of file