Exit code 137 with nixpkgs, despite not changing anything - haskell

I'm using Miso, a Haskell backend for JS, and my code was compiling fine yesterday. However, as I try to compile today I get this:
Preprocessing executable 'simple' for miso-1.8.0.0..
Building executable 'simple' for miso-1.8.0.0..
[1 of 1] Compiling Main ( exe/Main.hs, dist/build/simple/simple-tmp/Main.js_o )
Linking dist/build/simple/simple.jsexe (Main)
/nix/store/7crry947d1xvp1f15c6q089l0gcy5hpc-stdenv-linux/setup: line 1315: 3887 Killed ./Setup build
error: builder for '/nix/store/zaw5k6i7lqgxlw7i8aaxvqhknjky3f5x-miso-1.8.0.0.drv' failed with exit code 137
It seems like code 137 is a memory error, but the only thing open was my terminal. I've tried uninstalling and reinstalling nix, reinstalling Haskell, but no dice.
EDIT: Here an excerpt of the script.
for curPhase in $phases; do
if [[ "$curPhase" = buildPhase && -n "${dontBuild:-}" ]]; then continue; fi
if [[ "$curPhase" = checkPhase && -z "${doCheck:-}" ]]; then continue; fi
if [[ "$curPhase" = installPhase && -n "${dontInstall:-}" ]]; then continue; fi
if [[ "$curPhase" = fixupPhase && -n "${dontFixup:-}" ]]; then continue; fi
if [[ "$curPhase" = installCheckPhase && -z "${doInstallCheck:-}" ]]; then continue; fi
if [[ "$curPhase" = distPhase && -z "${doDist:-}" ]]; then continue; fi
if [[ -n $NIX_LOG_FD ]]; then
echo "#nix { \"action\": \"setPhase\", \"phase\": \"$curPhase\" }" >&$NIX_LOG_FD
fi
showPhaseHeader "$curPhase"
dumpVars
# Evaluate the variable named $curPhase if it exists, otherwise the
# function named $curPhase.
local oldOpts="$(shopt -po nounset)"
set +u
eval "${!curPhase:-$curPhase}"
eval "$oldOpts"
if [ "$curPhase" = unpackPhase ]; then
cd "${sourceRoot:-.}"
fi
done
}
Line 1315 is eval "$oldOpts".

I fixed it by changing the amount of memory the Ubuntu virtual machine used by editing .wslconfig. Even though it was enough before, 8 GB couldn't cut it, so doubling it to 16 worked.

Related

Editing file with vim without typing path (similar to autojump)

A few months back, I installed a utility on my mac so that instead of typing something like this:
vim /type/path/to/the/file
I could just type:
v file
9 times out of 10 it would guess the right file based on the past history, similar to the way autojump works. And instead of typing in vim I can just type the letter v.
I can't remember how I set this up though. It still works on my mac but I don't see anything in my .bash_profile that shows how I did that.
I'm trying to get this to work on my linux box.
This can be found here
https://github.com/rupa/v/blob/master/v
it should work in Linux too. It is a bash script that uses the viminfo
history file to fill in partial strings.
It can be installed on macOS with brew install v
Ah! I found the command with which. Here is the magical script. I can't determine where I got it.
#!/usr/bin/env bash
[ "$vim" ] || vim=vim
[ $viminfo ] || viminfo=~/.viminfo
usage="$(basename $0) [-a] [-l] [-[0-9]] [--debug] [--help] [regexes]"
[ $1 ] || list=1
fnd=()
for x; do case $x in
-a) deleted=1;;
-l) list=1;;
-[1-9]) edit=${x:1}; shift;;
--help) echo $usage; exit;;
--debug) vim=echo;;
--) shift; fnd+=("$#"); break;;
*) fnd+=("$x");;
esac; shift; done
set -- "${fnd[#]}"
[ -f "$1" ] && {
$vim "$1"
exit
}
while IFS=" " read line; do
[ "${line:0:1}" = ">" ] || continue
fl=${line:2}
[ -f "${fl/\~/$HOME/}" -o "$deleted" ] || continue
match=1
for x; do
[[ "$fl" =~ $x ]] || match=
done
[ "$match" ] || continue
i=$((i+1))
files[$i]="$fl"
done < "$viminfo"
if [ "$edit" ]; then
resp=${files[$edit]}
elif [ "$i" = 1 -o "$list" = "" ]; then
resp=${files[1]}
elif [ "$i" ]; then
while [ $i -gt 0 ]; do
echo -e "$i\t${files[$i]}"
i=$((i-1))
done
read -p '> ' CHOICE
resp=${files[$CHOICE]}
fi
[ "$resp" ] || exit
$vim "${resp/\~/$HOME}"

Automating virtualenv activation/deactivation in zsh

I have a code that looks like this:
has_venv_in_path() {
unsetopt nomatch 2>/dev/null
local path_to_search
path_to_search=$1
echo "searching in $path_to_search"
if [[ ${path_to_search} = "/" ]]; then
echo "no"
fi
ls ${path_to_search}/*/bin/activate > /dev/null 2> /dev/null
if [ "$?" = '0' ]; then
echo "yes"
else
has_venv_in_path $(dirname "$path_to_search")
fi
}
has_venv_in_path function is written by me and it works if the path provided to it doesn't contain tilde like /home/user/foo. If ~/foo is provided that is going into infinite recursion.
So I found how to expand tilde, but I have very little knowledge of bash, so I can't properly use it in my function.
Can anyone help with that?
Suppose we have following folder structure.
/code/foo/bar/baz
/code/foo/venv/bin/activate
if we cd into /code/foo/bar/baz, it should activate venv.
if we cd into /code/foo, it should activate venv
if we cd out of /code/foo/*, it should deactivate venv.
Given that the actual goal here is to look for a virtualenv root somewhere above the currently specified directory...
find_venv_above() {
local dir=${1:-$PWD}
while [[ $dir = /*/* ]]; do
[[ -e "$dir/bin/activate" ]] && {
printf '%s\n' "$dir"
return 0
}
dir=${dir%/*}
done
return 1
}
...used as:
if venv_root=$(find_venv_above); then
echo "Currently in a virtualenv rooted at $venv_root"
fi
Alternately, if you want to find a virtualenv below the current location:
find_venv() {
for option in "${1:-$PWD}"/*/bin/activate; do
[[ -x "$option" ]] && {
printf '%s\n' "${option%/bin/activate}"
return 0
}
done
return 1
}
Usage is similar. That said, if you wanted to recurse multiple levels rather than only one, I'd strongly suggest using find.

Bash thinks input is incorrect when it is?

I have this script, but on line 51, when I answer "y", bash skips that and tells me to "answer y or n" (skips to line 58):
debianDeps() {
apt-get install git cmake build-essential liblua5.2-dev \
libgmp3-dev libmysqlclient-dev libboost-system-dev
}
fedoraDeps() {
yum install git cmake gcc-c++ boost-devel \
gmp-devel community-mysql-devel lua-devel
}
bsdDeps() {
cd /usr/ports/shells/bash && make install clean BATCH=yes
cd /usr/ports/devel/git && make install clean BATCH=yes
cd /usr/ports/devel/cmake && make install clean BATCH=yes
cd /usr/ports/lang/gcc47 && make install clean BATCH=yes
cd /usr/ports/lang/luajit && make install clean BATCH=yes
cd /usr/ports/devel/boost-libs && make install clean BATCH=yes
cd /usr/ports/math/gmp && make install clean BATCH=yes
cd /usr/ports/databases/mysql-connector-c && make install clean BATCH=yes
}
libInstall() {
echo "Libraries and Build Tools... Installed"
}
bsdBuild() {
echo "Building on FreeBSD"
mkdir build && cd build
CXX=g++47 cmake ..
echo "Build on $cpuCores threads with $coreBuild processes? (experimental but loads faster) y or n "
read $ans1_4
if [[ $ans1_4 = "y" ]]; then
echo -e $greenText"Building on $cpuCores threads with $coreBuild ."$none
make -j $coreBuild
elif [[ $ans1_4 = "n" ]]; then
echo -e $blueText"Building on a single thread."$none
make
else
echo "answer y or n"
echo -e $redText"Answer y or n"$none
fi
}
genBuild() {
echo "Building..."
mkdir build && cd build
cmake ..
echo "Build on $cpuCores threads with $coreBuild processes? (experimental but loads faster) y or n "
read $ans1_4
if [[ $ans1_4 = "y" ]]; then
echo -e $greenText"Building on $cpuCores threads with $coreBuild ."$none
make -j $coreBuild
elif [[ $ans1_4 = "n" ]]; then
echo -e $blueText"Building on a single thread."$none
make
else
echo -e $redText"Answer y or n"$none
fi
}
clean() {
mkdir objs/
mv *.o objs/
echo "There might be a few leftover files."
}
###
### Script starts here
###
#check if root
if [[ $EUID -ne 0 ]]; then
echo "You must be root to use this script, press enter to exit."
read end
exit 1
fi
#OS dependencies and other stuff
echo "Chose your Operating System. {Supported OS: Debian, Ubuntu, Fedora, CentOS, FreeBSD} "
read ans1
if [[ $ans1 = "Fedora" ]] || [[ $nas1 = "CentOS" ]]; then
echo -n "Should the script install dependencies? y or n"
read ans1_1
if [[ $ans1_1 = "y" ]]; then
fedoraDeps
elif [[ $ans1_1 = "n" ]]; then
break
else
echo "Answer 'y' or 'n' "
fi
elif [[ $ans1 = "Debian" ]] || [[ $ans1 = "Ubuntu" ]]; then
echo -n "Should the script install dependencies? y or n"
read ans1_1
if [[ $ans1_1 = "y" ]]; then
debianDeps
elif [[ $ans1_1 = "n" ]]; then
break
else
echo "Answer 'y' or 'n' "
fi
elif [[ $ans1 = "FreeBSD" ]]; then
echo -n "Should the script install dependencies? y or n"
read ans1_1
if [[ $ans1_1 = "y" ]]; then
bsdDeps
elif [[ $ans1_1 = "n" ]]; then
break
else
echo "Answer 'y' or 'n' "
fi
else
echo "Pick a valid OS"
fi
#Compiling here
echo -n "Are we on FreeBSD? y or n"
read ans1_2
if [[ $ans1_2 = "y" ]]; then
bsdbuild
elif [[ $ans1_2 = "n" ]]; then
genBuild
else
echo "Answer y or n"
fi
echo "Should the folder be cleaned? y or n"
read ans1_3
if [[ $ans1_3 = "y" ]]; then
clean
elif [[ $ans1_3 = "n" ]]; then
echo "Exiting..."
exit 1
else
echo "Answer y or n"
fi
read $ans1_4 should be read ans1_4 I made a little mistake there.

Ash MATCH operator (=~)

I'm trying to fit a script for linux onto my WD world edition drive.
The script is written for Bash (debian) but my WD only runs busybox (with ash). Despite this, I have gotten most functionality in there just from using Google. There is only one operator i have not found a counterpart to, the =~ operator
How can i port the functionality of the =~ operator from the old script to ash?
Script:
#! /bin/bash
# posttorrent.sh by Killemov
{
# Log file, file where we tell what events have been processed.
LOG_FILE=/var/log/posttorrent.log
# Username for transmission remote.
TR_USERNAME="username"
# Password for transmission remote.
TR_PASSWORD="password"
# Get current time.
NOW=$(date +%Y-%m-%d\ %H:%M:%S)
# Source directory, should not be changed.
SRC_DIR="${TR_TORRENT_DIR}/${TR_TORRENT_NAME}"
# Directory to store the un-compressed files in..
DEST_DIR="${TR_TORRENT_DIR}/${TR_TORRENT_NAME}/"
# This parameter string could be passed from Transmission in the future.
TR_TORRENT_PARAMETER="EXTRACT SLEEP1h"
echo "text"
if [ -e "$SRC_DIR/keep" ]; then
TR_TORRENT_PARAMETER="$TR_TORRENT_PARAMETER KEEP"
fi
if [ -e "$SRC_DIR/exit" ]; then
TR_TORRENT_PARAMETER="EXIT"
fi
# Actual processing starts here.
if [[ "$TR_TORRENT_PARAMETER" =~ "EXIT" ]]; then
echo $NOW "Exiting $TR_TORRENT_NAME" >> $LOG_FILE
exit 0
fi
echo "text2"
if [[ "$TR_TORRENT_PARAMETER" =~ "EXTRACT" ]]; then
cd $TR_TORRENT_DIR
if [ -d "$SRC_DIR" ]; then
IFS=$'\n'
unset RAR_FILES i
for RAR_FILE in $( find "$SRC_DIR" -iname "*.rar" ); do
if [[ $RAR_FILE =~ .*part.*.rar ]]; then
if [[ $RAR_FILE =~ .*part0*1.rar ]]; then
RAR_FILES[i++]=$RAR_FILE
fi
else
RAR_FILES[i++]=$RAR_FILE
fi
done
unset IFS
if [ ${#RAR_FILES} -gt 0 ]; then
for RAR_FILE in "$(eval \$$RAR_FILES[#])"; do
unrar x -inul "$RAR_FILE" "$DEST_DIR"
if [ $? -gt 0 ]; then
echo $NOW "Error unrarring $TR_TORRENT_NAME" >> $LOG_FILE
transmission-remote -n $TR_USERNAME:$TR_PASSWORD -t$TR_TORRENT_ID --verify --start
exit 0
fi
done
if [[ ! "$TR_TORRENT_PARAMETER" =~ "KEEP" ]]; then
SLEEP=$(expr match "$TR_TORRENT_PARAMETER" '.*SLEEP\([0-9a-zA-Z]*\)')
if [ ${#SLEEP} -gt 0 ]; then
sleep $SLEEP
fi
transmission-remote -n $TR_USERNAME:$TR_PASSWORD -t$TR_TORRENT_ID --remove-and-delete
fi
echo $NOW "Unrarred $TR_TORRENT_NAME" >> $LOG_FILE
fi
fi
fi
} &
(i had some trouble with indirect references, i hoped i fixed that correctly)
Well for the $VARIABLE =~ PATERN you should be able to use the:
echo "$VARIABLE" | grep -E PATTERN
But I think you will have a little bit of trouble with the arithmetical expressions i++ as well - if it's implemented, then you still need to use the i=$(($i + 1)) syntax, if it's not implemented, then the i=$(expr $i + 1) syntax.
I presume you're reason for the IFS=$'\n' is to split the find on newlines, but you're probably better off with issuing the find into a temporary file, and then doing a while read line; do ... done <$tmpfile,
Additionally, I'm not certain if all versions of busybox ash support arrays, so you may have a problem there as well.

Bash string comparison not working

I have the following Bash function:
checkForUpdates() {
checkLatest
ret=$?
if [ $ret != 0 ]; then
return $ret
fi
count=0
for i in $(ssh $__updateuser#$__updatehost "ls $__updatepath/*${latest}*"); do
file="${i##$__updatepath}"
echo "$file" >> $__debuglog
if [ -f $__pkgpath/$file ]; then
remoteHash=$(ssh $__updateuser#$__updatehost "md5sum -b < $__updatepath/${file}")
localHash=$(md5sum -b < $__pkgpath/$file)
echo "${remoteHash:0:32} = ${localHash:0:32}" >> $__debuglog
if [ "${remoteHash:0:32}" != "${localHash:0:32}" ]; then
files[$count]=$file
count=$(($count + 1))
echo "Hashes not matched, adding $i" >> $__debuglog
fi
else
files[$count]=$file
count=$(($count + 1))
echo "$file missing" >> $__debuglog
fi
done
# Verify that the files array isn't empty.
if [ $count != 0 ]; then
return 0
else
return 33
fi
}
For some reason, the remoteHash/localHash comparison always returns true. I added the echo so that I could see the values of the hashes and they are definitely different and I can't figure out where I'm going wrong. I have tried different operators with no success and it is driving me crazy!
this isn't related to your question but more of general advice, first and most important you shouldn't parse the output of ls instead use find -print0 here's an example: http://mywiki.wooledge.org/BashFAQ/001
also consider using [[ instead of [ see: http://mywiki.wooledge.org/BashFAQ/031
now regarding your code, this part:
checkLatest
ret=$?
if [ $ret != 0 ]; then
return $ret
fi
could be written simply as:
checkLatest || return
and you don't need to keep a counter on the index of the array, if you initialize the var as an empty array like files=() you can then append elements to it with files+=("$file") you can get the count with "${#files[#]}"

Resources