From 0d6bcb513bf2f2fe92ff8b2fae75da95007a03e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Tue, 10 May 2022 15:51:43 +0200 Subject: [PATCH] makeBinaryWrapper: move into its own folder The derivation is complex enough to warrant moving out of all-packages.nix --- doc/stdenv/stdenv.chapter.md | 2 +- .../make-binary-wrapper/default.nix | 20 +++++++++++++++ .../make-binary-wrapper.sh | 2 +- pkgs/test/default.nix | 8 +++++- pkgs/top-level/all-packages.nix | 25 +------------------ 5 files changed, 30 insertions(+), 27 deletions(-) create mode 100644 pkgs/build-support/setup-hooks/make-binary-wrapper/default.nix rename pkgs/build-support/setup-hooks/{ => make-binary-wrapper}/make-binary-wrapper.sh (99%) diff --git a/doc/stdenv/stdenv.chapter.md b/doc/stdenv/stdenv.chapter.md index d5d27cbf0863..b57698cb90b3 100644 --- a/doc/stdenv/stdenv.chapter.md +++ b/doc/stdenv/stdenv.chapter.md @@ -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`. diff --git a/pkgs/build-support/setup-hooks/make-binary-wrapper/default.nix b/pkgs/build-support/setup-hooks/make-binary-wrapper/default.nix new file mode 100644 index 000000000000..f27a4c9fcdf2 --- /dev/null +++ b/pkgs/build-support/setup-hooks/make-binary-wrapper/default.nix @@ -0,0 +1,20 @@ +{ stdenv +, lib +, makeSetupHook +, dieHook +, tests +, cc ? stdenv.cc +, sanitizers ? [] +}: + +makeSetupHook { + deps = [ dieHook cc ]; + + substitutions = { + cc = let + san = lib.escapeShellArgs (map (s: "-fsanitize=${s}") sanitizers); + in "${cc}/bin/cc ${san}"; + + passthru.tests = tests.makeBinaryWrapper; + }; +} ./make-binary-wrapper.sh diff --git a/pkgs/build-support/setup-hooks/make-binary-wrapper.sh b/pkgs/build-support/setup-hooks/make-binary-wrapper/make-binary-wrapper.sh similarity index 99% rename from pkgs/build-support/setup-hooks/make-binary-wrapper.sh rename to pkgs/build-support/setup-hooks/make-binary-wrapper/make-binary-wrapper.sh index 3931b37c2429..abcde2429eeb 100644 --- a/pkgs/build-support/setup-hooks/make-binary-wrapper.sh +++ b/pkgs/build-support/setup-hooks/make-binary-wrapper/make-binary-wrapper.sh @@ -43,7 +43,7 @@ makeWrapper() { mkdir -p "$(dirname "$wrapper")" makeDocumentedCWrapper "$original" "$@" | \ - @CC@ \ + @cc@ \ -Wall -Werror -Wpedantic \ -Wno-overlength-strings \ -Os \ diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix index 2ab03bda8b77..e32534989589 100644 --- a/pkgs/test/default.nix +++ b/pkgs/test/default.nix @@ -71,7 +71,13 @@ with pkgs; dhall = callPackage ./dhall { }; - makeWrapper = callPackage ./make-wrapper {}; + makeWrapper = callPackage ./make-wrapper { }; + makeBinaryWrapper = callPackage ./make-binary-wrapper { + makeBinaryWrapper = pkgs.makeBinaryWrapper.override { + sanitizers = pkgs.lib.optionals (! (pkgs.stdenv.isDarwin && pkgs.stdenv.isAarch64)) + [ "undefined" "address" ]; + }; + }; pkgs-lib = recurseIntoAttrs (import ../pkgs-lib/tests { inherit pkgs; }); } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index b7554dda3980..a9b955db651b 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -783,30 +783,7 @@ with pkgs; } ../build-support/setup-hooks/make-wrapper.sh; - makeBinaryWrapper = let - f = { cc, sanitizers }: let - san = lib.concatMapStringsSep " " (s: "-fsanitize=${s}") sanitizers; - script = runCommand "make-binary-wrapper.sh" {} '' - substitute ${../build-support/setup-hooks/make-binary-wrapper.sh} $out \ - --replace " @CC@ " " ${cc}/bin/cc ${san} " - ''; - in - makeSetupHook { - deps = [ dieHook cc ]; - substitutions.passthru.tests = callPackage ../test/make-binary-wrapper { - makeBinaryWrapper = makeBinaryWrapper.override { - sanitizers = (if stdenv.isDarwin && stdenv.isAarch64 - then [ ] - else [ "undefined" "address" ] - ); - }; - }; - } script; - in - lib.makeOverridable f { - cc = stdenv.cc; - sanitizers = [ ]; - }; + makeBinaryWrapper = callPackage ../build-support/setup-hooks/make-binary-wrapper { }; makeModulesClosure = { kernel, firmware, rootModules, allowMissing ? false }: callPackage ../build-support/kernel/modules-closure.nix {