summaryrefslogtreecommitdiffstats
path: root/krebs/5pkgs
diff options
context:
space:
mode:
authorlassulus <lassulus@lassul.us>2017-10-01 17:54:06 +0200
committerlassulus <lassulus@lassul.us>2017-10-01 17:54:06 +0200
commitd7f65ea679866f24e4ca52b51bd6f068a6b38195 (patch)
tree6a09e7cc2a4c9af0507bdc189652c78832a2f952 /krebs/5pkgs
parentd973c779eb71749af464edb1ed0216b0d5317eb2 (diff)
parente62f376e6177f3efb0e0bcd3aad97a991c3b6d60 (diff)
Merge branch 'master' into staging/17.09
Diffstat (limited to 'krebs/5pkgs')
-rw-r--r--krebs/5pkgs/simple/git-preview.nix17
-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
4 files changed, 150 insertions, 80 deletions
diff --git a/krebs/5pkgs/simple/git-preview.nix b/krebs/5pkgs/simple/git-preview.nix
new file mode 100644
index 000000000..d6c9579a7
--- /dev/null
+++ b/krebs/5pkgs/simple/git-preview.nix
@@ -0,0 +1,17 @@
+{ coreutils, git, writeDashBin }:
+
+writeDashBin "git-preview" ''
+ set -efu
+ head_commit=$(${git}/bin/git log -1 --format=%H)
+ merge_commit=$1; shift
+ merge_message='Merge for git-preview'
+ preview_dir=$(${coreutils}/bin/mktemp --tmpdir -d git-preview.XXXXXXXX)
+ preview_branch=$(${coreutils}/bin/basename "$preview_dir")
+ ${git}/bin/git worktree add -b "$preview_branch" "$preview_dir" >/dev/null
+ ${git}/bin/git -C "$preview_dir" checkout "$head_commit"
+ ${git}/bin/git -C "$preview_dir" merge -m "$merge_message" "$merge_commit"
+ ${git}/bin/git -C "$preview_dir" diff "$head_commit.." "$@" &
+ ${git}/bin/git branch -fd "$preview_branch"
+ ${coreutils}/bin/rm -fR "$preview_dir"
+ wait
+''
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} "$@"
+''