summaryrefslogtreecommitdiffstats
path: root/krebs/5pkgs/simple
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2017-09-29 21:28:23 +0200
committermakefu <github@syntax-fehler.de>2017-09-29 21:28:23 +0200
commitc352397385d5e7cbf2095ead0aa4a74be116da34 (patch)
tree72a730cb2b451b5700a8eaf9420b4bd46f513ba9 /krebs/5pkgs/simple
parent9d9e9bc3d8087974370e3d62bc05d2332b2efab2 (diff)
parent37951eed3dd7806f73c40c47ec9cd047ad76c15d (diff)
Merge remote-tracking branch 'lass/master'
Diffstat (limited to 'krebs/5pkgs/simple')
-rw-r--r--krebs/5pkgs/simple/git-preview/default.nix15
-rw-r--r--krebs/5pkgs/simple/weechat/default.nix80
-rw-r--r--krebs/5pkgs/simple/withGetopt.nix118
3 files changed, 133 insertions, 80 deletions
diff --git a/krebs/5pkgs/simple/git-preview/default.nix b/krebs/5pkgs/simple/git-preview/default.nix
new file mode 100644
index 000000000..f20f2a636
--- /dev/null
+++ b/krebs/5pkgs/simple/git-preview/default.nix
@@ -0,0 +1,15 @@
+{ coreutils, git, stdenv, writeDashBin }:
+
+writeDashBin "git-preview" ''
+ PATH=${stdenv.lib.makeBinPath [
+ coreutils
+ git
+ ]}''${PATH+:$PATH}
+ hashes=$(git log --format=%h "..$1")
+ end=$(echo "$hashes" | head -1)
+ start=$(echo "$hashes" | tail -1)
+ # exit if no diff was found
+ test -z "$start" && exit 0
+ shift
+ git diff "$start^..$end" "$@"
+''
diff --git a/krebs/5pkgs/simple/weechat/default.nix b/krebs/5pkgs/simple/weechat/default.nix
deleted file mode 100644
index c703ca8bf..000000000
--- a/krebs/5pkgs/simple/weechat/default.nix
+++ /dev/null
@@ -1,80 +0,0 @@
-{ stdenv, fetchurl, ncurses, openssl, aspell, gnutls
-, zlib, curl , pkgconfig, libgcrypt
-, cmake, makeWrapper, libiconv
-, asciidoctor # manpages
-, guileSupport ? true, guile
-, luaSupport ? true, lua5
-, perlSupport ? true, perl
-, pythonPackages
-, rubySupport ? true, ruby
-, tclSupport ? true, tcl
-, extraBuildInputs ? [] }:
-
-assert guileSupport -> guile != null;
-assert luaSupport -> lua5 != null;
-assert perlSupport -> perl != null;
-assert rubySupport -> ruby != null;
-assert tclSupport -> tcl != null;
-
-let
- inherit (pythonPackages) python pycrypto pync;
-in
-
-stdenv.mkDerivation rec {
- version = "1.8";
- name = "weechat-${version}";
-
- src = fetchurl {
- url = "http://weechat.org/files/src/weechat-${version}.tar.bz2";
- sha256 = "10km0437lg9ms6f16h20s89l2w9f9g597rykybxb16s95ql48z08";
- };
-
- outputs = [ "out" "doc" ];
-
- enableParallelBuilding = true;
- cmakeFlags = with stdenv.lib; [
- "-DENABLE_MAN=ON"
- "-DENABLE_DOC=ON"
- ]
- ++ optionals stdenv.isDarwin ["-DICONV_LIBRARY=${libiconv}/lib/libiconv.dylib" "-DCMAKE_FIND_FRAMEWORK=LAST"]
- ++ optional (!guileSupport) "-DENABLE_GUILE=OFF"
- ++ optional (!luaSupport) "-DENABLE_LUA=OFF"
- ++ optional (!perlSupport) "-DENABLE_PERL=OFF"
- ++ optional (!rubySupport) "-DENABLE_RUBY=OFF"
- ++ optional (!tclSupport) "-DENABLE_TCL=OFF"
- ;
-
- buildInputs = with stdenv.lib; [
- ncurses python openssl aspell gnutls zlib curl pkgconfig
- libgcrypt pycrypto makeWrapper
- cmake
- asciidoctor
- ]
- ++ optional guileSupport guile
- ++ optional luaSupport lua5
- ++ optional perlSupport perl
- ++ optional rubySupport ruby
- ++ optional tclSupport tcl
- ++ extraBuildInputs;
-
- NIX_CFLAGS_COMPILE = "-I${python}/include/${python.libPrefix}"
- # Fix '_res_9_init: undefined symbol' error
- + (stdenv.lib.optionalString stdenv.isDarwin "-DBIND_8_COMPAT=1 -lresolv");
-
- postInstall = with stdenv.lib; ''
- NIX_PYTHONPATH="$out/lib/${python.libPrefix}/site-packages"
- wrapProgram "$out/bin/weechat" \
- ${optionalString perlSupport "--prefix PATH : ${perl}/bin"} \
- --prefix PATH : ${pythonPackages.python}/bin \
- --prefix PYTHONPATH : "$PYTHONPATH" \
- --prefix PYTHONPATH : "$NIX_PYTHONPATH"
- '';
-
- meta = {
- homepage = http://www.weechat.org/;
- description = "A fast, light and extensible chat client";
- license = stdenv.lib.licenses.gpl3;
- maintainers = with stdenv.lib.maintainers; [ lovek323 garbas the-kenny ];
- platforms = stdenv.lib.platforms.unix;
- };
-}
diff --git a/krebs/5pkgs/simple/withGetopt.nix b/krebs/5pkgs/simple/withGetopt.nix
new file mode 100644
index 000000000..196e6765a
--- /dev/null
+++ b/krebs/5pkgs/simple/withGetopt.nix
@@ -0,0 +1,118 @@
+with import <stockholm/lib>;
+{ utillinux, writeDash }:
+
+opt-spec: cmd-spec: let
+
+ cmd = cmd-spec opts;
+
+ cmd-script =
+ if typeOf cmd == "set"
+ then "exec ${cmd}"
+ else cmd;
+
+ opts = mapAttrs (name: value: value // rec {
+ long = value.long or (replaceStrings ["_"] ["-"] name);
+ ref = value.ref or "\"\$${varname}\"";
+ short = value.short or null;
+ switch = value.switch or false;
+ varname = value.varname or (replaceStrings ["-"] ["_"] name);
+ }) opt-spec;
+
+ # true if b requires a to define its default value
+ opts-before = a: b:
+ test ".*[$]${stringAsChars (c: "[${c}]") a.varname}\\>.*" (b.default or "");
+
+ opts-list = let
+ sort-out = toposort opts-before (attrValues opts);
+ in
+ if sort-out ? result
+ then sort-out.result
+ else throw "toposort output: ${toJSON sort-out}";
+
+ wrapper-name =
+ if typeOf cmd == "set" && cmd ? name
+ then "${cmd.name}-getopt"
+ else "getopt-wrapper";
+
+in writeDash wrapper-name ''
+ set -efu
+
+ wrapper_name=${shell.escape wrapper-name}
+
+ ${concatStringsSep "\n" (mapAttrsToList (name: opt: /* sh */ ''
+ unset ${opt.varname}
+ '') opts)}
+
+ args=$(${utillinux}/bin/getopt \
+ -l ${shell.escape
+ (concatMapStringsSep ","
+ (opt: opt.long + optionalString (!opt.switch) ":")
+ (filter (opt: opt.long != null)
+ (attrValues opts)))} \
+ -n "$wrapper_name" \
+ -o ${shell.escape
+ (concatMapStringsSep ""
+ (opt: opt.short + optionalString (!opt.switch) ":")
+ (filter (opt: opt.short != null)
+ (attrValues opts)))} \
+ -s sh \
+ -- "$@")
+ if \test $? != 0; then exit 1; fi
+ eval set -- "$args"
+
+ while :; do
+ case $1 in
+ ${concatStringsSep "\n" (mapAttrsToList (name: opt: /* sh */ ''
+ (${concatMapStringsSep "|" shell.escape (filter (x: x != "") [
+ (optionalString (opt.long != null) "--${opt.long}")
+ (optionalString (opt.short != null) "-${opt.short}")
+ ])})
+ ${if opt.switch then /* sh */ ''
+ ${opt.varname}=true
+ shift
+ '' else /* sh */ ''
+ ${opt.varname}=$2
+ shift 2
+ ''}
+ ;;
+ '') (filterAttrs
+ (_: opt: opt.long != null || opt.short != null)
+ opts))}
+ --)
+ shift
+ break
+ esac
+ done
+
+ ${concatMapStringsSep "\n"
+ (opt: /* sh */ ''
+ if \test "''${${opt.varname}+1}" != 1; then
+ printf '%s: missing mandatory option '--%s'\n' \
+ "$wrapper_name" \
+ ${shell.escape opt.long}
+ error=1
+ fi
+ '')
+ (filter
+ (x: ! hasAttr "default" x)
+ (attrValues opts))}
+ if test "''${error+1}" = 1; then
+ exit 1
+ fi
+
+ ${concatMapStringsSep "\n"
+ (opt: /* sh */ ''
+ if \test "''${${opt.varname}+1}" != 1; then
+ ${opt.varname}=${opt.default}
+ fi
+ '')
+ (filter
+ (hasAttr "default")
+ opts-list)}
+
+ ${concatStringsSep "\n" (mapAttrsToList (name: opt: /* sh */ ''
+ export ${opt.varname}
+ '') opts)}
+
+ ${cmd-script} "$@"
+''