Given following default.nix
,
{ stdenv, fetchurl, perl }:
stdenv.mkDerivation {
name = "hello-2.1.1";
builder = ./builder.sh;
src = fetchurl {
url = ftp://ftp.nluug.nl/pub/gnu/hello/hello-2.1.1.tar.gz;
md5 = "70c9ccf9fac07f762c24f2df2290784d";
};
inherit perl;
}
How can I get the value hello-2.1.1
from name
field using nix-instantiate
?
$ nix-instantiate --eval -E 'name' default.nix
error: undefined variable ‘name’ at (string):1:1
What your
nix-instantiate
invocation is doing, is trying to retrievename
from a mostly empty scope. What's missing here is a piece of functionality that is implemented in NixPkgs provides the arguments to your function indefault.nix
.Let's get the
callPackage
function from your current<nixpkgs>
:callPackage
requires two arguments, a function that defines the package and an attribute set of overrides. Instead of providing the function directly, you can provide a file reference instead.Now let's get the name
And run it
To experiment with Nix, I prefer to use
nix-repl
though. It is easier to use and has tab completion.