fix(haskell): Fix ghc[i]-with-packages
- Export functions. - Simplify arg-parsing by using getopts instead of getopt.
This commit is contained in:
@@ -11,36 +11,45 @@ in {
|
||||
programs.bash.profileExtra = ''
|
||||
# Start a GHCi REPL with the given packages made available.
|
||||
ghci-with-packages () {
|
||||
nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [ $@ ])" \
|
||||
--run ghci
|
||||
}
|
||||
|
||||
# Run GHC with the given packages made available.
|
||||
ghc-with-packages () {
|
||||
getopt -o "p" -- "$@"
|
||||
while true; do
|
||||
case "$1" in
|
||||
-p)
|
||||
packages="$1"
|
||||
shift 2
|
||||
packages=""
|
||||
while getopts 'p:h' opt; do
|
||||
case "$opt" in
|
||||
p)
|
||||
packages="''${OPTARG}"
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
?|h)
|
||||
echo >&2 "Usage: $(basename $0) [-p packages] [-- ghci-options]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift "$(($OPTIND -1))"
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Invalid options provided"
|
||||
exit 1
|
||||
fi
|
||||
nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [ $packages ])" \
|
||||
--run "ghci $@"
|
||||
}
|
||||
export -f ghci-with-packages
|
||||
|
||||
eval set -- "$options"
|
||||
# Run GHC with the given packages made available.
|
||||
ghc-with-packages () {
|
||||
packages=""
|
||||
while getopts 'p:h' opt; do
|
||||
case "$opt" in
|
||||
p)
|
||||
packages="''${OPTARG}"
|
||||
;;
|
||||
?|h)
|
||||
echo >&2 "Usage: $(basename $0) [-p packages] [-- ghc-options]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift "$(($OPTIND -1))"
|
||||
|
||||
nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [ $packages ])" \
|
||||
--run "ghc $@"
|
||||
}
|
||||
export -f ghc-with-packages
|
||||
'';
|
||||
|
||||
sydnix.impermanence.cache.directories =
|
||||
|
||||
Reference in New Issue
Block a user