Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/stdenv/stdenv.chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ makeWrapper $out/bin/foo $wrapperfile --set FOOBAR baz
makeWrapper $out/bin/foo $wrapperfile --prefix PATH : ${lib.makeBinPath [ hello git ]}
```

There’s many more kinds of arguments, they are documented in `nixpkgs/pkgs/build-support/setup-hooks/make-wrapper.sh` for the `makeWrapper` implementation and in `nixpkgs/pkgs/build-support/setup-hooks/make-binary-wrapper.sh` for the `makeBinaryWrapper` implementation.
There’s many more kinds of arguments, they are documented in `nixpkgs/pkgs/build-support/setup-hooks/make-wrapper.sh` for the `makeWrapper` implementation and in `nixpkgs/pkgs/build-support/setup-hooks/make-binary-wrapper/make-binary-wrapper.sh` for the `makeBinaryWrapper` implementation.

`wrapProgram` is a convenience function you probably want to use most of the time, implemented by both `makeWrapper` and `makeBinaryWrapper`.

Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/editors/neovim/utils.nix
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ let
hostprog_check_table);
in
[
"--argv0" "$0" "--add-flags" (lib.escapeShellArgs flags)
"--inherit-argv0" "--add-flags" (lib.escapeShellArgs flags)
] ++ lib.optionals withRuby [
"--set" "GEM_HOME" "${rubyEnv}/${rubyEnv.ruby.gemPath}"
] ++ lib.optionals (binPath != "") [
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/editors/vscode/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ let
++ lib.optionals stdenv.isLinux [
autoPatchelfHook
nodePackages.asar
(wrapGAppsHook.override { makeBinaryWrapper = makeWrapper; })
(wrapGAppsHook.override { inherit makeWrapper; })
];

dontBuild = true;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/networking/browsers/brave/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ stdenv.mkDerivation rec {

nativeBuildInputs = [
dpkg
(wrapGAppsHook.override { makeBinaryWrapper = makeWrapper; })
(wrapGAppsHook.override { inherit makeWrapper; })
];

buildInputs = [
Expand Down
9 changes: 3 additions & 6 deletions pkgs/applications/networking/browsers/firefox/wrapper.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, lib, makeDesktopItem, makeWrapper, lndir, config
{ stdenv, lib, makeDesktopItem, makeWrapper, makeBinaryWrapper, lndir, config
, fetchurl, zip, unzip, jq, xdg-utils, writeText

## various stuff that can be plugged in
Expand Down Expand Up @@ -229,18 +229,15 @@ let
# Symbolic link: wrap the link's target.
oldExe="$(readlink -v --canonicalize-existing "$executablePath")"
rm "$executablePath"
elif wrapperCmd=$(strings -dw "$executablePath" | sed -n '/^makeCWrapper/,/^$/ p'); [[ $wrapperCmd ]]; then
elif wrapperCmd=$(${makeBinaryWrapper.extractCmd} "$executablePath"); [[ $wrapperCmd ]]; then
# If the executable is a binary wrapper, we need to update its target to
# point to $out, but we can't just edit the binary in-place because of length
# issues. So we extract the command used to create the wrapper and add the
# arguments to our wrapper.
parseMakeCWrapperCall() {
shift # makeCWrapper
oldExe=$1; shift
for arg do case $arg in
--inherit-argv0) oldWrapperArgs+=(--argv0 '$0');; # makeWrapper doesn't understand --inherit-argv0
*) oldWrapperArgs+=("$arg");;
esac done
oldWrapperArgs=("$@")
}
eval "parseMakeCWrapperCall ''${wrapperCmd//"${browser}"/"$out"}"
rm "$executablePath"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ pname, version, src, meta, binaryName, desktopName, autoPatchelfHook
, makeDesktopItem, lib, stdenv, wrapGAppsHook, makeWrapper, alsa-lib, at-spi2-atk
, makeDesktopItem, lib, stdenv, wrapGAppsHook, makeShellWrapper, alsa-lib, at-spi2-atk
, at-spi2-core, atk, cairo, cups, dbus, expat, fontconfig, freetype, gdk-pixbuf
, glib, gtk3, libcxx, libdrm, libnotify, libpulseaudio, libuuid, libX11
, libXScrnSaver, libXcomposite, libXcursor, libXdamage, libXext, libXfixes
Expand All @@ -24,7 +24,8 @@ stdenv.mkDerivation rec {
libxshmfence
mesa
nss
(wrapGAppsHook.override { makeBinaryWrapper = makeWrapper; })
wrapGAppsHook
makeShellWrapper
];

dontWrapGApps = true;
Expand Down Expand Up @@ -78,7 +79,7 @@ stdenv.mkDerivation rec {
patchelf --set-interpreter ${stdenv.cc.bintools.dynamicLinker} \
$out/opt/${binaryName}/${binaryName}

wrapProgram $out/opt/${binaryName}/${binaryName} \
wrapProgramShell $out/opt/${binaryName}/${binaryName} \
"''${gappsWrapperArgs[@]}" \
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--enable-features=UseOzonePlatform --ozone-platform=wayland}}" \
--prefix XDG_DATA_DIRS : "${gtk3}/share/gsettings-schemas/${gtk3.name}/" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ in stdenv.mkDerivation rec {
nativeBuildInputs = [
autoPatchelfHook
dpkg
(wrapGAppsHook.override { makeBinaryWrapper = makeWrapper; })
(wrapGAppsHook.override { inherit makeWrapper; })
];

buildInputs = [
Expand Down
8 changes: 4 additions & 4 deletions pkgs/applications/science/logic/tlaplus/toolbox.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ lib
, fetchzip
, makeWrapper
, makeShellWrapper
, makeDesktopItem
, stdenv
, gtk3
Expand Down Expand Up @@ -35,8 +35,8 @@ stdenv.mkDerivation rec {
buildInputs = [ gtk3 ];

nativeBuildInputs = [
makeWrapper
(wrapGAppsHook.override { makeBinaryWrapper = makeWrapper; })
makeShellWrapper
wrapGAppsHook
];

dontWrapGApps = true;
Expand Down Expand Up @@ -64,7 +64,7 @@ stdenv.mkDerivation rec {
--set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
"$(find "$out/toolbox" -name jspawnhelper)"

makeWrapper $out/toolbox/toolbox $out/bin/tla-toolbox \
makeShellWrapper $out/toolbox/toolbox $out/bin/tla-toolbox \
--chdir "$out/toolbox" \
--add-flags "-data ~/.tla-toolbox" \
--prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath [ gtk3 libXtst glib zlib ]}" \
Expand Down
4 changes: 2 additions & 2 deletions pkgs/applications/video/mpv/wrapper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let
# All arguments besides the input and output binaries (${mpv}/bin/mpv and
# $out/bin/mpv). These are used by the darwin specific makeWrapper call
# used to wrap $out/Applications/mpv.app/Contents/MacOS/mpv as well.
mostMakeWrapperArgs = lib.strings.escapeShellArgs ([ "--argv0" "'$0'"
mostMakeWrapperArgs = lib.strings.escapeShellArgs ([ "--inherit-argv0"
# These are always needed (TODO: Explain why)
"--prefix" "LUA_CPATH" ";" "${mpv.luaEnv}/lib/lua/${mpv.lua.luaversion}/?.so"
"--prefix" "LUA_PATH" ";" "${mpv.luaEnv}/share/lua/${mpv.lua.luaversion}/?.lua"
Expand All @@ -53,7 +53,7 @@ let
)) ++ extraMakeWrapperArgs)
;
umpvWrapperArgs = lib.strings.escapeShellArgs ([
"--argv0" "'$0'"
"--inherit-argv0"
"--set" "MPV" "${placeholder "out"}/bin/mpv"
] ++ extraUmpvWrapperArgs)
;
Expand Down
27 changes: 27 additions & 0 deletions pkgs/build-support/setup-hooks/make-binary-wrapper/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{ stdenv
, lib
, darwin
, makeSetupHook
, dieHook
, writeShellScript
, tests
, cc ? stdenv.cc
, sanitizers ? []
}:

makeSetupHook {
deps = [ dieHook ]
# https://github.com/NixOS/nixpkgs/issues/148189
++ lib.optional (stdenv.isDarwin && stdenv.isAarch64) darwin.cctools;

substitutions = {
cc = "${cc}/bin/cc ${lib.escapeShellArgs (map (s: "-fsanitize=${s}") sanitizers)}";

# Extract the function call used to create a binary wrapper from its embedded docstring
passthru.extractCmd = writeShellScript "extract-binary-wrapper-cmd" ''
strings -dw "$1" | sed -n '/^makeCWrapper/,/^$/ p'
'';

passthru.tests = tests.makeBinaryWrapper;
};
} ./make-binary-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,25 @@ assertExecutable() {
# makeWrapper EXECUTABLE OUT_PATH ARGS

# ARGS:
# --argv0 NAME : set name of executed process to NAME
# (otherwise it’s called …-wrapped)
# --argv0 NAME : set the name of the executed process to NAME
# (if unset or empty, defaults to EXECUTABLE)
# --inherit-argv0 : the executable inherits argv0 from the wrapper.
# (use instead of --argv0 '$0')
# --set VAR VAL : add VAR with value VAL to the executable’s
# environment
# --set VAR VAL : add VAR with value VAL to the executable's environment
# --set-default VAR VAL : like --set, but only adds VAR if not already set in
# the environment
# --unset VAR : remove VAR from the environment
# --chdir DIR : change working directory (use instead of --run "cd DIR")
# --add-flags FLAGS : add FLAGS to invocation of executable
# TODO(@ncfavier): --append-flags

# --prefix ENV SEP VAL : suffix/prefix ENV with VAL, separated by SEP
# --suffix

# To troubleshoot a binary wrapper after you compiled it,
# use the `strings` command or open the binary file in a text editor.
makeWrapper() {
makeWrapper() { makeBinaryWrapper "$@"; }
makeBinaryWrapper() {
local NIX_CFLAGS_COMPILE= NIX_CFLAGS_LINK=
local original="$1"
local wrapper="$2"
Expand All @@ -43,7 +44,7 @@ makeWrapper() {
mkdir -p "$(dirname "$wrapper")"

makeDocumentedCWrapper "$original" "$@" | \
@CC@ \
@cc@ \
-Wall -Werror -Wpedantic \
-Wno-overlength-strings \
-Os \
Expand All @@ -52,7 +53,8 @@ makeWrapper() {
}

# Syntax: wrapProgram <PROGRAM> <MAKE-WRAPPER FLAGS...>
wrapProgram() {
wrapProgram() { wrapProgramBinary "$@"; }
wrapProgramBinary() {
local prog="$1"
local hidden

Expand All @@ -63,8 +65,6 @@ wrapProgram() {
hidden="${hidden}_"
done
mv "$prog" "$hidden"
# Silence warning about unexpanded $0:
# shellcheck disable=SC2016
makeWrapper "$hidden" "$prog" --inherit-argv0 "${@:2}"
}

Expand Down Expand Up @@ -311,8 +311,9 @@ void set_env_suffix(char *env, char *sep, char *suffix) {
"
}

# Embed a C string which shows up as readable text in the compiled binary wrapper
# documentationString ARGS
# Embed a C string which shows up as readable text in the compiled binary wrapper,
# giving instructions for recreating the wrapper.
# Keep in sync with makeBinaryWrapper.extractCmd
docstring() {
printf '%s' "const char * DOCSTRING = \"$(escapeStringLiteral "

Expand All @@ -333,7 +334,7 @@ makeCWrapper $(formatArgs "$@")

# formatArgs EXECUTABLE ARGS
formatArgs() {
printf '%s' "$1"
printf '%s' "${1@Q}"
shift
while [ $# -gt 0 ]; do
case "$1" in
Expand Down
23 changes: 14 additions & 9 deletions pkgs/build-support/setup-hooks/make-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ assertExecutable() {
# makeWrapper EXECUTABLE OUT_PATH ARGS

# ARGS:
# --argv0 NAME : set name of executed process to NAME
# (otherwise it’s called …-wrapped)
# --set VAR VAL : add VAR with value VAL to the executable’s
# environment
# --argv0 NAME : set the name of the executed process to NAME
# (if unset or empty, defaults to EXECUTABLE)
# --inherit-argv0 : the executable inherits argv0 from the wrapper.
# (use instead of --argv0 '$0')
# --set VAR VAL : add VAR with value VAL to the executable's environment
# --set-default VAR VAL : like --set, but only adds VAR if not already set in
# the environment
# --unset VAR : remove VAR from the environment
# --chdir DIR : change working directory (use instead of --run "cd DIR")
# --run COMMAND : run command before the executable
# --add-flags FLAGS : add FLAGS to invocation of executable
# TODO(@ncfavier): --append-flags

# --prefix ENV SEP VAL : suffix/prefix ENV with VAL, separated by SEP
# --suffix
Expand All @@ -29,7 +31,8 @@ assertExecutable() {
# --prefix-contents ENV SEP FILES : like --suffix-each, but contents of FILES
# are read first and used as VALS
# --suffix-contents
makeWrapper() {
makeWrapper() { makeShellWrapper "$@"; }
makeShellWrapper() {
local original="$1"
local wrapper="$2"
local params varName value command separator n fileNames
Expand Down Expand Up @@ -165,6 +168,9 @@ makeWrapper() {
elif [[ "$p" == "--argv0" ]]; then
argv0="${params[$((n + 1))]}"
n=$((n + 1))
elif [[ "$p" == "--inherit-argv0" ]]; then
# Whichever comes last of --argv0 and --inherit-argv0 wins
argv0='$0'
else
die "makeWrapper doesn't understand the arg $p"
fi
Expand Down Expand Up @@ -193,7 +199,8 @@ filterExisting() {
}

# Syntax: wrapProgram <PROGRAM> <MAKE-WRAPPER FLAGS...>
wrapProgram() {
wrapProgram() { wrapProgramShell "$@"; }
wrapProgramShell() {
local prog="$1"
local hidden

Expand All @@ -204,7 +211,5 @@ wrapProgram() {
hidden="${hidden}_"
done
mv "$prog" "$hidden"
# Silence warning about unexpanded $0:
# shellcheck disable=SC2016
makeWrapper "$hidden" "$prog" --argv0 '$0' "${@:2}"
makeWrapper "$hidden" "$prog" --inherit-argv0 "${@:2}"
}
4 changes: 2 additions & 2 deletions pkgs/build-support/setup-hooks/wrap-gapps-hook/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ stdenv
, lib
, makeSetupHook
, makeBinaryWrapper
, makeWrapper
, gobject-introspection
, isGraphical ? true
, gtk3
Expand Down Expand Up @@ -34,7 +34,7 @@ makeSetupHook {
] ++ [

# We use the wrapProgram function.
makeBinaryWrapper
makeWrapper
];
substitutions = {
passthru.tests = let
Expand Down
10 changes: 9 additions & 1 deletion pkgs/test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@ with pkgs;

dhall = callPackage ./dhall { };

makeWrapper = callPackage ./make-wrapper {};
makeWrapper = callPackage ./make-wrapper { };
makeBinaryWrapper = callPackage ./make-binary-wrapper {
makeBinaryWrapper = pkgs.makeBinaryWrapper.override {
# Enable sanitizers in the tests only, to avoid the performance cost in regular usage.
# The sanitizers cause errors on aarch64-darwin, see https://github.com/NixOS/nixpkgs/pull/150079#issuecomment-994132734
sanitizers = pkgs.lib.optionals (! (pkgs.stdenv.isDarwin && pkgs.stdenv.isAarch64))
[ "undefined" "address" ];
};
};

pkgs-lib = recurseIntoAttrs (import ../pkgs-lib/tests { inherit pkgs; });
}
8 changes: 4 additions & 4 deletions pkgs/tools/security/cryptomator/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ lib, stdenv, fetchFromGitHub
, autoPatchelfHook
, fuse, jffi
, maven, jdk, jre, makeWrapper, glib, wrapGAppsHook
, maven, jdk, jre, makeShellWrapper, glib, wrapGAppsHook
}:

let
Expand Down Expand Up @@ -65,7 +65,7 @@ in stdenv.mkDerivation rec {
rm $out/share/cryptomator/libs/jff*.jar
cp -f ${jffi}/share/java/jffi-complete.jar $out/share/cryptomator/libs/

makeWrapper ${jre}/bin/java $out/bin/cryptomator \
makeShellWrapper ${jre}/bin/java $out/bin/cryptomator \
--add-flags "--class-path '$out/share/cryptomator/libs/*'" \
--add-flags "--module-path '$out/share/cryptomator/mods'" \
--add-flags "-Dcryptomator.logDir='~/.local/share/Cryptomator/logs'" \
Expand Down Expand Up @@ -101,8 +101,8 @@ in stdenv.mkDerivation rec {
nativeBuildInputs = [
autoPatchelfHook
maven
makeWrapper
(wrapGAppsHook.override { makeBinaryWrapper = makeWrapper; })
makeShellWrapper
wrapGAppsHook
jdk
];
buildInputs = [ fuse jre glib jffi ];
Expand Down
Loading