[Nix-dev] Re: Trying to understand multiple versions

Yury G. Kudryashov urkud+nix at ya.ru
Fri Apr 30 21:21:02 CEST 2010


Josh wrote:
> It appears that package dependencies are specified just by package,
> and not version; is this correct?
Not really. In package's default.nix we just list dependencies by their 
names, but in top-level/all-packages.nix all the dependencies are passed to 
the function defined in default.nix. Usually they're just passed by name 
which means "pass default version" but sometimes we pass specific versions 
(see gtkLibs* in pkgs/top-level/all-packages.nix).

> Consider the following scenario:
In the following answers I assume that you're installing packages using nix-
env -i, not using NixOS.
> 1. I install package Foo-1.0, which depends on FunnyLib. The latest
> version of FunnyLib happens to be 1.0. Assumption: Package
> FunnyLib-1.0 will automatically be installed as well.
You should replace "the latest version" with "the default version". Package 
FunnyLib will be automatically built but will not added to your nix 
environment unless Foo puts it into "propagated env packages".
> 2. The FunnyLib-1.1 package is released. I upgrade FunnyLib to version
> 1.1. Assumption: Foo will continue to use FunnyLib-1.0, and I'll have
> 2 versions of FunnyLib installed.
Foo will continue to use FunnyLib-1.0 unless you're using some LD_* magic.
> 3. I install package Bar-1.0, which also uses FunnyLib. Assumption:
> Nix sees that FunnyLib-1.1 is installed, and will use that.
Nix will use the version of FunnyLib specified as build dependency of 
Bar-1.0. If Bar just use "FunnyLib" (without specific version), it will use 
default version of FunnyLib. The default version depends on nixpkgs state, 
not on your environment.
> 4. I run garbage collection. Assumption: nothing happens, since both
> versions of FunnyLib are currently in use.
Yes, you're right.
> 5. I "upgrade" Foo-1.0, even though there are no new versions
> available, to its already installed version. Assumption: it gets
> re-linked against FunnyLib-1.1; now, FunnyLib-1.0 is eligible for
> garbage collection.
That's true if in the new nixpkgs collection FunnyLib-1.1 is passed to Foo, 
not FunnyLib-1.0.
> Are my assumptions correct? Is there anything I'm missing above?
> 
> Suppose I never upgraded FunnyLib in step 2, but the updated package
> was available. Then I installed Bar as in step 3. Would Bar use the
> already installed, version of FunnyLib, or would it download and
> install the latest version? I would assume the latter.
Bar would download and install the version of FunnyLib passed to Bar in all-
packages.nix. Normally we just use "inherit FunnyLib" which means "default 
version". If default version have changed, Bar will download, install and 
use the new default version.
> Now, suppose that Foo uses some deprecated features of FunnyLib, and
> so requires a particular version, or any version in some specified
> range. How can this be handled?
funnyLib = import ../development/libraries/FunnyLib { ... };
funnyLib10 = import ../development/libraries/FunnyLib/1.0.nix { ... };
foo = import ../foo {
funnyLib = funnyLib10;
}
> A lot of software looks for a config or settings file in some standard
> directory like etc, as well as looking in the user's directory. I
> assume that under the Nix way of doing things, this file is inside the
> Nix store, in the directory for that program, yes? (I understand that
> Nix has built-in support for managing the configs of some programs; my
> concern is with everything else.)
That's true unless we need to change the configuration after package is 
installed. If we need this, we create an additional "package" foo-config, 
and foo-wrapper which tells foo to use foo-config configuration. Sometimes 
we decide that foo is definitely system-wide service, and tell it to use 
/etc instead of $out/etc. In these cases we symlink needed foo-config/etc to 
/etc (at least in NixOS).
> Assumption: every version of a
> program will have its own config file, unless I hardlink them
> together; and so every time a package is upgraded its configuration
> gets reset to the defaults... Am I correct?
Yes, with one additional remark: you must not change the files in /nix/store 
after the package is installed. In particular, /etc files.




More information about the nix-dev mailing list