about summary refs log tree commit diff
path: root/pkgs/lib
diff options
context:
space:
mode:
authorMarc Weber <marco-oweber@gmx.de>2008-01-19 01:23:48 +0000
committerMarc Weber <marco-oweber@gmx.de>2008-01-19 01:23:48 +0000
commitf22d19c12813f3f5f330ed3d0db8d1f2a6c147a4 (patch)
treea3ade07bb54af3c50e97fe55356df9090b4dbaff /pkgs/lib
parent47659b16f94ba25231815d65ae661c7a8f384cdb (diff)
downloadnixlib-f22d19c12813f3f5f330ed3d0db8d1f2a6c147a4.tar
nixlib-f22d19c12813f3f5f330ed3d0db8d1f2a6c147a4.tar.gz
nixlib-f22d19c12813f3f5f330ed3d0db8d1f2a6c147a4.tar.bz2
nixlib-f22d19c12813f3f5f330ed3d0db8d1f2a6c147a4.tar.lz
nixlib-f22d19c12813f3f5f330ed3d0db8d1f2a6c147a4.tar.xz
nixlib-f22d19c12813f3f5f330ed3d0db8d1f2a6c147a4.tar.zst
nixlib-f22d19c12813f3f5f330ed3d0db8d1f2a6c147a4.zip
slightly modified stringsWithDeps script Builder proposal adding the feature
overriding steps and has better documentation (IMHO) reusing as much as
possible of the code already written by raskin

svn path=/nixpkgs/trunk/; revision=10225
Diffstat (limited to 'pkgs/lib')
-rw-r--r--pkgs/lib/strings-with-deps2.nix47
1 files changed, 47 insertions, 0 deletions
diff --git a/pkgs/lib/strings-with-deps2.nix b/pkgs/lib/strings-with-deps2.nix
new file mode 100644
index 000000000000..85c3526ee22a
--- /dev/null
+++ b/pkgs/lib/strings-with-deps2.nix
@@ -0,0 +1,47 @@
+/* propoal Marc Weber (original idea and implementation: Michael Raskin)
+  This should not be a complete rewrite of Michael Raskins code.
+  I only fear having to override one step.. 
+  (which could be done using textClosureMap = f: .. and telling f to substitute a text string)
+  But I don't like this solution
+
+  I've rewritten the part creating the actual step hoping that it's easier to understand.
+
+  Baisc idea keeps the same: assemble a custom builder script by concatenating
+  text snippets with dependencies.
+
+  Difference: Instead of concatenating the text snippets only aliases are concatenated [1]
+  Then those alias names are looked up from an attribute set [2]
+  (this way giving you full control overriding steps)
+
+  All script snippets written by Michael Raskin will be reused thankfully :)
+*/
+ 
+/* Example:
+setup = { 
+  name = "setup";
+  value = "echo setup";       # the text snippet (by calling it value it fits the attr name expected by listToAttrs 
+}
+ 
+unpack = { 
+  name = "unpack";
+  value = "tar xf ... ";
+  dependencies = [ "setup" ]; # createScript ensures that these are prependend to this text snipped
+}
+
+script = createScript { steps = [setup unpack] }
+is equal to
+script = createScript { steps = [unpack] }
+
+# overriding example:
+script_overridden_setup = createScript { steps = [unpack]; override = { setup = "overridden setup"; }; };
+*/
+lib :
+let inherit (builtins) listToAttrs; 
+    inherit (lib) intersperse concatLists uniqList concatStrings;
+    in {
+     createScript = { steps, override ? {} } : let 
+        addNameToDeps = r : ( if (r ? dependencies) then r.dependencies else [] ) ++ [r.name];
+        names = uniqList { inputList = concatLists ( map addNameToDeps steps ) ; }; # [1] 
+        scriptsAsAttrs = listToAttrs steps; # [2] 
+      in concatStrings ( intersperse "\n" (map (x : __getAttr x (scriptsAsAttrs // override ) ) names) );
+    }