In Nix manual's Inheriting attributes section, we have
graphviz = (import ../tools/graphics/graphviz) {
inherit fetchurl stdenv libpng libjpeg expat x11 yacc;
inherit (xlibs) libXaw;
};
xlibs = {
libX11 = ...;
libXaw = ...;
...
}
libpng = ...;
libjpg = ...;
...
What do the brackets around import ... (i.e. (import ../tools/graphics/graphviz)) do? Also, what do the brackets in inherit (xlibs) libXaw; do?
xlibsis in the same scope as graphviz butlibXawis not, because it's inside thexlibsset. So to be able to pass it as an argument to the graphviz function you need to explicitlyinherit (xlibs) libXaw. That behaviour denoted by the brackets is unique to theinheritkeyword.The brackets in
(import ../tools/graphics/graphviz)are simply the common convention for denoting order of evaluation.importis a function that accepts a single argumentpath. The file in../tools/graphics/graphvizcontains a single function that accepts a set of attributes as its argument. So the brackets denote that the order of evaluation should be (1) import the function inpaththen (2) apply the attribute set{...}to that function.Edit: @danbst pointed out that in this case the brackets in
import ../tools/graphics/graphvizaren't needed. The reason for this is that evaluatingimport ../tools/graphics/graphvizreturns a function which is then called with the set{ ... }.The necessity of the brackets can be demonstrated by using the same values as arguments for this function
typesOfArgs = one: two: with builtins; "${typeOf one} and ${typeOf two}"which returns a string.typesOfArgs (import ../tools/graphics/graphviz) { }would evaluate to"lambda and set"but without the brackets the interpreter would evaluatetypesOfArgs import ../tools/graphics/graphvizto"lambda and path"and then try to call that string as a function with the argument{ }which would result inerror: attempt to call something which is not a function but a stringWithout the brackets the interpreter would assume you want to call the functionimportwith the 2 argumentspathand{ ... }, which would be an error.