summaryrefslogtreecommitdiff
path: root/Biz/Bild/Builder.nix
blob: 04002d0dbae15c4905a4dd7c8872309c2eccae84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{ 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
, 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 rec {
  inherit name buildPhase;
  src = lib.sources.cleanSourceWith {inherit filter; src = lib.sources.cleanSource root;};
  BIZ_ROOT = src;
  buildInputs = [ (private.${packageSet} deps) ];
  installPhase = ''
    mkdir -p $out/bin && cp ${name} $out/bin
  '';
}