Low-level derivations: Difference between revisions

DoggoBit (talk | contribs)
m fix display
DoggoBit (talk | contribs)
m Switched more args to named
 
(One intermediate revision by the same user not shown)
Line 8: Line 8:
{{File|example.sh|bash|#!/bin/bash
{{File|example.sh|bash|#!/bin/bash
echo "Hello, world!"}}
echo "Hello, world!"}}
When running this script (e.g. <code>$ ./example.sh</code>) we'll get exactly the output we want. However, we're trying to build the script using Nix. Our first approach might be to write a simple derivation{{cite manual|nix|language/derivations|5.4.1|Derivations}} similar to:
When running this script (e.g. <code>$ ./example.sh</code>) we'll get exactly the output we want. However, we're trying to build the script using Nix. Our first approach might be to write a simple derivation{{cite manual|nix|language/derivations|number=5.4.1|title=Derivations}} similar to:
{{File|example.nix|nix|<nowiki>derivation {
{{File|example.nix|nix|<nowiki>derivation {
   name = "hello-world";
   name = "hello-world";
Line 138: Line 138:
=== Standard environment ===
=== Standard environment ===


For practicality purposes, let's compare this to the standard environment way of doing this. Using <code>stdenv.mkDerivation</code>{{cite manual|nixpkgs|sec-using-stdenv|Using stdenv}} gives us access to the common Linux utilities pre-included for us{{cite manual|nixpkgs|sec-tools-of-stdenv|Tools provided by stdenv}}, so we don't have to do the package importing ourselves:
For practicality purposes, let's compare this to the standard environment way of doing this. Using <code>stdenv.mkDerivation</code>{{cite manual|nixpkgs|sec-using-stdenv|title=Using stdenv}} gives us access to the common Linux utilities pre-included for us{{cite manual|nixpkgs|sec-tools-of-stdenv|title=Tools provided by stdenv}}, so we don't have to do the package importing ourselves:


{{File|example.nix|nix|highlight=3|
{{File|example.nix|nix|highlight=3|
Line 158: Line 158:
=== Nixpkgs utilities ===
=== Nixpkgs utilities ===


Even further up the chain of abstractions, [[Nixpkgs]] contains many pre-built utilities for us that handle some of the configuration involved in the standard environment as well. In our case, we can use the <code>writeShellScript</code>{{cite manual|nixpkgs|trivial-builder-writeShellScript|writeShellScript}}:
Even further up the chain of abstractions, [[Nixpkgs]] contains many pre-built utilities for us that handle some of the configuration involved in the standard environment as well. In our case, we can use the <code>writeShellScript</code>{{cite manual|nixpkgs|trivial-builder-writeShellScript|title=writeShellScript}}:


{{File|example.nix|nix|
{{File|example.nix|nix|