From 539cff1b682349537e40964a2b9aeb94ff266c94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madeleine=20Sydney=20=C5=9Alaga?= Date: Fri, 1 May 2026 15:04:27 -0600 Subject: [PATCH] feat(haskell): ghc-with-packages --- modules/home/haskell.nix | 31 +++++++++++ modules/home/haskell/ghc-with-packages.sh | 52 ++++++++++++++++++ modules/home/users/crumb/haskell.nix | 67 ----------------------- users/msyds/default.nix | 1 + 4 files changed, 84 insertions(+), 67 deletions(-) create mode 100644 modules/home/haskell.nix create mode 100644 modules/home/haskell/ghc-with-packages.sh delete mode 100644 modules/home/users/crumb/haskell.nix diff --git a/modules/home/haskell.nix b/modules/home/haskell.nix new file mode 100644 index 0000000..9b9fc26 --- /dev/null +++ b/modules/home/haskell.nix @@ -0,0 +1,31 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.sydnix.haskell; +in { + options.sydnix.haskell.enable = + lib.mkEnableOption "Haskell"; + + config = lib.mkIf cfg.enable { + # Convenient shorthand for quickly opening Haskell REPLs. + programs.bash.profileExtra = + builtins.readFile ./haskell/ghc-with-packages.sh; + + home.file.".ghc/ghci.conf".text = '' + :set prompt "\x1b[38;5;5mλ>\x1b[0m " + :set prompt-cont "\x1b[38;5;5m|>\x1b[0m " + ''; + + sydnix.impermanence.cache.directories = + let xdg-cache-dir = + config.home.cacheHome + or "${config.home.homeDirectory}/.cache"; + in [ + # We don't want to rebuild Hackage simply due to a reboot, do we? }:) + (lib.removePrefix "${config.home.homeDirectory}/" + "${xdg-cache-dir}/cabal") + ".stack" + ]; + }; +} + diff --git a/modules/home/haskell/ghc-with-packages.sh b/modules/home/haskell/ghc-with-packages.sh new file mode 100644 index 0000000..66505bc --- /dev/null +++ b/modules/home/haskell/ghc-with-packages.sh @@ -0,0 +1,52 @@ +declare -a default_ghc_packages=(pretty-simple lens) + +ghc-with-packages () { + declare -a packages=() + local GHC_COMMAND=${GHC_COMMAND:-"ghc"} + packages+=$default_ghc_packages + local exit=0 stop_args + while [[ ! -z "$1" && -z "$stop_args" ]]; do + local opt="$1" + shift 1 + case "$opt" in + "--") + stop_args=1 + ;; + "-p") + while [[ ! -z "$1" && "$1" != -* ]]; do + packages+=("$1") + shift 1 + done + ;; + *|"-h") + exit=1 + ;; + esac + done + + local pretty_simple + + for p in "$packages"; do + if [[ "$p" = "pretty-simple" ]]; then + pretty_simple="-interactive-print=Text.Pretty.Simple.pPrint" + fi + done + + if [[ "$exit" -eq 0 ]]; then + # echo "packages: ${packages[@]}" + # echo "args: $*" + local pkgs="${packages[@]}" + nix-shell \ + -p "haskellPackages.ghcWithPackages (p: with p; [ $pkgs ])" \ + --run "$GHC_COMMAND $pretty_simple $*" + else + echo >&2 "Usage: ghci-with-packages [-p packages…] [-- ghci-options]" + return $exit + fi +} +export -f ghc-with-packages + +ghci-with-packages () { + GHC_COMMAND=ghci ghc-with-packages "$@" +} +export -f ghci-with-packages diff --git a/modules/home/users/crumb/haskell.nix b/modules/home/users/crumb/haskell.nix deleted file mode 100644 index aa11777..0000000 --- a/modules/home/users/crumb/haskell.nix +++ /dev/null @@ -1,67 +0,0 @@ -{ config, lib, pkgs, ... }: - -let - cfg = config.sydnix.users.crumb.haskell; -in { - options.sydnix.users.crumb.haskell.enable = - lib.mkEnableOption "Haskell, à la crumb"; - - config = lib.mkIf cfg.enable { - # Convenient shorthand for quickly opening Haskell REPLs. - programs.bash.profileExtra = '' - # Start a GHCi REPL with the given packages made available. - ghci-with-packages () { - packages="" - while getopts 'p:h' opt; do - case "$opt" in - p) - packages="''${OPTARG}" - ;; - ?|h) - echo >&2 "Usage: $(basename $0) [-p packages] [-- ghci-options]" - exit 1 - ;; - esac - done - shift "$(($OPTIND -1))" - - nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [ $packages ])" \ - --run "ghci $@" - } - export -f ghci-with-packages - - # 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 = - let xdg-cache-dir = - config.home.cacheHome - or "${config.home.homeDirectory}/.cache"; - in [ - # We don't want to rebuild Hackage simply due to a reboot, do we? }:) - (lib.removePrefix "${config.home.homeDirectory}/" - "${xdg-cache-dir}/cabal") - ".stack" - ]; - }; -} - diff --git a/users/msyds/default.nix b/users/msyds/default.nix index 6756c35..bdd6695 100644 --- a/users/msyds/default.nix +++ b/users/msyds/default.nix @@ -51,6 +51,7 @@ drawing-tablet.enable = on "sydpc"; easyeffects.enable = on "sydpc"; ryujinx.enable = on "sydpc"; + haskell.enable = true; sops = { enable = true; keyFile = "/persist/private-keys/age/crumb";