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

Nix Pills - error in example code - Chapter 8 - Generic Builders #225

Open
1 task
D3vil0p3r opened this issue Dec 9, 2023 · 3 comments
Open
1 task

Nix Pills - error in example code - Chapter 8 - Generic Builders #225

D3vil0p3r opened this issue Dec 9, 2023 · 3 comments

Comments

@D3vil0p3r
Copy link

D3vil0p3r commented Dec 9, 2023

Introduce your stance
In Nix Pills Chapter 8 - Generic Builders there is an error inside the example code.

Describe the issue
builder.sh is shown to be:

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

tar -xf $src

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

./configure --prefix=$out
make
make install

and buildInputs is empty and defined in `autotools.nix shown as:

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

When nix-build hello.nix is run, it produces the error:

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

It occurs because PATH variable defined in autotools.nix stores paths contained in baseInputs instead of buildInputs so it cannot find the tar executable coming from gnutar.

To fix this either in the for loop of builder.sh ALSO baseInputs along with buildInputs or define gnutar inside buildInputs = []; of autotools.nix file. Be free to choose the most elegant approach.

Page links
https://nixos.org/guides/nix-pills/generic-builders

Additional context
Add any other context about the problem here.

  • I already created a Pull Request
@garbas garbas transferred this issue from NixOS/nixos-homepage Dec 10, 2023
@henrik-ch
Copy link
Contributor

I think that the problem with the code above is that the suggested exercise hasn't been completed yet - please see this section of the page:

Exercise: Complete the new builder.sh 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.

please see here below a builder.sh modified accordingly.

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

tar -xf $src

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

./configure --prefix=$out
make
make install

and hello.nix

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

and autotools.nix - I think that this is exactly as you have it but just to make sure:

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

running nix-build hello.nix with the files as above, I think that the example should work.

I think that it could be helpful to many people not to leave this exercise as an open point with no listed solution. I am thinking of adding some type of accordion/tip section to make sure that everyone converges on the solution, but I don't know how that can be achieved yet.

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-12-11-documentation-team-meeting-notes-99/36866/1

@MikHulk
Copy link

MikHulk commented Apr 4, 2024

So it's not:

Just a matter of choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

4 participants