diff options
author | con-f-use <con-f-use@gmx.net> | 2023-10-15 09:28:37 +0200 |
---|---|---|
committer | con-f-use <con-f-use@gmx.net> | 2023-10-15 12:10:50 +0200 |
commit | 0f3fa9e6ef7eb6e4421656199651bdacc70b2442 (patch) | |
tree | d233e56d9f8d9fadea12976fcca3a5b4925d28c9 /pkgs/build-support | |
parent | 3650808d85dccbfa3be3d785dfd3ce33a757bd2c (diff) |
writeShellApplication: exclude shell checks
Diffstat (limited to 'pkgs/build-support')
3 files changed, 35 insertions, 1 deletions
diff --git a/pkgs/build-support/trivial-builders/default.nix b/pkgs/build-support/trivial-builders/default.nix index 8b8732af0656a..f7adfad455bda 100644 --- a/pkgs/build-support/trivial-builders/default.nix +++ b/pkgs/build-support/trivial-builders/default.nix @@ -311,6 +311,8 @@ rec { Similar to writeShellScriptBin and writeScriptBin. Writes an executable Shell script to /nix/store/<store path>/bin/<name> and checks its syntax with shellcheck and the shell's -n option. + Individual checks can be foregone by putting them in the excludeShellChecks + list, e.g. [ "SC2016" ]. Automatically includes sane set of shellopts (errexit, nounset, pipefail) and handles creation of PATH based on runtimeInputs @@ -338,6 +340,7 @@ rec { , runtimeInputs ? [ ] , meta ? { } , checkPhase ? null + , excludeShellChecks ? [ ] }: writeTextFile { inherit name meta; @@ -363,10 +366,11 @@ rec { # but we still want to use writeShellApplication on those platforms let shellcheckSupported = lib.meta.availableOn stdenv.buildPlatform shellcheck.compiler; + excludeOption = lib.optionalString (excludeShellChecks != [ ]) "--exclude '${lib.concatStringsSep "," excludeShellChecks}'"; shellcheckCommand = lib.optionalString shellcheckSupported '' # use shellcheck which does not include docs # pandoc takes long to build and documentation isn't needed for just running the cli - ${lib.getExe (haskell.lib.compose.justStaticExecutables shellcheck.unwrapped)} "$target" + ${lib.getExe (haskell.lib.compose.justStaticExecutables shellcheck.unwrapped)} ${excludeOption} "$target" ''; in if checkPhase == null then '' diff --git a/pkgs/build-support/trivial-builders/test/default.nix b/pkgs/build-support/trivial-builders/test/default.nix index 683f4b9fd04f3..cbd1b388ef666 100644 --- a/pkgs/build-support/trivial-builders/test/default.nix +++ b/pkgs/build-support/trivial-builders/test/default.nix @@ -25,6 +25,7 @@ recurseIntoAttrs { then callPackage ./references.nix {} else null; writeCBin = callPackage ./writeCBin.nix {}; + writeShellApplication = callPackage ./writeShellApplication.nix {}; writeScriptBin = callPackage ./writeScriptBin.nix {}; writeShellScript = callPackage ./write-shell-script.nix {}; writeShellScriptBin = callPackage ./writeShellScriptBin.nix {}; diff --git a/pkgs/build-support/trivial-builders/test/writeShellApplication.nix b/pkgs/build-support/trivial-builders/test/writeShellApplication.nix new file mode 100644 index 0000000000000..6ce6f0720fcf6 --- /dev/null +++ b/pkgs/build-support/trivial-builders/test/writeShellApplication.nix @@ -0,0 +1,29 @@ +/* + Run with: + + cd nixpkgs + nix-build -A tests.trivial-builders.writeShellApplication +*/ + +{ lib, writeShellApplication, runCommand }: +let + pkg = writeShellApplication { + name = "test-script"; + excludeShellChecks = [ "SC2016" ]; + text = '' + echo -e '#!/usr/bin/env bash\n' \ + 'echo "$SHELL"' > /tmp/something.sh # this line would normally + # ...cause shellcheck error + ''; + }; +in + assert pkg.meta.mainProgram == "test-script"; + runCommand "test-writeShellApplication" { } '' + + echo Testing if writeShellApplication builds without shellcheck error... + + target=${lib.getExe pkg} + + touch $out + '' + |