From e07a2fab7f065c3fa084027f07dcf8cafbd19394 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Thu, 12 Oct 2023 23:43:03 +0200 Subject: [PATCH] stdenv: substituteStream: deprecate --replace in favor of --replace-{fail,warn,quiet} --- .../emscripten.section.md | 6 ++--- doc/languages-frameworks/rust.section.md | 2 +- doc/stdenv/platform-notes.chapter.md | 2 +- doc/stdenv/stdenv.chapter.md | 23 +++++++++++----- .../manual/release-notes/rl-2405.section.md | 2 ++ pkgs/stdenv/generic/setup.sh | 27 ++++++++++++++++++- 6 files changed, 50 insertions(+), 12 deletions(-) diff --git a/doc/languages-frameworks/emscripten.section.md b/doc/languages-frameworks/emscripten.section.md index 20d358f2e9e3..9ce48db2c2de 100644 --- a/doc/languages-frameworks/emscripten.section.md +++ b/doc/languages-frameworks/emscripten.section.md @@ -86,9 +86,9 @@ One advantage is that when `pkgs.zlib` is updated, it will automatically update postPatch = pkgs.lib.optionalString pkgs.stdenv.isDarwin '' substituteInPlace configure \ - --replace '/usr/bin/libtool' 'ar' \ - --replace 'AR="libtool"' 'AR="ar"' \ - --replace 'ARFLAGS="-o"' 'ARFLAGS="-r"' + --replace-fail '/usr/bin/libtool' 'ar' \ + --replace-fail 'AR="libtool"' 'AR="ar"' \ + --replace-fail 'ARFLAGS="-o"' 'ARFLAGS="-r"' ''; }) ``` diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 9be381c0bfe2..8191722071e9 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -700,7 +700,7 @@ with import {}; hello = attrs: lib.optionalAttrs (lib.versionAtLeast attrs.version "1.0") { postPatch = '' substituteInPlace lib/zoneinfo.rs \ - --replace "/usr/share/zoneinfo" "${tzdata}/share/zoneinfo" + --replace-fail "/usr/share/zoneinfo" "${tzdata}/share/zoneinfo" ''; }; }; diff --git a/doc/stdenv/platform-notes.chapter.md b/doc/stdenv/platform-notes.chapter.md index b47f5af349b8..409c9f2e7b2e 100644 --- a/doc/stdenv/platform-notes.chapter.md +++ b/doc/stdenv/platform-notes.chapter.md @@ -54,7 +54,7 @@ Some common issues when packaging software for Darwin: # ... prePatch = '' substituteInPlace Makefile \ - --replace '/usr/bin/xcrun clang' clang + --replace-fail '/usr/bin/xcrun clang' clang ''; } ``` diff --git a/doc/stdenv/stdenv.chapter.md b/doc/stdenv/stdenv.chapter.md index c66301bcb1c8..c9c30fde172d 100644 --- a/doc/stdenv/stdenv.chapter.md +++ b/doc/stdenv/stdenv.chapter.md @@ -230,9 +230,9 @@ stdenv.mkDerivation rec { postInstall = '' substituteInPlace $out/bin/solo5-virtio-mkimage \ - --replace "/usr/lib/syslinux" "${syslinux}/share/syslinux" \ - --replace "/usr/share/syslinux" "${syslinux}/share/syslinux" \ - --replace "cp " "cp --no-preserve=mode " + --replace-fail "/usr/lib/syslinux" "${syslinux}/share/syslinux" \ + --replace-fail "/usr/share/syslinux" "${syslinux}/share/syslinux" \ + --replace-fail "cp " "cp --no-preserve=mode " wrapProgram $out/bin/solo5-virtio-mkimage \ --prefix PATH : ${lib.makeBinPath [ dosfstools mtools parted syslinux ]} @@ -1253,9 +1253,20 @@ postInstall = '' Performs string substitution on the contents of \, writing the result to \. The substitutions in \ are of the following form: -#### `--replace` \ \ {#fun-substitute-replace} +#### `--replace-fail` \ \ {#fun-substitute-replace-fail} Replace every occurrence of the string \ by \. +Will error if no change is made. + +#### `--replace-warn` \ \ {#fun-substitute-replace-warn} + +Replace every occurrence of the string \ by \. +Will print a warning if no change is made. + +#### `--replace-quiet` \ \ {#fun-substitute-replace-quiet} + +Replace every occurrence of the string \ by \. +Will do nothing if no change can be made. #### `--subst-var` \ {#fun-substitute-subst-var} @@ -1269,8 +1280,8 @@ Example: ```shell substitute ./foo.in ./foo.out \ - --replace /usr/bin/bar $bar/bin/bar \ - --replace "a string containing spaces" "some other text" \ + --replace-fail /usr/bin/bar $bar/bin/bar \ + --replace-fail "a string containing spaces" "some other text" \ --subst-var someVar ``` diff --git a/nixos/doc/manual/release-notes/rl-2405.section.md b/nixos/doc/manual/release-notes/rl-2405.section.md index aba4d3d72d1d..65980e3052e9 100644 --- a/nixos/doc/manual/release-notes/rl-2405.section.md +++ b/nixos/doc/manual/release-notes/rl-2405.section.md @@ -160,6 +160,8 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m - The option [`services.nextcloud.config.dbport`] of the Nextcloud module was removed to match upstream. The port can be specified in [`services.nextcloud.config.dbhost`](#opt-services.nextcloud.config.dbhost). +- `stdenv`: The `--replace` flag in `substitute`, `substituteInPlace`, `substituteAll`, `substituteAllStream`, and `substituteStream` is now deprecated if favor of the new `--replace-fail`, `--replace-warn` and `--replace-quiet`. The deprecated `--replace` equates to `--replace-warn`. + - The Yama LSM is now enabled by default in the kernel, which prevents ptracing non-child processes. This means you will not be able to attach gdb to an existing process, but will need to start that process from gdb (so it is a diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index ec8df76f2c79..aa519cce4be8 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -815,6 +815,8 @@ fi ###################################################################### # Textual substitution functions. +# only log once, due to max logging limit on hydra +_substituteStream_has_warned_replace_deprecation="" substituteStream() { local var=$1 @@ -822,8 +824,24 @@ substituteStream() { shift 2 while (( "$#" )); do + local is_required=1 + local is_quiet="" case "$1" in + --replace-quiet) + is_quiet=1 + ;& --replace) + # deprecated 2023-11-22 + # this will either get removed, or switch to the behaviour of --replace-fail in the future + if [ -z "$_substituteStream_has_warned_replace_deprecation" ]; then + echo "substituteStream(): WARNING: '--replace' is deprecated, use --replace-{fail,warn,quiet}. ($description)" >&2 + _substituteStream_has_warned_replace_deprecation=1 + fi + ;& + --replace-warn) + is_required="" + ;& + --replace-fail) pattern="$2" replacement="$3" shift 3 @@ -832,7 +850,14 @@ substituteStream() { eval "$var"'=${'"$var"'//"$pattern"/"$replacement"}' if [ "$pattern" != "$replacement" ]; then if [ "${!var}" == "$savedvar" ]; then - echo "substituteStream(): WARNING: pattern '$pattern' doesn't match anything in $description" >&2 + if [ -z "$is_required" ]; then + if [ -z "$is_quiet" ]; then + echo "substituteStream(): WARNING: pattern '$pattern' doesn't match anything in $description" >&2 + fi + else + echo "substituteStream(): ERROR: pattern '$pattern' doesn't match anything in $description" >&2 + return 1 + fi fi fi ;;