summary refs log tree commit diff
path: root/pkgs/lib/misc.nix
diff options
context:
space:
mode:
authorMarc Weber <marco-oweber@gmx.de>2013-02-11 08:12:12 +0100
committerEvgeny Egorochkin <phreedom@yandex.ru>2013-05-08 15:43:07 +0300
commite0fab80c27377edab687b72e4383dc0022c9cde0 (patch)
tree372a78b478cf0d7a8983799c6b5f1addd0415314 /pkgs/lib/misc.nix
parent5815d184609bcf48faf7643dd29af1c9bc6b6b04 (diff)
downloadnixpkgs-e0fab80c27377edab687b72e4383dc0022c9cde0.tar
nixpkgs-e0fab80c27377edab687b72e4383dc0022c9cde0.tar.gz
nixpkgs-e0fab80c27377edab687b72e4383dc0022c9cde0.tar.bz2
nixpkgs-e0fab80c27377edab687b72e4383dc0022c9cde0.tar.lz
nixpkgs-e0fab80c27377edab687b72e4383dc0022c9cde0.tar.xz
nixpkgs-e0fab80c27377edab687b72e4383dc0022c9cde0.tar.zst
nixpkgs-e0fab80c27377edab687b72e4383dc0022c9cde0.zip
experimental/multiple-versions-in-one-file
This patch introduces mergeAttrsByVersion to lib.

In some cases it does make sense to keep "experimental" and "older" versions of
the same package in one file because it follows the "do it once only" principle.
Very often many versions share their build instructions - so even though I
understand Eelcos opinion that different versions should be put into their own
.nix files - its my feeling telling me that this is fastest for most cases.

I agree with Eelco that if tweaks for individual versions become too much they
should be split into individual files.

See comments above mergeAttrsByVersion learn about its usage.

Signed-off-by: Marc Weber <marco-oweber@gmx.de>
Diffstat (limited to 'pkgs/lib/misc.nix')
-rw-r--r--pkgs/lib/misc.nix34
1 files changed, 34 insertions, 0 deletions
diff --git a/pkgs/lib/misc.nix b/pkgs/lib/misc.nix
index 32390b0d192..bd57d2b6518 100644
--- a/pkgs/lib/misc.nix
+++ b/pkgs/lib/misc.nix
@@ -317,6 +317,40 @@ rec {
   mergeAttrsByFuncDefaults = foldl mergeAttrByFunc { inherit mergeAttrBy; };
   mergeAttrsByFuncDefaultsClean = list: removeAttrs (mergeAttrsByFuncDefaults list) ["mergeAttrBy"];
 
+  # merge attrs based on version key into mkDerivation args, see mergeAttrBy to learn about smart merge defaults
+  #
+  # This function is best explained by an example:
+  #
+  #     {version ? "2.0"} :
+  #
+  #     mkDerivation (mergeAttrsByVersion "package-name" version 
+  #       { # version specific settings
+  #         "git" = { src = ..; preConfigre = "autogen.sh"; buildInputs = [automake autoconf libtool];  };
+  #         "2.0" = { src = ..; };
+  #       }
+  #       {  // shared settings
+  #          buildInputs = [ common build inputs ];
+  #          meta = { .. }
+  #       }
+  #     )
+  #
+  # Please note that e.g. Eelco Dolstra usually prefers having one file for
+  # each version. On the other hand there are valuable additional design goals
+  #  - readability
+  #  - do it once only
+  #  - try to avoid duplication
+  #
+  # Marc Weber and Michael Raskin sometimes prefer keeping older
+  # versions around for testing and regression tests - as long as its cheap to
+  # do so.
+  #
+  # Very often it just happens that the "shared" code is the bigger part.
+  # Then using this function might be appropriate.
+  #
+  # Be aware that its easy to cause recompilations in all versions when using this function
+  mergeAttrsByVersion = name: version: attrsByVersion: base:
+    mergeAttrsByFuncDefaultsClean [ { name = "${name}-${version}"; } base (maybeAttr version (throw "bad version ${version} for ${name}") attrsByVersion)];
+
   # sane defaults (same name as attr name so that inherit can be used)
   mergeAttrBy = # { buildInputs = concatList; [...]; passthru = mergeAttr; [..]; }
     listToAttrs (map (n : nameValuePair n lib.concat)