How to extract and build when using local tar files

I am trying to build the libraries and documentation for the lua binaries. To do this you download two tar files and then extract and build them. Problem I am having is that I cannot work out how to make Nix find the file in the directory. I have the two tar.gz files in the same directory as the derivation, but when I try to tar/unpack the files the derivation fails because the file is not in the directory in which the derivation is being built - which makes sense. I have tried copying the file into $out, have tried hard coding the names of the two tar files - all to no avail. My derivation is as follows:

{
   pkgs,
   stdenv,
   ...
}:


let

   project-name = "lua5_4_2";                       # Name of derivation

   version = "5.4.2";                               # Version of the file

   lua_doc = "./lua-${version}_Docs_html.tar.gz";     # Documentation for LUA

   lua_source = "./lua-${version}_Sources.tar.gz";    # Source code to build LUA

in

stdenv.mkDerivation rec
{

   name = "${project-name}";                        # Name of the derivation

   srcs =
   [
      lua_doc

      lua_source
   ];

   unpackPhase =
''
      runHook preUnpack

      
      for s in $srcs
      do
         tar --extract --file=$s
      done


      runHook postUnpack
'';

      configurePhase =
''
      runHook preConfigure


      #
      #Now we need to replace hard coded paths, etc, from the make file so that
      #it works correctly with Nix.
      #
      substituteInPlace Makefile    \
         --replace /usr/local $out  \
         --replace 'PLAT= guess' 'PLAT=linux'

      #
      #Now we need to create the output directory.
      #
      mkdir --parents $out


      runHook postConfigure
'';

      buildPhase =
''
      runHook preBuild


      make


      runHook postBuild
'';

      installPhase =
''
      runHook preInstall


      #
      #Now we need to install the software.
      #
      make install

      #
      #Now we need to create the directory to store the library in.
      #
      cd $out/lib

      #
      #As the IUP module requires a versioned 'liblua' library and neither NixOS
      #or LUA BINARIES provide it, we must perform the task ourselves.  The
      #below version must match the value of LUA_SUFFIX as defined in the IUP
      #derivations.
      #
      ln --symbolic --verbose liblua.a liblua54.a


      runHook postInstall
'';
}

I have searched the forum but could not find any answers that worked for me. Is it possible to do what I need to do ? Any help would be appreciated as I have spent hours trying to solve this one.
Thanking you for your time.

Solved part of the problem, by replacing -

lua_doc = "./lua-${version}_Docs_html.tar.gz";     # Documentation for LUA

lua_source = "./lua-${version}_Sources.tar.gz";    # Source code to build LUA

with

   lua_doc = ./lua-5.4.2_Docs_html.tar.gz;          # Documentation for LUA

   lua_source = ./lua-5.4.2_Sources.tar.gz;         # Source code to build LUA

Only thing that I cannot (yet) solve is how to use the ‘version’ variable in the two source code file names so that I can avoid having the version of the files in more than one place.

  1. Can’t you fetchurl/fetch* the files?

  2. ./. + "/lua-${version}_Sources.tar.gz" might work

@7c6f434c - I had been thinking of pathing with the ./. and then using + to create the entire thing, but your solution is neater than mine, so thank you for that. Where do I find answers such as these - having so many Nix manuals makes it hard to work out where to start searching. While I have had great support from this forum, and have read plenty of posts, I just don’t want to keep on posting such beginner questions if I knew where to best look.

Where do I find answers such as these - having so many Nix manuals makes it hard to work out where to start searching.

The standard issue is — reading the Nix manual throughout helps with understanding what is possible, but once one knows some practices from reading/writing Nixpkgs and, worse, discussions of proposals of official best practices, it is hard both to know which techniques are mentioned in which external guides, and sometimes even which techniques are non-obvious even after reading the Nix manual.

Technically speaking, https://nixos.org/manual/nix/stable/print.html#simple-values

Antiquotation is supported in any paths except those in angle brackets. ./${foo}-${bar}.nix is a more convenient way of writing ./. + “/” + foo + “-” + bar + “.nix” or ./. + “/${foo}-${bar}.nix”. At least one slash must appear before any antiquotations for this to be recognized as a path. a.${foo}/b.${bar} is a syntactically valid division operation. ./a.${foo}/b.${bar} is a path.

Oooh, so with a fresh enough Nix you could even get away without quotes. Didn’t think of it.