[Nix-dev] Re: Handle runtime dependencies

Nicolas Pierron nicolas.b.pierron at gmail.com
Mon Mar 17 22:02:46 CET 2008


On Mon, Mar 17, 2008 at 9:26 PM, Ludovic Courtès <ludo at gnu.org> wrote:
> Salut Nicolas,  ;-)
>
>  I'm still having a hard time trying to understand what you propose.
>
>  "Nicolas Pierron" <nicolas.b.pierron at gmail.com> writes:
>  > I have found a way to handle runtime dependencies which offer the
>  > opportunity to not recompile a program if its runtime dependencies
>  > have changed.
>
>  Can you give an example of what you call a "run-time dependency"?  Can
>  you illustrate it with a concrete package?

Sure, here is an example not clean yet but the code inside the
buildCommand could be generate to only keep the wrapper over "gitk"
and "git-gui". The buildCommand link files or create a wrapper around
a tool with "makeWrapper" that targets the original file.

   runtimeDependencies = { # Tcl/Tk, for `gitk'
     buildInputs = [ tcl tk makeWrapper ];

     buildCommand = ''
       ensureDir $out/
       for dir in $(ls $src/); do
         if test "$dir" = "bin"; then
           ensureDir $out/$dir/
           for f in $(ls $src/$dir/); do
             # wrapper over gitk and git-gui
	     if test "$f" = gitk -o "$f" = git-gui; then
	       makeWrapper $src/$dir/$f $out/$dir/$f	\
                 --set TK_LIBRARY "${tk}/lib/tk8.4"	\
                 --prefix PATH : "${tk}/bin"
             else
               ln -s $src/$dir/$f $out/$dir/$f
             fi
           done;
         else
           ln -s $src/$dir $out/$dir
         fi
       done
       '';
   };

In this case Tk is not a dependency of "git" and when a new version of
Tk is available git is not recompiled, only the wrapper scripts.

>  >From the discussion that followed, I've had the impression that you were
>  referring to packages that have undeclared dependencies, such as
>  dependencies on executables.  Is this correct?

Yes.

>  Assuming this is correct, then this packages are "impure", and I'd
>  assume the Nixish way to solve it is to make wrappers for those parts of
>  the package that are impure.

I admit that a "pure" package should not have any run-time
dependencies since it should be compiled with its dependencies but for
the cases that exists, we do not want to compile again the source for
something that is not used.

So the run-time dependencies use the fact that packages are "impure"
to compile less when there is a new version of program needed at the
execution.

>  In general, Nix doesn't permit "relocation".  For instance, an
>  executable is supposed to be always dynamically linked against the very
>  libraries that were used at build-time, and this cannot be changed at
>  run-time.  Likewise, shell scripts that refer to commands with
>  non-absolute paths should be wrapped with, e.g.,
>
>   wrapProgram "script.sh" --prefix PATH : \
>               /nix/store/xxx-some-dependency/bin

Which means if the dependency is not required at build-time then the
relocation is possible and the run-time dependecies are used to fill
the environment with the paths that are needed.

-- 
Nicolas Pierron



More information about the nix-dev mailing list