Automate Haskell development with nixpkgs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

interactive.nix 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. ################################################################################
  2. #
  3. # This file is part of the package nix-hs. It is subject to the license
  4. # terms in the LICENSE file found in the top-level directory of this
  5. # distribution and at:
  6. #
  7. # git://git.devalot.com/nix-hs.git
  8. #
  9. # No part of this package, including this file, may be copied, modified,
  10. # propagated, or distributed except according to the terms contained in
  11. # the LICENSE file.
  12. #
  13. ################################################################################
  14. { pkgs ? (import <nixpkgs> {}).pkgs
  15. , compiler ? "default" # Which version of GHC to use, or "default".
  16. , profiling ? false # Enable profiling or not.
  17. , optimization ? true # Enable optimization or not.
  18. , file # The package file (default.nix) to load.
  19. }:
  20. with pkgs.lib;
  21. let
  22. # Some handy bindings:
  23. cabal = "${basePackages.cabal-install}/bin/cabal";
  24. cabalFlags = concatStringsSep " "
  25. [ (optionalString optimization "--enable-optimization")
  26. (optionalString profiling "--enable-profiling")
  27. "--write-ghc-environment-files=never"
  28. ];
  29. # These are the shell functions that `nix-hs' will call into.
  30. shellFunctions = "\n" + ''
  31. # NOTE: This is here because the generic Haskell builder doesn't
  32. # end it's shellHook with a newline and so we get syntax errors
  33. # without the blank line above.
  34. alias cabal='${cabal} --config-file=/dev/null'
  35. do_cabal_build() {
  36. set -e
  37. cabal v2-build ${cabalFlags}
  38. }
  39. do_cabal_test() {
  40. set -e
  41. cabal v2-test ${cabalFlags}
  42. }
  43. do_cabal_clean() {
  44. set -e
  45. cabal v2-clean
  46. }
  47. do_cabal_repl() {
  48. set -e
  49. cabal v2-repl ${cabalFlags} "$@"
  50. }
  51. do_cabal_run() {
  52. set -e
  53. cabal v2-run ${cabalFlags} -v0 "$@"
  54. }
  55. do_cabal_haddock() {
  56. set -e
  57. cabal v2-haddock
  58. }
  59. '';
  60. # Select a compiler:
  61. basePackages =
  62. if compiler == "default"
  63. then pkgs.haskellPackages
  64. else pkgs.haskell.packages."ghc${compiler}";
  65. # Override the Haskell package set with the one from above:
  66. alteredPackages = pkgs // { haskellPackages = basePackages; };
  67. # Load the local file and override its shell environment:
  68. drv = (import file { pkgs = alteredPackages; }).overrideAttrs (orig: {
  69. passthru = orig.passthru // {
  70. env = orig.passthru.env.overrideAttrs (_env: {
  71. shellHook = _env.shellHook + shellFunctions;
  72. });
  73. };
  74. });
  75. in drv.env