# Baby step #2 - using tree in the ./builder script

**URL:** https://discourse.nixos.org/t/baby-step-2-using-tree-in-the-builder-script/1571
**Category:** Help
**Created:** [December 2, 2018, 5:33pm UTC](https://discourse.nixos.org/t/baby-step-2-using-tree-in-the-builder-script/1571 "2018-12-02T17:33:02Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![alpinekid](https://discourse.nixos.org/user_avatar/discourse.nixos.org/alpinekid/32/748_2.png) [@alpinekid](https://discourse.nixos.org/u/alpinekid)
#### Post date: [December 2, 2018, 5:33pm UTC](https://discourse.nixos.org/t/baby-step-2-using-tree-in-the-builder-script/1571/1 "2018-12-02T17:33:02Z")

</div>

I’m trying to take the next 3 baby steps but none worked.  
Environment: ubuntu 16.4

Lets take the the one I want most 1st.  
I’m trying to use tree in my build script.  
I added it to my system using  
` nix-env -i tree`  
and it works.

```auto
which tree
/home/mral/.nix-profile/bin/tree
mral@sunburst20171202:/nix/store/4c4qq58y8yyj3dyhzv3737km0r7hbxpp-atrTest-0.0.1$ whereis tree
tree: /nix/store/p0cb4i0kwvkajxmvrzwfdsh5rzjrgig7-user-environment/bin/tree /usr/share/man/man3/tree.3.gz

```

I can run tree from a standard bash shell using unbutu’s bash shell and  
from the nix-shell.  
When I try to build my package is fails and I’m sure its because of the pure  
build stuff that nix does, clearing path etc.  
What I dont know is how to declare tree as a depencency.

I’ve tried all kinds of incantations following hints that I’ve seen in the manual.  
Various combination of import, using { tree} or {} all in various places  
and none have worked and none of the error messages gave me enough information  
to know what I was doing wrong.  
The nix expression is:

```auto
#atrTest.nix
let
  pkgs = import <nixpkgs> {};
in

pkgs.stdenv.mkDerivation rec {
		name = "atrTest-0.0.1";
		#args = [" -v "];
		builder = ./builder.sh;
		src = ./makefile;
		extraStuff = "extra stuff${name} for shell";
		postInstall = ''
	mkdir ''${out}/Assets
	echo "all done now running postInstall for ${name}" > ''${out}/Assets/log.txt
'';
		}

```

The build script is:

```auto
#builder.sh
source $stdenv/setup

echo "hi from $0, pwd=$(pwd), myName=${extraStuff}, arg=$1"
mkdir -p ${out}/atrnix
tree > ${out}/fileList.xml
echo "hi from nix-build" > ${out}/atrnix/hello.txt
echo "${postInstall}" >> ${out}/postSetup

```

I’m invoking it from a nix-shell as:

```auto
 nix-build -K atrTest.nix
these derivations will be built:
  /nix/store/9jnk7i5nr5i1ndzb3sja399xnfv4ykkp-atrTest-0.0.1.drv
building '/nix/store/9jnk7i5nr5i1ndzb3sja399xnfv4ykkp-atrTest-0.0.1.drv'...
hi from /nix/store/9k6jjnplqpg8mwjyy0wjailrng5g7gl9-builder.sh, pwd=/tmp/nix-build-atrTest-0.0.1.drv-5, myName=extra stuffatrTest-0.0.1 for shell, arg=
/nix/store/9k6jjnplqpg8mwjyy0wjailrng5g7gl9-builder.sh: line 6: tree: command not found
note: keeping build directory '/tmp/nix-build-atrTest-0.0.1.drv-5'
builder for '/nix/store/9jnk7i5nr5i1ndzb3sja399xnfv4ykkp-atrTest-0.0.1.drv' failed with exit code 127
error: build of '/nix/store/9jnk7i5nr5i1ndzb3sja399xnfv4ykkp-atrTest-0.0.1.drv' failed

```

I can see that it cann’t find the tree command but  
how do I declare it as a dependency so it will be found?

I’ll start a seperate thread for the args problem, its been commented out for now.  
I’ll start a seperate thread for the postInstall, its showing up as env variable  
instead of being executed like I expected.

---

<div class="post-metadata">

### Author: ![ryantm](https://discourse.nixos.org/user_avatar/discourse.nixos.org/ryantm/32/900_2.png) [@ryantm](https://discourse.nixos.org/u/ryantm)
#### Post date: [December 2, 2018, 6:45pm UTC](https://discourse.nixos.org/t/baby-step-2-using-tree-in-the-builder-script/1571/2 "2018-12-02T18:45:27Z")

</div>

You need to add `buildInputs = [pkgs.tree];` to the derivation. Technically you should use `nativeBuildInputs` because you are only using tree at build time.

---

<div class="post-metadata">

### Author: ![alpinekid](https://discourse.nixos.org/user_avatar/discourse.nixos.org/alpinekid/32/748_2.png) [@alpinekid](https://discourse.nixos.org/u/alpinekid)
#### Post date: [December 2, 2018, 7:43pm UTC](https://discourse.nixos.org/t/baby-step-2-using-tree-in-the-builder-script/1571/3 "2018-12-02T19:43:20Z")

</div>

> [@ryantm](#):
>
> buildInputs = [pkgs.tree];

Thanks that worked. I extended my test by using md5sum and to my surprise it worked without adding it to the buildInputs attribute list. Is there a list or way to find out what the set of utilities that are present by default and then I will know that if I’m using something not on the list I have to add it to buildInputs.

I’m going to think about your refinement about buildtime vs runtime. I know what that means but I’m not far enough along the learning curve to really know why thats important.

---

<div class="post-metadata">

### Author: ![ilikeavocadoes](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/i/848f3c/32.png) [@ilikeavocadoes](https://discourse.nixos.org/u/ilikeavocadoes)
#### Post date: [December 3, 2018, 6:17am UTC](https://discourse.nixos.org/t/baby-step-2-using-tree-in-the-builder-script/1571/4 "2018-12-03T06:17:32Z")

</div>

I like your style. Please continue posting these baby steps -threads, it’s interesting 🙂

I’ve been using nixos for a year now and my biggest complaint is the unstructured and partial nature of documentation. Especially a proper API listing that would list all the functions and their arguments etc. This would make a fine project…

---

<div class="post-metadata">

### Author: ![alpinekid](https://discourse.nixos.org/user_avatar/discourse.nixos.org/alpinekid/32/748_2.png) [@alpinekid](https://discourse.nixos.org/u/alpinekid)
#### Post date: [December 3, 2018, 10:18am UTC](https://discourse.nixos.org/t/baby-step-2-using-tree-in-the-builder-script/1571/5 "2018-12-03T10:18:59Z")

</div>

Thanks @ilikeavocadoes for the encouragement. Its nice to know I’m adding something valuable.
