Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show new output for :b #136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions pills/07-working-derivation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,20 @@
</para>

<para>
First of all, let's write our <filename>builder.sh</filename> in the
The builder needs to create something in the path
<varname>$out</varname>, be it a file or a directory.
We'll start with simplest possible builder;
it produces a single file containing the word "foo".
Create <filename>builder.sh</filename> in the
current directory:

<programlisting><xi:include href="./07/builder.sh.txt" parse="text" /></programlisting>

The command <literal>declare -xp</literal>
lists exported variables.
(<literal>declare</literal> is a builtin bash function.)
As we covered in the previous pill, Nix computes the output path of the
derivation. The resulting <literal>.drv</literal> file contains a list of
environment variables passed to the builder. One of these is
<varname>$out</varname>.
</para>
<para>
What we have to do is create something in the path
<varname>$out</varname>, be it a file or a directory. In this case we are
creating a file.
</para>

<para>
In addition, we print out the environment variables during the build
process. We cannot use <application>env</application> for this, because
<application>env</application> is part of
<application>coreutils</application> and we don't have a dependency to it
yet. We only have <application>bash</application> for now.
</para>

<para>
Like for coreutils in the previous pill, we get a blessed bash for free
Expand All @@ -98,9 +86,9 @@

<xi:include href="./07/simple-derivation.xml" />

We did it! The contents of
<filename>/nix/store/w024zci0x1hh1wj6gjq0jagkc1sgrf5r-<emphasis>foo</emphasis></filename>
is really foo. We've built our first derivation.
<xi:include href="./07/cat-foo.xml" />

We did it! We've built our first derivation.
</para>
<para>
Note that we used <code>./builder.sh</code> and not
Expand All @@ -114,6 +102,30 @@

<section>
<title>The builder environment</title>
<para>
What environment variables does the builder have access to?
We can modify <filename>builder.sh</filename> to find out.

<programlisting><xi:include href="./07/builder2.sh.txt" parse="text" /></programlisting>

The command <literal>declare -xp</literal>
lists exported variables.
(<literal>declare</literal> is a builtin bash function.)
We cannot use <application>env</application> for this, because
<application>env</application> is part of
<application>coreutils</application> and we don't have a dependency to it
yet. We only have <application>bash</application> for now.
</para>
Create the derivation as you did before.

<xi:include href="./07/simple-derivation2.xml" />

Notice that a new path was assigned to <varname>$out</varname>.
Let's examine the file produced by this new version of the builder.

<xi:include href="./07/cat-declare.xml" />
<para>
</para>
<para>
Let's inspect those environment variables printed during the build process.
<itemizedlist>
Expand Down
1 change: 0 additions & 1 deletion pills/07/builder.sh.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
declare -xp
echo foo > $out
1 change: 1 addition & 0 deletions pills/07/builder2.sh.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare -xp > $out
19 changes: 19 additions & 0 deletions pills/07/cat-declare.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<screen xmlns="http://docbook.org/ns/docbook"><prompt>$ </prompt><userinput>cat /nix/store/0l6b6p86r73a9vlf7rfl9rdmgzh8jcwb-foo</userinput>
<computeroutput>declare -x HOME="/homeless-shelter"
declare -x NIX_BUILD_CORES="0"
declare -x NIX_BUILD_TOP="/build"
declare -x NIX_LOG_FD="2"
declare -x NIX_STORE="/nix/store"
declare -x OLDPWD
declare -x PATH="/path-not-set"
declare -x PWD="/build"
declare -x SHLVL="1"
declare -x TEMP="/build"
declare -x TEMPDIR="/build"
declare -x TERM="xterm-256color"
declare -x TMP="/build"
declare -x TMPDIR="/build"
declare -x builder="/nix/store/czx8vkrb9jdgjyz8qfksh10vrnqa723l-bash-4.4-p23/bin/bash"
declare -x name="foo"
declare -x out="/nix/store/0l6b6p86r73a9vlf7rfl9rdmgzh8jcwb-foo"
declare -x system="x86_64-linux"</computeroutput></screen>
2 changes: 2 additions & 0 deletions pills/07/cat-foo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<screen xmlns="http://docbook.org/ns/docbook"><prompt>$ </prompt><userinput>cat /nix/store/mypzica2nmd4w5c6faz49da97nih3k1y-foo</userinput>
<computeroutput>foo</computeroutput></screen>
25 changes: 2 additions & 23 deletions pills/07/simple-derivation.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
<screen xmlns="http://docbook.org/ns/docbook"><prompt>nix-repl> </prompt><userinput>d = derivation { name = "foo"; builder = "${bash}/bin/bash"; args = [ ./builder.sh ]; system = builtins.currentSystem; }</userinput>
<prompt>nix-repl> </prompt><userinput>:b d</userinput>
<computeroutput>these derivations will be built:
/nix/store/i76pr1cz0za3i9r6xq518bqqvd2raspw-<emphasis>foo.drv</emphasis>
building '/nix/store/i76pr1cz0za3i9r6xq518bqqvd2raspw-<emphasis>foo.drv</emphasis>'...
declare -x HOME="/homeless-shelter"
declare -x NIX_BUILD_CORES="4"
declare -x NIX_BUILD_TOP="/tmp/nix-build-foo.drv-0"
declare -x NIX_LOG_FD="2"
declare -x NIX_STORE="/nix/store"
declare -x OLDPWD
declare -x PATH="/path-not-set"
declare -x PWD="/tmp/nix-build-foo.drv-0"
declare -x SHLVL="1"
declare -x TEMP="/tmp/nix-build-foo.drv-0"
declare -x TEMPDIR="/tmp/nix-build-foo.drv-0"
declare -x TMP="/tmp/nix-build-foo.drv-0"
declare -x TMPDIR="/tmp/nix-build-foo.drv-0"
declare -x builder="/nix/store/q1g0rl8zfmz7r371fp5p42p4acmv297d-bash-4.4-p19/bin/bash"
declare -x name="foo"
declare -x out="/nix/store/gczb4qrag22harvv693wwnflqy7lx5pb-foo"
declare -x system="x86_64-linux"
warning: you did not specify '--add-root'; the result might be removed by the garbage collector
/nix/store/gczb4qrag22harvv693wwnflqy7lx5pb-<emphasis>foo</emphasis>
<computeroutput>[1 built, 0.0 MiB DL]

this derivation produced the following outputs:
out -> /nix/store/gczb4qrag22harvv693wwnflqy7lx5pb-<emphasis>foo</emphasis></computeroutput></screen>
out -> /nix/store/mypzica2nmd4w5c6faz49da97nih3k1y-<emphasis>foo</emphasis></computeroutput></screen>
8 changes: 8 additions & 0 deletions pills/07/simple-derivation2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<screen xmlns="http://docbook.org/ns/docbook"><prompt>nix-repl> </prompt><userinput>:l &lt;nixpkgs></userinput>
<computeroutput>Added 3950 variables.</computeroutput>
<prompt>nix-repl> </prompt><userinput>d = derivation { name = "foo"; builder = "${bash}/bin/bash"; args = [ ./builder.sh ]; system = builtins.currentSystem; }</userinput>
<prompt>nix-repl> </prompt><userinput>:b d</userinput>
<computeroutput>[1 built, 0.0 MiB DL]

this derivation produced the following outputs:
out -> /nix/store/0l6b6p86r73a9vlf7rfl9rdmgzh8jcwb-<emphasis>foo</emphasis></computeroutput></screen>