[Nix-dev] User environment hooks

Eelco Dolstra e.dolstra at tudelft.nl
Fri Oct 10 15:22:11 CEST 2008


Andres Loeh wrote:

> One way to look at nix-env is that it implicitly constructs a Nix
> derivation (called the user environment) and builds it in the store.
> Unfortunately, we never quite see the Nix expression that belongs to
> the derivation -- it really is implicit.
> 
> However, we can think about it as something like a function, lets
> call it buildUserEnvironment, applied to a list of arguments that
> typically are attribute names from the nixpkgs collection:
> 
> let
> 
>   pkgs = import ...nixpkgs...;
> 
> in
> 
>   with pkgs;
>   buildEnvironment
>     [
>       # all the packages I'm interested in
>       git
>       ghc
>       texLive
>       firefox
>       ...
>     ];

This is essentially what you can do in NixOS: there is a configuration option
environment.extraPackages where you can specify extra packages to be added to
the system-wide path.  Obviously you can use arbitrarily complicated expressions
there.  This allows purely declarative package management without using nix-env.

However, the disadvantage (sometimes advantage) is that it forces all packages
to be rebuilt/updated at the same time, as people who have OpenOffice in
environment.extraPackages will know: you can't keep old versions around.  (In
fact, if a package has disappeared from Nixpkgs, then you can't build the
configuration at all anymore.)

Nix-env gets around this because the expression that it generates uses the store
paths of the installed packages directory, i.e.

  import .../corepkgs/buildenv {
    derivations = [
      /nix/store/qwlzyznsc6snqs7axqs9csnni8ql9i6f-openoffice.org-2.4.1
      /nix/store/9b27dla8m12r1c16nvbi5kbrdiribcys-firefox-2.0.0.16-with-plugins
      ...
    ];
  };

But obviously this isn't declarative.  Any knowledge about functions used to
build the packages is gone.

So there is a tension between the declarative and "evolutionary" (store
path-based) models for nix-env.  It's not clear to me how they can be combined
in a clean way...

-- 
Eelco Dolstra | http://www.st.ewi.tudelft.nl/~dolstra/



More information about the nix-dev mailing list