fix(haskell): Fix ghc[i]-with-packages

- Export functions.
- Simplify arg-parsing by using getopts instead of getopt.
This commit is contained in:
Madeleine Sydney
2025-04-10 07:42:10 -06:00
parent 240bdfb6da
commit ba8410a98d

View File

@@ -11,36 +11,45 @@ in {
programs.bash.profileExtra = '' programs.bash.profileExtra = ''
# Start a GHCi REPL with the given packages made available. # Start a GHCi REPL with the given packages made available.
ghci-with-packages () { ghci-with-packages () {
nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [ $@ ])" \ packages=""
--run ghci while getopts 'p:h' opt; do
} case "$opt" in
p)
# Run GHC with the given packages made available. packages="''${OPTARG}"
ghc-with-packages () {
getopt -o "p" -- "$@"
while true; do
case "$1" in
-p)
packages="$1"
shift 2
;; ;;
--) ?|h)
shift echo >&2 "Usage: $(basename $0) [-p packages] [-- ghci-options]"
break exit 1
;; ;;
esac esac
done done
shift "$(($OPTIND -1))"
if [ $? -ne 0 ]; then nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [ $packages ])" \
echo "Invalid options provided" --run "ghci $@"
exit 1 }
fi 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 ])" \ nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [ $packages ])" \
--run "ghc $@" --run "ghc $@"
} }
export -f ghc-with-packages
''; '';
sydnix.impermanence.cache.directories = sydnix.impermanence.cache.directories =