[Nix-dev] Generating nix expression vs. ad-hoc generation of derivations (was: Re: [Nix-commits] [NixOS/nixpkgs] c6a2a1: ffmpeg: Update to latest version 0.11.1.)

2012-07-24 Thread Florian Friesdorf
On Tue, 24 Jul 2012 19:40:27 +0200, Vladimír Čunát vcu...@gmail.com wrote:
 On 24 July 2012 19:20, Florian Friesdorf f...@chaoflow.net wrote:
  I understand the wish for having it in one expression and keep
  duplication low. But I think the expressions should be as simple as
  possible and, as Eelco says, with the possibility to change them
  independently.
 
 Well, OK, it seems to be the major opinion here, so I'm going to
 respect it when writing expressions.
 
 
  I think generating expressions is a better solution to target
  duplication than having expressions deal with different versions. This
  is already done for at least xorg and haskellPackages.
 
 But that is exactly what I do... you supply a version and an
 expression for the version is returned.
 
 If we could generate dependencies and options from standard build
 systems like autotools, cmake, ... that would really be great. Perhaps
 with some amendments because of broken packages, but still it would
 save so much code

If I understand correctly you want / are doing something like this:

There is a nix expression that when called returns a nix derivation for
a specific version of ffmpeg. I would call this ad-hoc generation of
derivations using the nix language. I might be mistaken, but I think
in a way this is similar to the approach Marc is using in his overlays
[1].

A recurring discussion seems to be whether derivations should be
generated on the fly like this or whether there should be nix
expressions in nixpkgs that have a one-to-one correspondance to
derivations.

These expressions can also be generated, but that happens prior and
independent to running nix, in whatever language desired.

I see the following advantages:

- generated expressions look very similar to manually created ones
  making it much easier to understand what is going on

- no knowledge needed of the tools used to create the expressions.
  Instead it is easily possible to change an expression if needed and
  those knowing the tools can integrate the changes into the tools
  generating the expressions. AFAIK done like that by Peter and Andres
  for haskellPackages.

- magic, like dependency-resolution, is done outside of nix, keeping the
  complexity of nix and nixpkgs low.

It feels that if we are able to generate derivations, we should do so,
but put them into files (nixpkgs) and use these files as the interface
between nix and the algorithms that help us to generate the derivations.


1. arbitrary source (hackage, pypi, marmalade, different ffmpeg versions)

2. magic tools (sharing code) to generate expression that declare
   derivations, in contrast to generating them

3. nixpkgs

4. nix/nixos tools to install these package

What do you not like about this approach and in what way do you think
generating derivations on the fly is better?

regards
florian

[1] http://nixos.org/wiki/Nix(OS)_related_repositories_and_work
-- 
Florian Friesdorf f...@chaoflow.net
  GPG FPR: 7A13 5EEE 1421 9FC2 108D  BAAF 38F8 99A3 0C45 F083
Jabber/XMPP: f...@chaoflow.net
IRC: chaoflow on freenode,ircnet,blafasel,OFTC


pgpFl9mKRDr9L.pgp
Description: PGP signature
___
nix-dev mailing list
nix-dev@lists.science.uu.nl
http://lists.science.uu.nl/mailman/listinfo/nix-dev


Re: [Nix-dev] Generating nix expression vs. ad-hoc generation of derivations (was: Re: [Nix-commits] [NixOS/nixpkgs] c6a2a1: ffmpeg: Update to latest version 0.11.1.)

2012-07-24 Thread Vladimír Čunát
Just a line of warning, I'm a great dreamer... that's probably related
to why I do *theoretical* computer science :-)

On 24 July 2012 20:10, Florian Friesdorf f...@chaoflow.net wrote:
 If I understand correctly you want / are doing something like this:

 There is a nix expression that when called returns a nix derivation for
 a specific version of ffmpeg. I would call this ad-hoc generation of
 derivations using the nix language. I might be mistaken, but I think
 in a way this is similar to the approach Marc is using in his overlays
 [1].

No, I do nothing this complicated. I just used a classic technique in
functional programming: I *added a first parameter*, so by supplying
the package version you get the usual nix expression for that ffmpeg
version [video2]. This was just very simple modification and so it was
useful to implement directly in nix.

[video2] http://github.com/vcunat/nixpkgs/commits/vlada/video2


 A recurring discussion seems to be whether derivations should be
 generated on the fly like this or whether there should be nix
 expressions in nixpkgs that have a one-to-one correspondance to
 derivations.

 These expressions can also be generated, but that happens prior and
 independent to running nix, in whatever language desired.

I don't see much difference. The generating language can be anything
in both cases, if we have a good interface. The most important thing
IMO is that in git we have only the primary stuff and generators
(nothing generated).


 I see the following advantages:

 - generated expressions look very similar to manually created ones
   making it much easier to understand what is going on

Not really needed, you should normally only read the generators and
leave the generated content only for nix utilities.

 - no knowledge needed of the tools used to create the expressions.
   Instead it is easily possible to change an expression if needed and
   those knowing the tools can integrate the changes into the tools
   generating the expressions. AFAIK done like that by Peter and Andres
   for haskellPackages.

You can always pretty-print the generated nix expression and modify
it. From experience there will always be cases when the generator
doesn't output exactly what we want (broken cabal files, etc.), so we
will want to patch some of the outputs.

 - magic, like dependency-resolution, is done outside of nix, keeping the
   complexity of nix and nixpkgs low.

Well, this is a topic for a long discussion. I would personally rather
improve nix so it *could* handle dependency resolution. I'm not saying
we should normally use it for regular packages, as too much
variability hurts -- that's a problem in gentoo, two people are then
quite unlikely to build the same thing -- it has many unpleasant
implications.

 It feels that if we are able to generate derivations, we should do so,
 but put them into files (nixpkgs) and use these files as the interface
 between nix and the algorithms that help us to generate the derivations.

Certainly, we should generate nix expressions. The question is what
parameters will the generators accept -- how to choose the versions,
etc.

Also I again emphasize that distributing generated expressions is IMO
bad (or having them in git). We should only distribute generators and
patches for some broken to-be-generated expressions.

 1. arbitrary source (hackage, pypi, marmalade, different ffmpeg versions)

 2. magic tools (sharing code) to generate expression that declare
derivations, in contrast to generating them

 3. nixpkgs

 4. nix/nixos tools to install these package

 What do you not like about this approach and in what way do you think
 generating derivations on the fly is better?

I see storing the generated expressions *only as a caching mechanism*.
Nothing less, nothing more.


 On Tue, 24 Jul 2012 19:40:27 +0200, Vladimír Čunát vcu...@gmail.com wrote:
 If we could generate dependencies and options from standard build
 systems like autotools, cmake, ... that would really be great. Perhaps
 with some amendments because of broken packages, but still it would
 save so much code

I imagine it like this. Building:

- b1. Some *front-end* somehow generates the derivations to be built
(that is, nix expressions). That can be even a very complicated
constraint-solving gui tool which anyone configures according to his
needs. Various sources of expressions, substitutes, present packages
and other user demands can be considered here. A very complicated
process, in full strength perhaps not suitable for nix or similar
language, rather something that can use classic constraint-solving
libraries, full-blown gui etc.

- b2. The resulting expression is passed to nix as usual.

- b3. Some *environment-builder* is invoked to update the runtime
environment as required. In nixos case it would also restart services,
etc. Perhaps it could also do some configuration migration if versions
differ too much (in cases where the package don't do this well
automatically).