mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-20 04:31:52 +00:00
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
This commit is contained in:
parent
47659b16f9
commit
f22d19c128
47
pkgs/lib/strings-with-deps2.nix
Normal file
47
pkgs/lib/strings-with-deps2.nix
Normal file
|
@ -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) );
|
||||
}
|
|
@ -229,6 +229,10 @@ rec {
|
|||
inherit stdenv lib;
|
||||
};
|
||||
|
||||
builderDefs2 = lib.sumArgs ((import ./builder-defs2.nix) (builderDefs null));
|
||||
|
||||
stringsWithDeps2 = (import ../lib/strings-with-deps2.nix) lib;
|
||||
|
||||
# Call a specific version of a Nix expression, that is,
|
||||
# `selectVersion ./foo {version = "0.1.2"; args...}' evaluates to
|
||||
# `import ./foo/0.1.2.nix args'.
|
||||
|
|
52
pkgs/top-level/builder-defs2.nix
Normal file
52
pkgs/top-level/builder-defs2.nix
Normal file
|
@ -0,0 +1,52 @@
|
|||
# documentation see ../lib/strings-with-deps2.nix
|
||||
# coverts Michael Raskin builder script snippets so that they can be used with createScript from strings-with-deps2.nix
|
||||
|
||||
raskin_defs : rec {
|
||||
|
||||
defAddToSearchPath = {
|
||||
name = "defAddToSearchPath";
|
||||
value = raskin_defs.defAddToSearchPath.text;
|
||||
dependencies = [ "defNest" ];
|
||||
};
|
||||
defNest = {
|
||||
name = "defNest";
|
||||
value = raskin_defs.defNest.text;
|
||||
};
|
||||
minInit = {
|
||||
name = "minInit";
|
||||
value = raskin_defs.minInit.text;
|
||||
dependencies = [ "defNest" "defAddToSearchPath" ];
|
||||
};
|
||||
|
||||
addInputs = {
|
||||
name = "addInputs";
|
||||
value = raskin_defs.addInputs.text;
|
||||
dependencies = [ "minInit" ];
|
||||
};
|
||||
|
||||
toSrcDir = s : {
|
||||
name = "toSrcDir";
|
||||
value = (raskin_defs.toSrcDir s).text;
|
||||
dependencies = [ "minInit" ];
|
||||
};
|
||||
|
||||
doConfigure = {
|
||||
name = "doConfigure";
|
||||
value = raskin_defs.doConfigure.text;
|
||||
dependencies = [ "minInit" "addInputs" "doUnpack" ];
|
||||
};
|
||||
|
||||
doAutotools = {
|
||||
name = "doAutotools";
|
||||
value = raskin_defs.doAutotools.text;
|
||||
dependencies = [ "minInit" "addInputs" "doUnpack" ];
|
||||
};
|
||||
|
||||
doMake = {
|
||||
name = "doMake";
|
||||
value = raskin_defs.doMake.text;
|
||||
dependencies = [ "minInit" "addInputs" "doUnpack" ];
|
||||
};
|
||||
|
||||
# more have to be added here!
|
||||
}
|
Loading…
Reference in a new issue