feat(haskell): ghc-with-packages
All checks were successful
build / build (push) Successful in 2m59s
All checks were successful
build / build (push) Successful in 2m59s
This commit is contained in:
31
modules/home/haskell.nix
Normal file
31
modules/home/haskell.nix
Normal file
@@ -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"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
52
modules/home/haskell/ghc-with-packages.sh
Normal file
52
modules/home/haskell/ghc-with-packages.sh
Normal file
@@ -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
|
||||||
@@ -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"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -51,6 +51,7 @@
|
|||||||
drawing-tablet.enable = on "sydpc";
|
drawing-tablet.enable = on "sydpc";
|
||||||
easyeffects.enable = on "sydpc";
|
easyeffects.enable = on "sydpc";
|
||||||
ryujinx.enable = on "sydpc";
|
ryujinx.enable = on "sydpc";
|
||||||
|
haskell.enable = true;
|
||||||
sops = {
|
sops = {
|
||||||
enable = true;
|
enable = true;
|
||||||
keyFile = "/persist/private-keys/age/crumb";
|
keyFile = "/persist/private-keys/age/crumb";
|
||||||
|
|||||||
Reference in New Issue
Block a user