Last active
November 28, 2024 02:18
-
-
Save kesor/935c10405d090d016555f2b42421766d to your computer and use it in GitHub Desktop.
A function to wrap home-manager packages in environment variable setting shell script
This file contains hidden or 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
{ lib, pkgs, ... }: | |
let | |
# Function to wrap a package with custom environment variables | |
makeWrappedPackage = pkg: envVars: pkgs.stdenv.mkDerivation { | |
name = "env-wrap-${pkg.name}"; | |
nativeBuildInputs = [ pkgs.makeWrapper ]; | |
buildCommand = '' | |
mkdir -p $out/bin | |
for exe in ${lib.getExe pkg}; do | |
exeName=$(basename "$exe") | |
makeWrapper "$exe" "$out/bin/$exeName" \ | |
${lib.concatMapStringsSep " " (kv: "--set ${kv.name} ${kv.value}") (lib.attrsToList envVars)} | |
done | |
''; | |
}; | |
in { | |
wrap = pkg: envVars: makeWrappedPackage pkg envVars; | |
} |
This file contains hidden or 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
# Example of usage in home.nix | |
{ config, lib, pkgs, ... }: | |
let | |
envVarsWrapper = import ./lib/nix-env-vars-wrapper.nix { inherit lib pkgs; }; | |
in with pkgs; { | |
home.packages = [ | |
(envVarsWrapper.wrap qjackctl { | |
LD_LIBRARY_PATH = "${config.home.profileDirectory}/lib"; | |
}) | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment