Derivations: Difference between revisions

DoggoBit (talk | contribs)
Low-level derivations: Fix escaped nixpkgs reference
DoggoBit (talk | contribs)
Low-level derivations: Replace with working example in low-level derivations
Line 21: Line 21:
{{Main|Low-level derivations}}
{{Main|Low-level derivations}}
As mentioned above, writing derivations in this manner can quickly become unwieldy and unfeasible. However, in order to understand why, do check out the main article above to follow the process of writing a derivation while hitting every hurdle that you might hit when building one yourself. Doing so is the best way to understand conceptually how derivations operate. You can see what a well defined low-level derivation might look like, in this case simply creating a script that displays the message ''"Hello, world!"'':
As mentioned above, writing derivations in this manner can quickly become unwieldy and unfeasible. However, in order to understand why, do check out the main article above to follow the process of writing a derivation while hitting every hurdle that you might hit when building one yourself. Doing so is the best way to understand conceptually how derivations operate. You can see what a well defined low-level derivation might look like, in this case simply creating a script that displays the message ''"Hello, world!"'':
{{File|example.nix|nix|<nowiki>let
 
   pkgs = import </nowiki><<nowiki>nixpkgs</nowiki>><nowiki> {};
{{File|example.nix|nix|highlight=11|<nowiki>
let
   pkgs = import </nowiki><<nowiki>nixpkgs</nowiki>><nowiki> { };
in
in
derivation {
derivation {
Line 30: Line 32:
   args = [
   args = [
     "-c"
     "-c"
     "echo 'echo \"Hello, World!\"' </nowiki>><nowiki> $out"
     ''
      export PATH="$PATH:${pkgs.coreutils}/bin"
      echo '#!${pkgs.bash}/bin/bash' </nowiki>><nowiki> $out
      echo 'echo "Hello, World!"' </nowiki>>><nowiki> $out
      chmod +x $out
    ''
   ];
   ];
}</nowiki>}}
}</nowiki>}}