diff --git a/doc/manual/writing-nix-expressions.xml b/doc/manual/writing-nix-expressions.xml index b5452b3a7..77431f961 100644 --- a/doc/manual/writing-nix-expressions.xml +++ b/doc/manual/writing-nix-expressions.xml @@ -1606,7 +1606,8 @@ removeAttrs { x = 1; y = 2; z = 3; } ["a" "x" "z"] - builtins.toFile + builtins.toFile name s Store the string s in a @@ -1713,6 +1714,40 @@ in foo builder in a more structured format than plain environment variables. + + + shows an example where this is + the case. The builder is supposed to generate the configuration + file for a Jetty + servlet container. A servlet container contains a number + of servlets (*.war files) each exported under + a specific URI prefix. So the servlet configuration is a list of + attribute sets containing the path and + war of the servlet (). This kind of information is + difficult to communicate with the normal method of passing + information through an environment variable, which just + concatenates everything together into a string (which might just + work in this case, but wouldn’t work if fields are optional or + contain lists themselves). Instead the Nix expression is + converted to an XML representation with + toXML, which is unambiguous and can easily be + processed with the appropriate tools. For instance, in the + example an XSLT stylesheet () is applied to it () to + generate the XML configuration file for the Jetty server. The XML + representation produced from by toXML is shown in . + + Note that uses the toFile built-in to write the + builder and the stylesheet “inline” in the Nix expression. The + path of the stylesheet is spliced into the builder at + xsltproc ${stylesheet} + .... + Passing information to a builder using <function>toXML</function> @@ -1727,10 +1762,11 @@ stdenv.mkDerivation (rec { builder = builtins.toFile "builder.sh" " source $stdenv/setup mkdir $out - echo $servlets | xsltproc ${stylesheet} - > $out/server-conf.xml + echo $servlets | xsltproc ${stylesheet} - > $out/server-conf.xml]]> + stylesheet = builtins.toFile "stylesheet.xsl"]]> @@ -1745,7 +1781,7 @@ stdenv.mkDerivation (rec { "; - servlets = builtins.toXML [ + servlets = builtins.toXML []]> - The string in the attribute servlets - evaluates to something like this: - + XML representation produced by + <function>toXML</function> + @@ -1778,7 +1814,7 @@ stdenv.mkDerivation (rec { ]]> - +