summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--krebs/3modules/setuid.nix4
-rw-r--r--krebs/5pkgs/simple/whatsupnix/whatsupnix.bash36
-rw-r--r--lib/default.nix4
-rw-r--r--lib/shell.nix2
-rw-r--r--lib/types.nix21
5 files changed, 40 insertions, 27 deletions
diff --git a/krebs/3modules/setuid.nix b/krebs/3modules/setuid.nix
index c9677fd24..a17ec0883 100644
--- a/krebs/3modules/setuid.nix
+++ b/krebs/3modules/setuid.nix
@@ -47,9 +47,7 @@ let
type = mkOptionType {
# TODO admit symbolic mode
name = "octal mode";
- check = x:
- isString x &&
- match "[0-7][0-7][0-7][0-7]" x != null;
+ check = test "[0-7][0-7][0-7][0-7]";
merge = mergeOneOption;
};
};
diff --git a/krebs/5pkgs/simple/whatsupnix/whatsupnix.bash b/krebs/5pkgs/simple/whatsupnix/whatsupnix.bash
index eba44be1c..042763048 100644
--- a/krebs/5pkgs/simple/whatsupnix/whatsupnix.bash
+++ b/krebs/5pkgs/simple/whatsupnix/whatsupnix.bash
@@ -1,26 +1,33 @@
#!/usr/bin/env bash
-
+#
# Prints build logs for failed derivations in quiet build mode (-Q).
# See https://github.com/NixOS/nix/issues/443
#
# Usage:
#
-# set -o pipefail
-# nix-build ... -Q ... | whatsupnix [user@target[:port]]
+# nix-build ... -Q ... 2>&1 | whatsupnix [user@target[:port]]
+#
+# Exit Codes:
+#
+# 0 No failed derivations could be found. This either means there where
+# no build errors, or stdin wasn't nix-build output.
+#
+# 1 Usage error; arguments couldn't be parsed.
+#
+# 2 Build error; at least one failed derivation could be found.
#
-
GAWK=${GAWK:-gawk}
NIX_STORE=${NIX_STORE:-nix-store}
-broken=$(mktemp)
-trap 'rm -f -- "$broken"' EXIT
+failed_drvs=$(mktemp --tmpdir whatsupnix.XXXXXXXX)
+trap 'rm -f -- "$failed_drvs"' EXIT
exec >&2
-$GAWK -v broken="$broken" '
+$GAWK -v failed_drvs="$failed_drvs" '
match($0, /^builder for ‘(\/nix\/store\/[^’]+\.drv)’ failed/, m) {
- print m[1] >> broken
+ print m[1] >> failed_drvs
}
{ print $0 }
'
@@ -28,7 +35,7 @@ $GAWK -v broken="$broken" '
case $# in
0)
print_log() {
- $NIX_STORE -l "$1"
+ NIX_PAGER= $NIX_STORE -l "$1"
}
;;
1)
@@ -47,7 +54,7 @@ case $# in
remote_host=$1
print_log() {
ssh "$remote_user@$remote_host" -p "$remote_port" \
- nix-store -l "$1"
+ env NIX_PAGER= nix-store -l "$1"
}
;;
*)
@@ -55,7 +62,6 @@ case $# in
exit 1
esac
-export NIX_PAGER='' # for nix-store
while read -r drv; do
title="** FAILED $drv LOG **"
frame=${title//?/*}
@@ -68,6 +74,10 @@ while read -r drv; do
print_log "$drv"
echo
-done < "$broken"
+done < "$failed_drvs"
-exit 0
+if test -s "$failed_drvs"; then
+ exit 2
+else
+ exit 0
+fi
diff --git a/lib/default.nix b/lib/default.nix
index 9399a0107..803a614a1 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -29,6 +29,10 @@ let
setAttr = name: value: set: set // { ${name} = value; };
+ test = re: x: isString x && testString re x;
+
+ testString = re: x: match re x != null;
+
toC = x: let
type = typeOf x;
reject = throw "cannot convert ${type}";
diff --git a/lib/shell.nix b/lib/shell.nix
index a8ff5dbe0..f9779028e 100644
--- a/lib/shell.nix
+++ b/lib/shell.nix
@@ -5,7 +5,7 @@ with lib;
rec {
escape =
let
- isSafeChar = c: match "[-+./0-9:=A-Z_a-z]" c != null;
+ isSafeChar = testString "[-+./0-9:=A-Z_a-z]";
in
stringAsChars (c:
if isSafeChar c then c
diff --git a/lib/types.nix b/lib/types.nix
index 530cd1e69..5a01e5b03 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -2,10 +2,10 @@
let
inherit (lib)
- all any concatMapStringsSep concatStringsSep const filter flip genid
- hasSuffix head isInt isString length match mergeOneOption mkOption
+ all any concatMapStringsSep concatStringsSep const filter flip
+ genid hasSuffix head isInt isString length mergeOneOption mkOption
mkOptionType optional optionalAttrs optionals range splitString
- stringLength substring typeOf;
+ stringLength substring test typeOf;
inherit (lib.types)
attrsOf bool either enum int listOf nullOr path str string submodule;
in
@@ -338,7 +338,8 @@ rec {
check = let
IPv4address = let d = "([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"; in
concatMapStringsSep "." (const d) (range 1 4);
- in x: isString x && match IPv4address x != null;
+ in
+ test IPv4address;
merge = mergeOneOption;
};
addr6 = mkOptionType {
@@ -346,7 +347,8 @@ rec {
check = let
# TODO check IPv6 address harder
IPv6address = "[0-9a-f.:]+";
- in x: isString x && match IPv6address x != null;
+ in
+ test IPv6address;
merge = mergeOneOption;
};
@@ -396,14 +398,13 @@ rec {
file-mode = mkOptionType {
name = "file mode";
- check = x: isString x && match "[0-7]{4}" x != null;
+ check = test "[0-7]{4}";
merge = mergeOneOption;
};
haskell.conid = mkOptionType {
name = "Haskell constructor identifier";
- check = x:
- isString x && match "[[:upper:]][[:lower:]_[:upper:]0-9']*" x != null;
+ check = test "[[:upper:]][[:lower:]_[:upper:]0-9']*";
merge = mergeOneOption;
};
@@ -426,14 +427,14 @@ rec {
name = "label";
# TODO case-insensitive labels
check = x: isString x
- && match "[0-9A-Za-z]([0-9A-Za-z-]*[0-9A-Za-z])?" x != null;
+ && test "[0-9A-Za-z]([0-9A-Za-z-]*[0-9A-Za-z])?" x;
merge = mergeOneOption;
};
# POSIX.1‐2013, 3.278 Portable Filename Character Set
filename = mkOptionType {
name = "POSIX filename";
- check = x: isString x && match "([0-9A-Za-z._])[0-9A-Za-z._-]*" x != null;
+ check = test "([0-9A-Za-z._])[0-9A-Za-z._-]*";
merge = mergeOneOption;
};