From efbabdb59809bc03d93c3b3013357ba09c1e4666 Mon Sep 17 00:00:00 2001 From: Michael Raskin <7c6f434c@mail.ru> Date: Sat, 11 Aug 2007 10:34:07 +0000 Subject: [PATCH] Converted Vim package to a template-based form with only lists filled in manually. Added library functions to support it. Added two proposed package templates to top-level, so that every discussion about package format can result in just editing templates or adding new ones. svn path=/nixpkgs/trunk/; revision=9100 --- pkgs/applications/editors/vim/default.nix | 44 +++++++++++++------ pkgs/lib/default.nix | 38 +++++++++++++++- .../tools/package-management/nix/unstable.nix | 11 ++--- pkgs/top-level/all-packages.nix | 2 + pkgs/top-level/template-simple.nix | 17 +++++++ pkgs/top-level/template.nix | 40 +++++++++++++++++ 6 files changed, 131 insertions(+), 21 deletions(-) create mode 100644 pkgs/top-level/template-simple.nix create mode 100644 pkgs/top-level/template.nix diff --git a/pkgs/applications/editors/vim/default.nix b/pkgs/applications/editors/vim/default.nix index 71d89f44888f..317fedd902da 100644 --- a/pkgs/applications/editors/vim/default.nix +++ b/pkgs/applications/editors/vim/default.nix @@ -1,10 +1,31 @@ -args: +args: +let + defList = []; + #stdenv and fetchurl are added automatically + notForBuildInputs = []; + getVal = (args.lib.getValue args defList); + check = args.lib.checkFlag args; + reqsList = [ + ["gtkGUI" "glib" "gtk" "pkgconfig" "libXpm" "libXext" "x11Support"] + ["athenaGUI" "libXau" "libXt" "libXaw" "libXpm" "libXext" "x11Support"] + ["x11Support" "libX11"] + ["hugeFeatures"] + ["true" "ncurses"] + ]; + buildInputsNames = args.lib.filter (x: (null!=getVal x)&& + (! args.lib.isInList (notForBuildInputs ++ + ["stdenv" "fetchurl" "lib"] ++ + (map builtins.head reqsList)) x)) + /*["libX11" "glib" "gtk" "pkgconfig" "libXpm" "libXext" + "libXau" "libXt" "libXaw" "ncurses"];*/ + (builtins.attrNames args); +in + assert args.lib.checkReqs args defList reqsList; args.stdenv.mkDerivation { name = "vim-7.1" + - (if ((args ? hugeFeatures) - && args.hugeFeatures) then + (if (check "hugeFeatures") then "-huge" else "") - + (if ((args ? libX11)&&(args.libX11 != null)) + + (if (check "x11Support") then "-X11" else "") ; @@ -15,19 +36,14 @@ args.stdenv.mkDerivation { inherit (args) ncurses; - buildInputs =(with ({libX11=null; libXext=null; - libSM=null; libXpm=null; libXt=null; - libXaw=null; libXau=null; glib=null; - gtk=null; pkgconfig=null; - } // args); [ncurses] ++ - (args.lib.filter (x: x != null) - [libX11 libXext libSM libXpm libXt - libXaw libXau glib gtk pkgconfig])); - + debug = builtins.attrNames args; + buildInputs = args.lib.filter (x: x!=null) (map getVal buildInputsNames); + + preConfigure = "echo \$debug"; postInstall = "ln -s $out/bin/vim $out/bin/vi"; preBuild="touch src/auto/link.sed"; configureFlags=" --enable-gui=auto --disable-xim "+ - (if ((args ? hugeFeatures) && args.hugeFeatures) then + (if (check "hugeFeatures") then "--with-features=huge --enable-cscope --enable-multibyte --enable-xsmp " else ""); diff --git a/pkgs/lib/default.nix b/pkgs/lib/default.nix index 3b4124fbc279..a6e87b218026 100644 --- a/pkgs/lib/default.nix +++ b/pkgs/lib/default.nix @@ -124,6 +124,40 @@ rec { then [] else [first] ++ range (builtins.add first 1) last; - #Return [arg] or [] for null arg - + # Return true only if there is an attribute and it is true. + checkFlag = attrSet: name: + if (name == "true") then true else + getAttr [name] false attrSet ; + + logicalOR = x: y: x || y; + logicalAND = x: y: x && y; + + # Input : attrSet, [ [name default] ... ], name + # Output : its value or default. + getValue = attrSet: argList: name: + ( getAttr [name] (if argList == [] then null else + let x = builtins.head argList; in + if (head x) == name then + (head (tail x)) + else (getValue attrSet + (tail argList) name)) attrSet ); + + # Input : attrSet, [[name default] ...], [ [flagname reqs..] ... ] + # Output : are reqs satisfied? It's asserted. + checkReqs = attrSet : argList : condList : + ( + fold logicalAND true + (map (x: let name = (head x) ; in + + ((checkFlag attrSet name) -> + (fold logicalAND true + (map (y: let val=(getValue attrSet argList y); in + (val!=null) && (val!=false)) + (tail x))))) condList)) ; + + + isInList = list: x: + if (list == []) then false else + if (x == (head list)) then true else + isInList (tail list) x; } diff --git a/pkgs/tools/package-management/nix/unstable.nix b/pkgs/tools/package-management/nix/unstable.nix index 97138de923a3..891126128924 100644 --- a/pkgs/tools/package-management/nix/unstable.nix +++ b/pkgs/tools/package-management/nix/unstable.nix @@ -6,11 +6,12 @@ stdenv.mkDerivation { name = "nix-0.11pre8816"; - src = fetchurl { - url = http://nix.cs.uu.nl/dist/nix/nix-0.11pre8816/nix-0.11pre8816.tar.bz2; - md5 = "dd432e6a05179fe30a95c3758e70ac51"; - }; - + src = + fetchurl { + url = http://nix.cs.uu.nl/dist/nix/nix-unstable-latest/nix-0.11pre9063.tar.bz2; + sha256 = "0fxsvam0ihzcfg694d28d6b3vkx5klh25jvf3y5igyyqszmmhnxj"; + }; + buildInputs = [perl curl openssl]; configureFlags = " diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index e0838487af30..fa1510973835 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -3345,6 +3345,8 @@ rec { libXt libXaw libXau; inherit (gtkLibs) glib gtk; hugeFeatures = true; + gtkGUI = true; + x11Support = true; }; vlc = import ../applications/video/vlc { diff --git a/pkgs/top-level/template-simple.nix b/pkgs/top-level/template-simple.nix new file mode 100644 index 000000000000..86acd22217d2 --- /dev/null +++ b/pkgs/top-level/template-simple.nix @@ -0,0 +1,17 @@ +args: +args.stdenv.mkDerivation { + name = ""; + + src = args.fetchurl { + url = ; + sha256 = ""; + }; + + buildInputs =(with args; []); + + meta = { + description = " + +"; + }; +} diff --git a/pkgs/top-level/template.nix b/pkgs/top-level/template.nix new file mode 100644 index 000000000000..4f834dd18f18 --- /dev/null +++ b/pkgs/top-level/template.nix @@ -0,0 +1,40 @@ +args: +let + defList = [ +(assert false) - correct it; List element is of form ["name" default] + ]; + #stdenv and fetchurl are added automatically + notForBuildInputs = [ +(assert false) - correct it; List of names of non-buildInput arguments + ]; + getVal = (args.lib.getValue args defList); + check = args.lib.checkFlag args; + reqsList = [ +(assert false) - correct it; List element is of form ["name" "requirement-name" ... ] + ]; + buildInputsNames = args.lib.filter (x: (null!=getVal x)&& + (! args.lib.isInList (notForBuildInputs ++ + ["stdenv" "fetchurl" "lib"] ++ + (map builtins.head reqsList)) x)) + /*["libX11" "glib" "gtk" "pkgconfig" "libXpm" "libXext" + "libXau" "libXt" "libXaw" "ncurses"];*/ + (builtins.attrNames args); +in + assert args.lib.checkReqs args defList reqsList; +with args; +args.stdenv.mkDerivation { + name = " +#!!! Fill me // +" ; + + src = args. +#Put fetcher here + + buildInputs = args.lib.filter (x: x!=null) (map getVal buildInputsNames); + + meta = { + description = " +#Fill description here +"; + }; +}