From ba8410a98dcffd2ddfbedab456e52ee7f5599fe6 Mon Sep 17 00:00:00 2001 From: Madeleine Sydney Date: Thu, 10 Apr 2025 07:42:10 -0600 Subject: [PATCH] fix(haskell): Fix ghc[i]-with-packages - Export functions. - Simplify arg-parsing by using getopts instead of getopt. --- modules/home/users/crumb/haskell.nix | 49 ++++++++++++++++------------ 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/modules/home/users/crumb/haskell.nix b/modules/home/users/crumb/haskell.nix index 1c888f6..7674cfd 100644 --- a/modules/home/users/crumb/haskell.nix +++ b/modules/home/users/crumb/haskell.nix @@ -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 =