Stuck on exercise in Nix Pills chapter 8


I am running on NixOS 21.05.

I am stuck on completing the excercise in Nix Pills Chapter 8.3.

Exercise: Complete the new by adding $baseInputs in the for loop together with $buildInputs . As you noticed, we passed that new variable in the derivation. Instead of merging buildInputs with the base ones, we prefer to preserve buildInputs as seen by the caller, so we keep them separated. Just a matter of choice.

I have limited bash experience, so I get stuck here. I suppose some bash knowledge is good to have, but I would rather get on with learning nix :grinning_face_with_smiling_eyes: No idea how to do this, and the following Nix Pill seems to depend on it, where I get this message running the nix-store -r command:

❯ nix-store -r /nix/store/7rmv83d9lwhd4z37479irw54dlsg0qgg-hello.drv
this derivation will be built:
building '/nix/store/7rmv83d9lwhd4z37479irw54dlsg0qgg-hello.drv'...
/nix/store/ line 7: tar: No such file or director

Is it possible this could be related? Struggling to see if I have made any typos, but tried to just copy paste and I am getting the same results.

Here are the relevant files: (as mentioned, I didn’t know excactly what to do, so I left it as is):

set -e
unset PATH
for p in $buildInputs; do
  export PATH=$p/bin${PATH:+:}$PATH

tar -xf $src

for d in *; do
  if [ -d "$d" ]; then
    cd "$d"

./configure --prefix=$out
make install


pkgs: attrs:
with pkgs;
let defaultAttrs = {
  builder = "${bash}/bin/bash";
  args = [ ./ ];
  baseInputs = [ gnutar gzip gnumake gcc binutils-unwrapped coreutils gawk gnused gnugrep ];
  buildInputs = [ ];
  system = builtins.currentSystem;
derivation (defaultAttrs // attrs)


  pkgs = import <nixpkgs> { };
  mkDerivation = import ./autotools.nix pkgs;
mkDerivation {
  name = "hello";
  src = ./hello-2.10.tar.gz;

And as mentioned, I run this command per 9.3

nix-instantiate hello.nix

with the following output

warning: you did not specify '--add-root'; the result might be removed by the garbage collector

So far so good.

But when I run

nix-store -r /nix/store/7rmv83d9lwhd4z37479irw54dlsg0qgg-hello.drv

I get this:

this derivation will be built:
building '/nix/store/7rmv83d9lwhd4z37479irw54dlsg0qgg-hello.drv'...
/nix/store/ line 7: tar: No such file or directory
error: builder for '/nix/store/7rmv83d9lwhd4z37479irw54dlsg0qgg-hello.drv' failed with exit code 127;
       last 1 log lines:
       > /nix/store/ line 7: tar: No such file or directory
       For full logs, run 'nix log /nix/store/7rmv83d9lwhd4z37479irw54dlsg0qgg-hello.drv'.

I do have the hello-2.10.tar.gz file in the same folder, downloaded from In earlier parts of the tutorial, I was successful in unpacking it.

Oh, I looked into chapter 10, and it gives away the solution there:

for p in $baseInputs $buildInputs; do
  export PATH=$p/bin${PATH:+:}$PATH

Simple enough if you know a bit of bash I guess :slight_smile: In my opinion as a beginner, this solution should be given right away instead of making it a bash exercise that can confuse a beginner :blush:

It took you just 36 minutes to cheat the exercise :wink: . More seriously, the pills are mostly a journey on building software with Nix that clearly expects the user to have some background on getting around on a unix system and builds upon that to explain Nix’s peculiarities… It’s an approach to Nix. By the way, it makes you exercise with bash because the stdenv builder script is written in Bash, so if you’re gonna use it, it may be good to know it a bit. As you have learned, if you feel stranded, just ask!


Thanks! That is noted :slight_smile: I have learned lots from it so far regardless.

You are probably right in that I need deeper UNIX and bash knowledge to grasp it all fully.