Low-level derivations: Difference between revisions
m →A Hello, world example: Again, escape those pesky operators |
Refine first example |
||
| Line 12: | Line 12: | ||
name = "hello-world"; | name = "hello-world"; | ||
system = builtins.currentSystem; | system = builtins.currentSystem; | ||
builder = "/bin/ | builder = "/bin/bash"; | ||
args = [ | args = [ | ||
"-c" | |||
"echo 'Hello, World!' </nowiki>><nowiki> $out" | "echo '#!/bin/bash' </nowiki>><nowiki> $out" | ||
"echo 'echo \"Hello, World!\"' </nowiki>><nowiki> $out" | |||
"chmod +x $out" | |||
]; | ]; | ||
}</nowiki>}} | }</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: | ||
# 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; | |||
# Make the output file executable. | |||