From 58eb3d380601897c6ba9679eafc9c77305549b6f Mon Sep 17 00:00:00 2001 From: Greg Pfeil Date: Mon, 5 Dec 2022 01:16:12 -0700 Subject: [PATCH] mkshell: refactor Bash snippet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I’ve been using https://github.com/Fuuzetsu/shellcheck-nix-attributes on most of my derivations, and attaching it to one derived from `mkShell` resulted in ``` shellcheck_buildPhase In /nix/store/8774inwznc87dwhac90winc9b5k6gmkb-nix-shell_shellcheck_buildPhase line 1: echo "------------------------------------------------------------" >>$out ^-- SC2129 (style): Consider using { cmd1; cmd2; } >> file instead of individual redirects. ^--^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: echo "------------------------------------------------------------" >>"$out" In /nix/store/8774inwznc87dwhac90winc9b5k6gmkb-nix-shell_shellcheck_buildPhase line 2: echo " WARNING: the existence of this path is not guaranteed." >>$out ^--^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: echo " WARNING: the existence of this path is not guaranteed." >>"$out" In /nix/store/8774inwznc87dwhac90winc9b5k6gmkb-nix-shell_shellcheck_buildPhase line 3: echo " It is an internal implementation detail for pkgs.mkShell." >>$out ^--^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: echo " It is an internal implementation detail for pkgs.mkShell." >>"$out" In /nix/store/8774inwznc87dwhac90winc9b5k6gmkb-nix-shell_shellcheck_buildPhase line 4: echo "------------------------------------------------------------" >>$out ^--^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: echo "------------------------------------------------------------" >>"$out" In /nix/store/8774inwznc87dwhac90winc9b5k6gmkb-nix-shell_shellcheck_buildPhase line 5: echo >> $out ^--^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: echo >> "$out" In /nix/store/8774inwznc87dwhac90winc9b5k6gmkb-nix-shell_shellcheck_buildPhase line 7: export >> $out ^--^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: export >> "$out" For more information: https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ... https://www.shellcheck.net/wiki/SC2129 -- Consider using { cmd1; cmd2; } >>... ``` ——— https://garnix.io/build/qgxbameB This addresses the shellcheck complaints. --- pkgs/build-support/mkshell/default.nix | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkgs/build-support/mkshell/default.nix b/pkgs/build-support/mkshell/default.nix index e7552f434848..39b02a47141a 100644 --- a/pkgs/build-support/mkshell/default.nix +++ b/pkgs/build-support/mkshell/default.nix @@ -44,12 +44,13 @@ stdenv.mkDerivation ({ phases = [ "buildPhase" ]; buildPhase = '' - echo "------------------------------------------------------------" >>$out - echo " WARNING: the existence of this path is not guaranteed." >>$out - echo " It is an internal implementation detail for pkgs.mkShell." >>$out - echo "------------------------------------------------------------" >>$out - echo >> $out - # Record all build inputs as runtime dependencies - export >> $out + { echo "------------------------------------------------------------"; + echo " WARNING: the existence of this path is not guaranteed."; + echo " It is an internal implementation detail for pkgs.mkShell."; + echo "------------------------------------------------------------"; + echo; + # Record all build inputs as runtime dependencies + export; + } >> "$out" ''; } // rest)