{ lib, symlinkJoin, writeTextFile, writeShellScriptBin }: let inherit (lib) concatStrings mapAttrsToList; in rec { configure = pkg: wrapped: (symlinkJoin { name = "${pkg.name}-configured"; paths = [ wrapped pkg ]; }).overrideAttrs (oldAttrs: { passthru = pkg.passthru or {}; }) // { unconfigured = pkg; }; addFlags = pkg: bin: flags: configure pkg (writeShellScriptBin bin '' exec ${pkg}/bin/${bin} ${flags} "$@" ''); setEnv = pkg: bin: env: configure pkg (writeShellScriptBin bin ((concatStrings (mapAttrsToList (name: value: "export ${name}=${value}\n") env)) + '' exec ${pkg}/bin/${bin} "$@" '') ); xdgConfig = { package, executable, path, text }: setEnv package executable { XDG_CONFIG_HOME = writeTextFile { name = "${package.name}-config"; destination = "/${path}"; inherit text; }; }; }