diff --git a/pkgs/lib/default.nix b/pkgs/lib/default.nix index 87789a19603..4777d7fb668 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 00000000000..56463361928 --- /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 ff4de11bc8b..5be18ae205a 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); }; + + +}