Low-level derivations: Difference between revisions

DoggoBit (talk | contribs)
Refine first example
DoggoBit (talk | contribs)
Make the example technically correct
Line 15: Line 15:
   args = [
   args = [
     "-c"
     "-c"
     "echo '#!/bin/bash' </nowiki>><nowiki> $out"
     ''
    "echo 'echo \"Hello, World!\"' </nowiki>><nowiki> $out"
      echo '#!/bin/bash' </nowiki>><nowiki> $out
    "chmod +x $out"
      echo 'echo "Hello, World!"' </nowiki>>><nowiki> $out
      chmod +x $out
    ''
   ];
   ];
}</nowiki>}}There are a number of elements in this Nix file, but remembering the conceptual model of a framework makes quick work of figuring them out: a derivation is a set of ''inputs along with an executable'' that produces a deterministic ''output'', following a list of ''steps.'' Here our inputs are quite literally the key-value pairs in the derivation [[Attribute set|attrset]]: the <code>name</code> of the derivation and the system it's being built ''for''. The executable (called the builder) is the program found at <code>/bin/bash</code>. And the steps are:
}</nowiki>}}There are a number of elements in this Nix file, but remembering the conceptual model of a framework makes quick work of figuring them out: a derivation is a set of ''inputs along with an executable'' that produces a deterministic ''output'', following a list of ''steps.'' Here our inputs are quite literally the key-value pairs in the derivation [[Attribute set|attrset]]: the <code>name</code> of the derivation and the system it's being built ''for''. The executable (called the <code>builder</code>) is the program found at <code>/bin/bash</code>. And the steps are:


# Write the string <code>#!/bin/bash</code> to the output file (<code>$out</code>);
# Write the string <code>#!/bin/bash</code> to the output file (<code>$out</code>);
# Write the string <code>echo "Hello, World!"</code> to the output file;
# Write the string <code>echo "Hello, World!"</code> to the output file;
# Make the output file executable.
# Make the output file executable.