makeRelative package:file-embed

Take a predicate to infer the project root and a relative file path, the given file path is then attached to the inferred project root This function looks at the source location of the Haskell file calling it, finds the first parent directory with a file matching the given predicate, and uses that as the root directory for fixing the relative path.
$(makeRelativeToLocationPredicate ((==) ".cabal" . takeExtension) "data/foo.txt" >>= embedFile)
Take a relative file path and attach it to the root of the current project. The idea here is that, when building with Stack, the build will always be executed with a current working directory of the root of the project (where your .cabal file is located). However, if you load up multiple projects with stack ghci, the working directory may be something else entirely. This function looks at the source location of the Haskell file calling it, finds the first parent directory with a .cabal file, and uses that as the root directory for fixing the relative path.
$(makeRelativeToProject "data/foo.txt" >>= embedFile)