NixOS / nix-pills

Creative Commons Attribution Share Alike 4.0 International
394 stars 116 forks source link

Nix Pill Nr. 10 builder.sh ./configure not found #124

Open ThoenigAdrian opened 4 years ago

ThoenigAdrian commented 4 years ago

Trying out Nix Pill Nr. 10 Part 1:

It says:

source builder.sh

But this fails with :

bash: ./configure: No such file or directory

thus i added some debug code which print the directory name found by the builder.sh:

for d in *; do
  if [ "$src" == *"$d"* ] && [ -d "$d" ]; then
    cd "$d"
    echo "$d" # THIS IS THE DEBUG CODE I ADDED
    break
  fi
done

To my suprprise this prints "Desktop" instead of "hello-2.10" . Which makes sense because this loop (iiuic) iterates over every file and if it's a directory it cd's into it.

jane@nixos:~]$ ls -l total 6180 -rw-r--r-- 1 jane users 362 Jan 24 08:26 autotools.nix -rw-r--r-- 1 jane users 371 Jan 24 09:47 builder.sh drwxr-xr-x 2 jane users 4096 Dec 28 20:04 Desktop drwxr-xr-x 2 jane users 4096 Dec 28 20:04 Documents drwxr-xr-x 2 jane users 4096 Jan 21 10:44 Downloads drwxr-xr-x 12 jane users 4096 Nov 16 2014 hello-2.10 -rw-r--r-- 1 jane users 725946 Jan 21 10:57 hello-2.10.tar.gz -rw-r--r-- 1 jane users 140 Jan 24 09:31 hello.nix [....]

and Desktop is the first directory therefore it will cd into "Desktop" instead of "hello-2.10" .

Imo this is a bug in builder.sh.

With the following workaround it will work:

mkdir empty
cp hello.nix ./empty/
cp autotools.nix ./empty/
cp hello-2.10-tar.gz ./empty/
cp builder.sh ./empty/

But I think the proper way would be to change the "cd"-logic in builder.sh

jtojnar commented 4 years ago

We could make the builder error out when there are multiple directories in $PWD like the real deal does

https://github.com/NixOS/nixpkgs/blob/40e51d2092f1011c110c895e2818636cc25d4f09/pkgs/stdenv/generic/setup.sh#L881-L904

but as you can see that would unnecessarily increase the builder complexity without adding didactic value.

It is common practice to run tutorials in their own directory, if just for the ease of clean up afterwards. It will probably be better to add such suggestion to https://nixos.org/nixos/nix-pills/working-derivation.html#idm140737316246784 instead.

ThoenigAdrian commented 4 years ago

yes a note in the beginning would be fine as well :)