From 88af507c33ab32ae23e35bde9cd7fbbc0d534390 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Thu, 3 Aug 2023 22:25:06 -0400 Subject: Move buildPhase to a nix-instantiate argument --- Biz/Bild.hs | 19 +++++++++---------- Biz/Bild/Builder.nix | 34 ++++++++++++++++++++++++++++++++++ Biz/Bild/Haskell.nix | 36 ------------------------------------ 3 files changed, 43 insertions(+), 46 deletions(-) create mode 100644 Biz/Bild/Builder.nix delete mode 100644 Biz/Bild/Haskell.nix (limited to 'Biz') diff --git a/Biz/Bild.hs b/Biz/Bild.hs index d20c46e..5c28964 100644 --- a/Biz/Bild.hs +++ b/Biz/Bild.hs @@ -835,17 +835,16 @@ nixBuild loud Target {..} = args = [ argstr "srcs" <| unwords <| map str <| (root path) : Set.toList srcs, argstr "root" <| str root, - argstr "packageSet" "ghcWith" + argstr "packageSet" "ghcWith", + (argstr "langDeps" <| unwords <| map str <| Set.toList langdeps) <|> mempty, + argstr "name" <| str <| outname out, + argstr "main" <| str path, + argstr "mainIs" <| str <| Namespace.toHaskellModule namespace, + argstr "buildPhase" <| unwords + <| (Text.pack <| toNixFlag compiler) : + compilerFlags, + [str <| root "Biz/Bild/Builder.nix"] ] - ++ (langdeps == mempty) - ?: ( [], - [argstr "langDeps" <| unwords <| map str <| Set.toList langdeps] - ) - ++ [ argstr "name" <| str <| outname out, - argstr "main" <| str path, - argstr "mainIs" <| str <| Namespace.toHaskellModule namespace, - [str <| root "Biz/Bild/Haskell.nix"] - ] |> mconcat |> map Text.unpack, onFailure = Log.fail ["bild", "instantiate", nschunk namespace] >> Log.br, diff --git a/Biz/Bild/Builder.nix b/Biz/Bild/Builder.nix new file mode 100644 index 0000000..a0ed17c --- /dev/null +++ b/Biz/Bild/Builder.nix @@ -0,0 +1,34 @@ +{ 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 +, buildPhase +}: +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 buildPhase; + buildInputs = [ (private.${packageSet} deps) ]; + src = lib.sources.cleanSourceWith {inherit filter; src = lib.sources.cleanSource root;}; + installPhase = '' + mkdir -p $out/bin && cp ${name} $out/bin + ''; +} diff --git a/Biz/Bild/Haskell.nix b/Biz/Bild/Haskell.nix deleted file mode 100644 index 24b6686..0000000 --- a/Biz/Bild/Haskell.nix +++ /dev/null @@ -1,36 +0,0 @@ -{ 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