From b154d6b3be99a4a9f5907c84645ca569183bb40e Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Wed, 2 Aug 2023 10:38:22 -0400 Subject: Factor out nix builder into Haskell.nix This also fixed a bug where every dependency would get pulled into the Haskell target while searching for transitive dependencies. --- Biz/Bild/Example.hs | 6 +++++- Biz/Bild/Haskell.nix | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 Biz/Bild/Haskell.nix (limited to 'Biz/Bild') diff --git a/Biz/Bild/Example.hs b/Biz/Bild/Example.hs index f812707..87472bb 100644 --- a/Biz/Bild/Example.hs +++ b/Biz/Bild/Example.hs @@ -1,5 +1,9 @@ +{-# LANGUAGE NoImplicitPrelude #-} + -- : out example module Biz.Bild.Example where +import Alpha + main :: IO () -main = print "hi" +main = putStrLn "Hello world" diff --git a/Biz/Bild/Haskell.nix b/Biz/Bild/Haskell.nix new file mode 100644 index 0000000..24b6686 --- /dev/null +++ b/Biz/Bild/Haskell.nix @@ -0,0 +1,36 @@ +{ srcs # list of files +, root # path to git root +, packageSet # name mapped to private.${packageSet}, e.g. 'ghcWith' +, langDeps ? null # list of deps (as a string), split and passed to packageSet +, name # exe name +, main # entrypoint file +, mainIs # entrypoint module name +}: +with import (/. + root + "/Biz/Bild.nix") {}; +with builtins; +let + srcs_ = lib.strings.splitString " " srcs; + skip = ["_" ".direnv"]; + filter = file: type: + if elem (baseNameOf file) skip then false + # TODO: this means any new directory will cause a rebuild. this bad. + # i should recurse into the directory and match against the srcsr + else if type == "directory" then true + else if type == "regular" then builtins.elem file srcs_ + else false; + deps = pkgset: + if langDeps != null then + private.selectAttrs (lib.strings.splitString " " langDeps) pkgset + else + []; +in stdenv.mkDerivation { + inherit name; + buildInputs = [ (private.${packageSet} deps) ]; + src = lib.sources.cleanSourceWith {inherit filter; src = lib.sources.cleanSource root;}; + buildPhase = '' + ghc -Werror -i$src -odir. -hidir. --make $src/${main} -main-is "${mainIs}" -o ${name} + ''; + installPhase = '' + mkdir -p $out/bin && cp ${name} $out/bin + ''; +} -- cgit v1.2.3