Git Product home page Git Product logo

shellcheck-nix-attributes's Introduction

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 someDerivation

If we try to build it, we may see something like:

$ nix-build example-fail.nix --no-out-link
these derivations will be built:
  /nix/store/pywslpazmnqaqjk03qia051qyxfcc2z4-someDerivation_shellcheck_installPhase.drv
  /nix/store/bgfxd8kwcq6k5c9prprppdc3ym78fzky-someDerivation.drv
building '/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 1
error: build of '/nix/store/bgfxd8kwcq6k5c9prprppdc3ym78fzky-someDerivation.drv' failed

Great.

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.

shellcheck-nix-attributes's People

Contributors

fuuzetsu avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.