From 2405d872307fbeed7a29aff162c4f8172c30ca8f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 30 Mar 2009 13:22:19 +0000 Subject: [PATCH] * Move some functions for manipulating meta and name attributes out of all-packages.nix and into lib. svn path=/nixpkgs/trunk/; revision=14778 --- pkgs/lib/default.nix | 5 +++-- pkgs/lib/meta.nix | 44 ++++++++++++++++++++++++++++++++++++++++ pkgs/stdenv/adapters.nix | 17 ++++++++++++++-- 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 pkgs/lib/meta.nix diff --git a/pkgs/lib/default.nix b/pkgs/lib/default.nix index 87789a196036..4777d7fb6685 100644 --- a/pkgs/lib/default.nix +++ b/pkgs/lib/default.nix @@ -6,12 +6,13 @@ let attrsets = import ./attrsets.nix; sources = import ./sources.nix; options = import ./options.nix; + meta = import ./meta.nix; debug = import ./debug.nix; misc = import ./misc.nix; in - { inherit trivial lists strings attrsets sources options debug; } + { inherit trivial lists strings attrsets sources options meta debug; } # !!! don't include everything at top-level; perhaps only the most # commonly used functions. // trivial // lists // strings // attrsets // sources // options - // debug // misc + // meta // debug // misc diff --git a/pkgs/lib/meta.nix b/pkgs/lib/meta.nix new file mode 100644 index 000000000000..56463361928f --- /dev/null +++ b/pkgs/lib/meta.nix @@ -0,0 +1,44 @@ +/* Some functions for manipulating meta attributes, as well as the + name attribute. */ + +rec { + + + /* Add to or override the meta attributes of the given + derivation. + + Example: + addMetaAttrs {description = "Bla blah";} somePkg + */ + addMetaAttrs = newAttrs: drv: + drv // { meta = (if drv ? meta then drv.meta else {}) // newAttrs; }; + + + /* Change the symbolic name of a package for presentation purposes + (i.e., so that nix-env users can tell them apart). + */ + setName = name: drv: drv // {inherit name;}; + + + /* Like `setName', but takes the previous name as an argument. + + Example: + updateName (oldName: oldName + "-experimental") somePkg + */ + updateName = updater: drv: drv // {name = updater (drv.name);}; + + + /* Append a suffix to the name of a package. !!! the suffix should + really be appended *before* the version, at least most of the + time. + */ + appendToName = suffix: updateName (name: "${name}-${suffix}"); + + + /* Decrease the nix-env priority of the package, i.e., other + versions/variants of the package will be preferred. + */ + lowPrio = drv: addMetaAttrs { priority = "10"; } drv; + + +} diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index ff4de11bc8b7..5be18ae205ae 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -107,5 +107,18 @@ rec { isStatic = true; } // {inherit fetchurl;}; - -} \ No newline at end of file + + /* Modify a stdenv so that the specified attributes are added to + every derivation returned by its mkDerivation function. + + Example: + stdenvNoOptimise = + addAttrsToDerivation + { NIX_CFLAGS_COMPILE = "-O0"; } + stdenv; + */ + addAttrsToDerivation = extraAttrs: stdenv: stdenv // + { mkDerivation = args: stdenv.mkDerivation (args // extraAttrs); }; + + +}