From 407c9fd520e8084f3a313297cdd6e99e56247f07 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 4 Oct 2006 15:20:19 +0000 Subject: [PATCH] * Explanation of toXML example. --- doc/manual/writing-nix-expressions.xml | 52 ++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 8 deletions(-) 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 { ]]> - +