ShellCheck inline scripts during test phase

Hi all,

I’ve been working on a few nixpkgs PRs to address some ShellCheck lints, and I’ve been wondering what to do with scripts inlined into Nix code. I’m thinking I could run them through shellcheck (via stdin or builtins.toFile) during the test phase - would that be a good approach to allow people to mix shell code into Nix?

(Personally I’m not a fan of mixing languages because of all the syntax clashes, extra faff escaping things, and not having any syntax highlighting, but if this is a common pattern we’re going to have to live with for the foreseeable future at least the code should be linted.)

Most of the inclined code, at least I feel, will be in one of the phases that derivations like to override. So maybe checking all of pkgs/ for .*Phase\s*=\s*'' (regex) will return a fair share of all inlined shell code.
After that it’s only a matter of extracting it (should also be pretty doable with regex, although beware that '' is also used to escape ${}!) and running shell check over the result.

Could you override the builder to just do that with the chunks it’s given?

Oh, that gives me another idea. You can use the repl to easily print (or even check it right in there) the shell code of all (and here’s the big upside!) only modified phases. <package>.drvAttrs.<tab>.
You can easily iterate over all since it’s just an attribute set.