summary refs log tree commit diff
path: root/lib/composable-derivation.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-10-10 13:28:21 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-10-10 13:28:21 +0200
commit5fef92c4a0c91153e3edac3a61a232581765074a (patch)
tree291d684d0ef71e200e6d8ab5c33fc1aca467cbb3 /lib/composable-derivation.nix
parent2a537fb369d1479748fe233261eaadfa5c2fa930 (diff)
downloadnixlib-5fef92c4a0c91153e3edac3a61a232581765074a.tar
nixlib-5fef92c4a0c91153e3edac3a61a232581765074a.tar.gz
nixlib-5fef92c4a0c91153e3edac3a61a232581765074a.tar.bz2
nixlib-5fef92c4a0c91153e3edac3a61a232581765074a.tar.lz
nixlib-5fef92c4a0c91153e3edac3a61a232581765074a.tar.xz
nixlib-5fef92c4a0c91153e3edac3a61a232581765074a.tar.zst
nixlib-5fef92c4a0c91153e3edac3a61a232581765074a.zip
Move pkgs/lib/ to lib/
Diffstat (limited to 'lib/composable-derivation.nix')
-rw-r--r--lib/composable-derivation.nix54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/composable-derivation.nix b/lib/composable-derivation.nix
new file mode 100644
index 000000000000..1099bd152bf6
--- /dev/null
+++ b/lib/composable-derivation.nix
@@ -0,0 +1,54 @@
+{lib, pkgs} :
+let inherit (lib) nv nvs; in
+{
+  # see for example:
+  # - development/interpreters/php_configurable/default.nix
+  # - .. search composableDerivation in all-packages.nix ..
+  #
+  # You should be able to override anything you like easily
+  # grep the mailinglist by title "python proposal" (dec 08)
+  # -> http://mail.cs.uu.nl/pipermail/nix-dev/2008-December/001571.html
+  # to see why this got complicated when using all its features
+  # TODO add newer example using new syntax (kernel derivation proposal -> mailinglist)
+  composableDerivation = {
+        mkDerivation ? pkgs.stdenv.mkDerivation,
+
+        # list of functions to be applied before defaultOverridableDelayableArgs removes removeAttrs names
+        # prepareDerivationArgs handles derivation configurations
+        applyPreTidy ? [ lib.prepareDerivationArgs ],
+
+        # consider adding addtional elements by derivation.merge { removeAttrs = ["elem"]; };
+        removeAttrs ? ["cfg" "flags"]
+
+      }: (lib.defaultOverridableDelayableArgs ( a: mkDerivation a) 
+         {
+           inherit applyPreTidy removeAttrs;
+         }).merge;
+
+  # some utility functions
+  # use this function to generate flag attrs for prepareDerivationArgs
+  # E nable  D isable F eature
+  edf = {name, feat ? name, enable ? {}, disable ? {} , value ? ""}:
+    nvs name {
+    set = {
+      configureFlags = ["--enable-${feat}${if value == "" then "" else "="}${value}"];
+    } // enable;
+    unset = {
+      configureFlags = ["--disable-${feat}"];
+    } // disable;
+  };
+
+  # same for --with and --without-
+  # W ith or W ithout F eature
+  wwf = {name, feat ? name, enable ? {}, disable ? {}, value ? ""}:
+    nvs name {
+    set = enable // {
+      configureFlags = ["--with-${feat}${if value == "" then "" else "="}${value}"]
+                       ++ lib.maybeAttr "configureFlags" [] enable;
+    };
+    unset = disable // {
+      configureFlags = ["--without-${feat}"]
+                       ++ lib.maybeAttr "configureFlags" [] disable;
+    };
+  };
+}