summaryrefslogtreecommitdiff
path: root/Biz/Bild/Builder.nix
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2023-08-03 22:25:06 -0400
committerBen Sima <ben@bsima.me>2023-08-03 22:38:28 -0400
commit88af507c33ab32ae23e35bde9cd7fbbc0d534390 (patch)
tree0aef964b759d518806dafd6495e473d5206044eb /Biz/Bild/Builder.nix
parent40c6c18e57d88b101bd4396d48aefa681689bfb3 (diff)
Move buildPhase to a nix-instantiate argument
Diffstat (limited to 'Biz/Bild/Builder.nix')
-rw-r--r--Biz/Bild/Builder.nix34
1 files changed, 34 insertions, 0 deletions
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
+ '';
+}