Simple Nix derivation help

I’ve been through the various Pills and documentation, and (of course) there’s a lot of contradicting info. That is, a lot of stuff will NOT run on vanilla nix 2.24.9 (I don’t have any optional flake or other features enabled). I’ve also downloaded the nixpkg tarball which lists all existing nix stuff in 24.05 release (as I - at this point - don’t want it to go out and snarf this every time), and unpacked that into /opt/nix/24.05

Right now, I’ve a VERY simple case:

I have a git repo, in it a default.nix file (at the root of the repo) plus the sources I want to build. I have a script called builder.sh in that git repo at the root.

So, my default.nix looks like this:

let
  nixpkgs = /opt/nix/24.05;
  pkgs = import nixpkgs {};
in

pkgs.stdenv.mkDerivation rec {
  name = "testme";
  version = 1.0;
  system = builtins.currentSystem;
  src = "./.";
  buildInputs = with pkgs; [ SDL ];
  builder = ./builder.sh ;
}

my builder.sh (it’s a plain text file, no bash #!, but it’s set to executable) contains just 2 lines:
echo $PWD
./buildme.sh

Now, when I run nix-build default.nix it eventually fails with a line 2: ./buildme.sh: No such file or directory (and yes, buildme.sh has proper permissions and execute bit)

How come it’s not copying all my sources from the initial directory into the temp build directory? And worse, how does it find builder.sh but not buildme.sh if they’re literally in the same directory?

Remove the quotes.

Also, Working with local files — nix.dev documentation would be safer.

PS the pills are one person’s opinion from 10 years ago, not well-written, and IMO pretty useless in 2024. The 3 official manuals will get you further

And code blocks are ideally fenced with triple backticks for readability.

removing the quotes in that src line doesn’t change anything. still the same error.

And I don’t want to add the file to the derivation. I want it to be executed as part of the build of the entire derivation.

That is, builder.sh is my build command, which should execute buildme.sh which actually creates the files that are going into the derivation. I don’t expect either of those two files to eventally be in the derivation itself.

I fail to see how filesets are relevant here - they’re for copying stuff into the /nix/store/<derivation-directory>

I don’t understand what you’re looking for here. A derivation is a build recipe for nix. All files needed for the recipe need to be part of the recipe.

OK, something is funny here.

let
  nixpkgs = /opt/nix/24.05;
  pkgs = import nixpkgs {};
in

pkgs.stdenv.mkDerivation rec {
  name = "testme";
  version = 1.0;

  system = builtins.currentSystem ;
  src = ./. ;
  
  buildInputs = with pkgs; [
    SDL
  ];

  buildPhase = ''
   ./builder.sh
   '';
}

Works. Sigh.

“derivation” is the recipe, but the output of a nix-build is both the derivation file AND the finished built stuff (i.e. the /nix/store// directory). Exactly what is the latter called?

I also noticed another issue: you used builder here, that will basically blast everything that mkDerivation uses to shreds.

Instead, use buildPhase or something as such.

Yes.

Instantiating the expression you wrote results in a store derivation, and realising the store derivation results in what the manual calls a “store object”, though I’d probably just call it the build result.

OK. Pretty close now.

One last thing: is there any way (using the buildPhase methodology above) that I can tell the bash function being invoked to use the -x option so I can fully see what’s going on in the shell it creates?

Set env.NIX_DEBUG to some integer within the mkDerivation call, I’m assuming you want it at least 6.