Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trivial-builders.nix: add writeShellScriptBin builder #19050

Closed
wants to merge 1 commit into from

Conversation

grwlf
Copy link
Contributor

@grwlf grwlf commented Sep 28, 2016

Motivation for this change

We often use Nix to write in-place shell scripts. This patch adds writeShellScriptBin which enables basic syntax-checking for such a scripts.

More detailed, it does the following:

  1. Assuming caller-supplied text is a shell-script, adds '#!${stdenv.shell}' header
  2. Calls underlying writeScriptBin function
  3. Calls sh -n to check the basic syntax
Things done
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • OS X
    • Linux
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@mention-bot
Copy link

@grwlf, thanks for your PR! By analyzing the annotation information on this pull request, we identified @edolstra, @nbp and @urkud to be potential reviewers

@Mic92
Copy link
Member

Mic92 commented Oct 5, 2016

Looking at nixpkgs there are more instances where writeShellScript could be used instead of the specialized form, which installs scripts to bin.

in
runCommand name {} ''
${stdenv.shell} -n ${s}/bin/${name}
cp -v -r ${s} $out
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is great!

Still, instead of making a copy of the verified script, I think it would be better to add a checkPhase to the writeTextFile function above.

@joachifm
Copy link
Contributor

So do we want to integrate this?

@grwlf
Copy link
Contributor Author

grwlf commented Jan 24, 2017 via email

@joachifm
Copy link
Contributor

joachifm commented Feb 26, 2017

I just noticed that this now has the checkPhase suggested by @nbp. I've tested it locally and it works fine, but seeing as it changes writeTextFile I wonder about the rebuild impact of this change?

Also, I notice that it no longer puts the resulting script under $out/bin, which somewhat disagrees with how other *Bin builders work.

@grwlf
Copy link
Contributor Author

grwlf commented Mar 15, 2017

@joachifm , I fixed the /bin/${name} location in the build expression.
Regarding the massive rebuild, unfortunately, yes, it will take place. Looks like we should make a choice: either add checkPhase to the writeTextFile or stick with the 2-staged expression I posted originally:

  # Create a Shell script, check its syntax
  writeShellScriptBin = name : text :
    let
      s = writeScriptBin name ''
        #!${stdenv.shell}
        ${text}
      '';
    in
      runCommand name {} ''
        ${stdenv.shell} -n ${s}/bin/${name}
        cp -v -r ${s} $out
      '';

I there is a compromise, please let me know.

@joachifm
Copy link
Contributor

Ah, the rebuild is not a problem per se, if we want this change we can put it into staging. Preferably along with some other change that'd also require a mass rebuild.

@grwlf
Copy link
Contributor Author

grwlf commented Mar 23, 2017

OK.
Travis build log looks unrelated to the patch. Should I do anything more on this topic before the merge?

@grahamc
Copy link
Member

grahamc commented Aug 2, 2017

Applied in f49c2fb thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants