Fuuzetsu/shellcheck-nix-attributes
{ "createdAt": "2020-04-15T05:37:42Z", "defaultBranch": "master", "description": null, "fullName": "Fuuzetsu/shellcheck-nix-attributes", "homepage": null, "language": "Nix", "name": "shellcheck-nix-attributes", "pushedAt": "2020-04-15T05:37:56Z", "stargazersCount": 5, "topics": [], "updatedAt": "2024-11-17T04:09:04Z", "url": "https://github.com/Fuuzetsu/shellcheck-nix-attributes"}shellcheck-nix-attributes
Section titled “shellcheck-nix-attributes”When writing derivations with nix, the underlying language that gets
executed in Bash, which means we can end up with many Bash snippets in
our nix files. It may be desirable to check these snippets with the
excellent shellcheck script such that we know that nothing strange
is going to happen late into the build.
By applying the nix expression here to your derivation, an additional set of phases will run an the very start of the build. These phases will check each of the specified attributes and exit the build with failure if necessary.
Let’s consider a file example-fail.nix that defines a simple
derivation and runs shellcheck on installPhase:
{ pkgs ? import <nixpkgs> {} }:
let shellchecked = pkgs.callPackage ./default.nix {}; someDerivation = pkgs.stdenvNoCC.mkDerivation { name = "someDerivation"; phases = [ "installPhase" ]; installPhase = '' mkdir $out echo foo > $out/some-output ''; };in shellchecked someDerivationIf we try to build it, we may see something like:
$ nix-build example-fail.nix --no-out-linkthese derivations will be built: /nix/store/pywslpazmnqaqjk03qia051qyxfcc2z4-someDerivation_shellcheck_installPhase.drv /nix/store/bgfxd8kwcq6k5c9prprppdc3ym78fzky-someDerivation.drvbuilding '/nix/store/pywslpazmnqaqjk03qia051qyxfcc2z4-someDerivation_shellcheck_installPhase.drv'...building '/nix/store/bgfxd8kwcq6k5c9prprppdc3ym78fzky-someDerivation.drv'...shellcheck_installPhase
In /nix/store/f4lzcsyqfmnf9x4hswql7mijxsysngsn-someDerivation_shellcheck_installPhase line 1:mkdir $out ^--^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:mkdir "$out"
In /nix/store/f4lzcsyqfmnf9x4hswql7mijxsysngsn-someDerivation_shellcheck_installPhase line 2:echo foo > $out/some-output ^--^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:echo foo > "$out"/some-output
For more information: https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...builder for '/nix/store/bgfxd8kwcq6k5c9prprppdc3ym78fzky-someDerivation.drv' failed with exit code 1error: build of '/nix/store/bgfxd8kwcq6k5c9prprppdc3ym78fzky-someDerivation.drv' failedGreat.
See default.nix for some things you can configure and few comments.
Your nixpkgs has to be recent-ish enough to support all the used
library functions, such as getAttrs. If you’d like to support older
versions or would like to pin a known-working nixpkgs, feel free to
open an issue.