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.

lib.nix 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. # https://code.devalot.com/open/nix-hs
  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. # Extra library functions:
  14. { pkgs }: with pkgs.lib;
  15. let
  16. haskellSourceFilter = name: type:
  17. let baseName = baseNameOf (toString name); in ! (
  18. baseName == "dist" ||
  19. baseName == "dist-newstyle" ||
  20. baseName == "TAGS" ||
  21. hasPrefix ".ghc.environment" baseName
  22. );
  23. in rec {
  24. # A source cleaner for Haskell programs:
  25. cleanSource = src:
  26. cleanSourceWith {
  27. inherit src;
  28. filter = name: type:
  29. cleanSourceFilter name type &&
  30. haskellSourceFilter name type;
  31. };
  32. # Override a derivation so that its source is smaller:
  33. overrideSrc = src: drv:
  34. pkgs.haskell.lib.overrideCabal drv
  35. (_: {src = cleanSource src;});
  36. # Append some build inputs:
  37. appendBuildInputs = buildInputs: drv:
  38. drv.overrideAttrs (orig: {
  39. buildInputs = orig.buildInputs ++ buildInputs;
  40. });
  41. # Enable benchmarks (not sure why this isn't the default):
  42. benchmark = drv: pkgs.haskell.lib.doBenchmark drv;
  43. # Missing from Haskell lib:
  44. unBreak = drv: with pkgs.haskell.lib;
  45. overrideCabal drv (_: {
  46. broken = false;
  47. patches = [ ];
  48. });
  49. # Add data files to `drv` by running `f` and giving it the path to
  50. # where data files will be stored. It should return a shell
  51. # fragment.
  52. addDataFiles = hpkgs: f: drv: with pkgs.haskell.lib;
  53. let gname = hpkgs.ghc.name;
  54. gsystem = hpkgs.ghc.system;
  55. go = overrideCabal drv (orig: {
  56. postInstall = (orig.postInstall or "") +
  57. f "$data/share/${gname}/${gsystem}-${gname}/${drv.name}";
  58. });
  59. in if f != null then go else drv;
  60. # Fetch a dependency from Git and provide it with the updated
  61. # package set.
  62. fetchGit = args:
  63. let src = builtins.fetchGit args;
  64. in import "${src}/default.nix" { inherit pkgs; };
  65. }