When reading section 15.4 of nix Package Manager Guide it talks about passing parameters to the builder script.
So I tried it:-)
#atrTest.nix with args
let
pkgs = import <nixpkgs> {};
in
pkgs.stdenv.mkDerivation rec {
name = "atrTest-0.0.1";
args = ["-run 2"];
builder = ./builder.sh;
src = ./makefile;
extraStuff = "extra stuff${name} for shell";
buildInputs = [pkgs.tree];
postInstall = ''
mkdir ''${out}/Assets
echo "all done now running postInstall for ${name}" > ''${out}/Assets/log.txt
'';
}
When I added the args attribute to the argument list of mkDerivation, I received the folowing infelicity;
nix-build -K atrTest.nix
these derivations will be built:
/nix/store/ppr4ip18g4xm0nkbrpr08l4jcvf06jy4-atrTest-0.0.1.drv
building '/nix/store/ppr4ip18g4xm0nkbrpr08l4jcvf06jy4-atrTest-0.0.1.drv'...
bash: - : invalid option
Usage: bash [GNU long option] [option] ...
bash [GNU long option] [option] script-file ...
GNU long options:
--debug
tl;dr
ption (invocation only)
-abefhkmnptuvxBCHP or -o option
note: keeping build directory '/tmp/nix-build-atrTest-0.0.1.drv-8'
builder for '/nix/store/ppr4ip18g4xm0nkbrpr08l4jcvf06jy4-atrTest-0.0.1.drv' failed with exit code 2
error: build of '/nix/store/ppr4ip18g4xm0nkbrpr08l4jcvf06jy4-atrTest-0.0.1.drv' failed
I was expecting that my builder script would be called with the args -run 2.
Instead it looks like bash was called with the arguments. While this might be useful
in some use cases, the ability to pass arguments to my builder script also
seems useful.
I did try it as a list of 2 arguments, ["run" "2"]
but it didnt like that either.
This brings up a couple of salient points:
- the manual’s description and the actual behavior seem to be inconsistent.
- How do I pass arguments to the builder script?
Just as a side note, I’d like to recommend that formal documentation follow RFC2119. This specification
described the use of words like should and shall. The nix manual says
The optional attribute args specifies command-line arguments to be passed to the builder. It should be a list.
When I tried adding the args attribute as a string I got an error. It seems that it MUST be a list. Its a minor point but, IMHO, the intent of RFC2119 is a good one and easy to follow. Further discussion is provided at microformats. Its an easy read and only covers 5 words and how to use them.
So my question is; how do I specify parameters to be passed to my builder script?