[Nix-dev] Generated path names within a derivation

Nicolas Pierron nicolas.b.pierron at gmail.com
Tue Jun 9 01:09:11 CEST 2009


On Mon, Jun 8, 2009 at 21:59, Nathaniel Waisbrot (Cont
ARL/CISD)<nathaniel.waisbrot at arl.army.mil> wrote:
> I tried the following:
>
>  getFile = dir: file: (toPath "${dir}/${file}");
>  aFile = getFile "/nix/nixpkgs/networks"    "${version}.patch";
>  patches = [ aFile ];
>
> in the hopes that just wrapping things inside of a function would trick
> Nix into evaluating it as a known path.
> No dice; "cannot coerce a function to a string" when evaluating the
> first line.  (I don't see what function it's trying to coerce...)

1) This error message comes from the derivation processing.  When you
use mkDerivation you implicitly declare that all attributes* are
converted to Strings to be passed as environment variables to the
builder script.
*: except meta.

from Nix manual: ( http://hydra.nixos.org/build/32831/download/1/manual/ )

* builtins.toPath s
Convert the string value s into a path value. The string s must
represent an absolute path (i.e., must start with /). The path need
not exist. The resulting path is canonicalised, e.g., builtins.toPath
"//foo/xyzzy/../bar/" returns /foo/bar.

So there is a miss check here to force the user to use an absolute
path.  This is a constraint caused by the lazy evaluation which
implies that you don't know where the toPath function is called.


2) To solve your problem you can concatenate the path with a string.
Unfortunately, I am not sure this will recompile the package if its
patch changes.

patches = [ (./ + "/${version}.patch") ];


3) If the solution (2) does not recompile when the content of the
patch file change, then I'll suggest you to generate for each patch a
small nix expression which contains the relative path to the patch:

expression sample:

# 1.0.patch.nix
./1.0.patch


which can easily be generated with this command line:

for p in ./*.patch; do
  # suppose that there is at least one patch file.
  echo $p > $p.nix
done

Then your line will become:

patch = [ (import (./ + "/${version}.patch.nix") ]

-- 
Nicolas Pierron
http://www.linkedin.com/in/nicolasbpierron
Albert Einstein - Never memorize what you can look up on books.



More information about the nix-dev mailing list