Derivation fails when using ./builder.sh - bash - no such file or directory

I have been trying to create a derivation for IUP, a portable user interface written for C. As this is the first one that I have tried, I am having a lot of trouble getting it correct and even though I seem to be following the manuals, it still fails. I am obviously doing something wrong but cannot see what and was hoping for some pointers so that I can get this one moving. I am running Nix 2.3.6 under Debian testing/bullseye, kernel 5.7.6. I have tried the derivation two ways and they fail both times and with different error messages. My first attempt was to do:

with ( import {} );

stdenv.mkDerivation rec
{
name = “iup”; # Name of the derivation

imports =
[
   ../common/local-settings.nix          # Include NIX local settings file
];

buildInputs = 
[
  coreutils-full                         # Full set of core utilities
  fftw                                   # Fast fourier transform library
  freetype                               # A font rendering engine
  glib                                   # C library of building blocks
  gnumake                                # Make software building tools
  gtk3                                   # GTK for C version 3
  gtkmm3                                 # GTK for C++ version 3
  harfbuzz                               # Open Type text shaping engine
  libGL                                  # GL library and header files
  libGLU                                 # GLU library and header files
  pkg-config                             # Package configuration for code
  webkitgtk                              # Web kit 2 libraries and headers

];

builder = “${bash}/bin/bash”; # Using BASH as our builder

args =
[
./builder.sh
“force” # Force full code fetch from SVN
“nixos” # Ensure we use script via NIX
];

meta =
{
description = “A portable user interface written for the C language.”;

  longDescription =
  ''
        A portable user interface written for the C language.  It provides
        image handling, canvases and GUI functionality.  It runs on Linux,
        Mac and Windows.
  '';

  maintainers = [ "xxxxx" ];

};
}

and when you do ‘nix-build’ it fails with:

these derivations will be built:
/nix/store/k2h9pwyimmfqff21hrq22czl1pda3vl8-iup.drv
building ‘/nix/store/k2h9pwyimmfqff21hrq22czl1pda3vl8-iup.drv’…
bash: /nix/store/rbh0is244rwvcv9a918bvmmky9i1isyk-builder.sh: No such file or directory
builder for ‘/nix/store/k2h9pwyimmfqff21hrq22czl1pda3vl8-iup.drv’ failed with exit code 127
error: build of ‘/nix/store/k2h9pwyimmfqff21hrq22czl1pda3vl8-iup.drv’ failed

When I change the derivation to the following:
with ( import {} );

stdenv.mkDerivation rec
{
name = “iup”; # Name of the derivation

imports =
[
   ../common/local-settings.nix          # Include NIX local settings file
];

buildInputs = 
[
  coreutils-full                         # Full set of core utilities
  fftw                                   # Fast fourier transform library
  freetype                               # A font rendering engine
  glib                                   # C library of building blocks
  gnumake                                # Make software building tools
  gtk3                                   # GTK for C version 3
  gtkmm3                                 # GTK for C++ version 3
  harfbuzz                               # Open Type text shaping engine
  libGL                                  # GL library and header files
  libGLU                                 # GLU library and header files
  pkg-config                             # Package configuration for code
  webkitgtk                              # Web kit 2 libraries and headers

];

builder = ./builder.sh; # Using our own custom builder

args =
[
“force” # Force full code fetch from SVN
“nixos” # Ensure we use script via NIX
];

meta =
{
description = “A portable user interface written for the C language.”;

  longDescription =
  ''
        A portable user interface written for the C language.  It provides
        image handling, canvases and GUI functionality.  It runs on Linux,
        Mac and Windows.
  '';

  maintainers = [ "xxxxxx" ];

};
}

it fails with:

these derivations will be built:
/nix/store/8nrds7wpg6r69bqqw6king5p5c07iqij-iup.drv
building ‘/nix/store/8nrds7wpg6r69bqqw6king5p5c07iqij-iup.drv’…
bash: force: No such file or directory
builder for ‘/nix/store/8nrds7wpg6r69bqqw6king5p5c07iqij-iup.drv’ failed with exit code 127
error: build of ‘/nix/store/8nrds7wpg6r69bqqw6king5p5c07iqij-iup.drv’ failed

I am completely stuck at the moment as until I can get IUP built, then I cannot move onto my C and C++ applications and write derivations for them. Any help that can be offered will be much appreciated,

First you can post code in this way to avoid mangling formatting:

```nix
nix code here (you can also use other languages after top ```)
```

Secondly, you probably didn’t want to replace builder in the first place, as you can just replace the phases such as buildPhase as shown in https://nixos.org/nixpkgs/manual/#sec-using-stdenv, like this:

stdenv.mkDerivation {
  name = "fnord-4.5";
  ...
  buildPhase = ''
    gcc foo.c -o foo
  '';
  installPhase = ''
    mkdir -p $out/bin
    cp foo $out/bin
  '';
}

So you might want something like buildPhase = "${./builder.sh} force nixos". You need to make it build and install into $out (an environment variable containing the build destination).


If you want us to help, it would be very helpful if you could provide your builder script and Nix expression so that we can try out exactly what you have and fix exactly the problems, not having to rely on guesswork. If we can recreate exactly the problems you are having, it will be more efficient to find what the problem is and to fix it.

Of course, if for some reason you cannot provide those it’s okay too, but we’ll have to rely on communication.

Now for some other problems I noticed:

  1. ‘Force full code fetch from SVN’: This will not work. You are not allowed network access in regular builders because it breaks. You’ll want to use a fetcher, specifically fetchsvn. See here: https://nixos.org/nixpkgs/manual/#chap-pkgs-fetchers, then when you assign it to src as shown in the link, your buildPhase etc. will run in the directory of a writable copy of the downloaded source.
  2. ‘Ensure we use script via NIX’: It’s a bit suspicious. If by ‘we use script via NIX’ you mean you change some stuff in the build process to make it work with Nix then it’s fine and right, but if you run the nix or nix-* programs, it’s probably not what you want. Just build it normally and put it in $out. (By the way Nix isn’t normally spelt all capitalized.)

As of why everything got screwed up when you tried using builder, I think it’s probably args not doing what you think it does, but I’m not sure why or if it’s the reason.

Many thanks for your reply. I did not publish builder.sh as it is over 1000 lines and was a debian bash shell script that was modified to run on both debian and NixOS. With your advice I think I need to make it a lot more like a Nix builder rather than trying to hold onto debian so much. Thought it might be easier to keep it as a script for both operating systems - but your helpful advice makes me realise otherwise. Thanks for the formatting tips. Will try harder on this next time.
Thanks again,