Open D3vil0p3r opened 10 months ago
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.
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
So it's not:
Just a matter of choice.
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:and
buildInputs
is empty and defined in `autotools.nix shown as:When
nix-build hello.nix
is run, it produces the error:It occurs because
PATH
variable defined inautotools.nix
stores paths contained inbaseInputs
instead ofbuildInputs
so it cannot find thetar
executable coming fromgnutar
.To fix this either in the
for
loop ofbuilder.sh
ALSObaseInputs
along withbuildInputs
or definegnutar
insidebuildInputs = [];
ofautotools.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.