@@ -3,7 +3,7 @@
33
44{ lib, writeText, inherit-local }:
55
6−{
6+rec {
77 withPackages = pkgs: let
88 extras = map (x: x.emacsBufferSetup pkgs) (builtins.filter (builtins.hasAttr "emacsBufferSetup") pkgs);
99 in writeText "dir-locals.el" ''
@@ -49,4 +49,28 @@
4949
5050 ${lib.concatStringsSep "\n" extras}
5151 '';
52+ # nix-buffer function for a project with a bunch of haskell packages
53+ # in one directory
54+ haskellMonoRepo = { project-root # The monorepo root
55+ , haskellPackages # The composed haskell packages set that contains all of the packages
56+ }: { root }:
57+ let # The haskell paths.
58+ haskell-paths = lib.filesystem.haskellPathsInDir project-root;
59+ # Find the haskell package that the 'root' is in, if any.
60+ haskell-path-parent =
61+ let filtered = builtins.filter (name:
62+ lib.hasPrefix (toString (project-root + "/${name}")) (toString root)
63+ ) (builtins.attrNames haskell-paths);
64+ in
65+ if filtered == [] then null else builtins.head filtered;
66+ # We're in the directory of a haskell package
67+ is-haskell-package = haskell-path-parent != null;
68+ haskell-package = haskellPackages.${haskell-path-parent};
69+ # GHC environment with all needed deps for the haskell package
70+ haskell-package-env =
71+ builtins.head haskell-package.env.nativeBuildInputs;
72+ in
73+ if is-haskell-package
74+ then withPackages [ haskell-package-env ]
75+ else {};
5276}