summary refs log tree commit diff
path: root/pkgs/development/compilers/crystal/build-package.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/compilers/crystal/build-package.nix')
-rw-r--r--pkgs/development/compilers/crystal/build-package.nix27
1 files changed, 17 insertions, 10 deletions
diff --git a/pkgs/development/compilers/crystal/build-package.nix b/pkgs/development/compilers/crystal/build-package.nix
index 215c3d37d88..4edf1ddf958 100644
--- a/pkgs/development/compilers/crystal/build-package.nix
+++ b/pkgs/development/compilers/crystal/build-package.nix
@@ -24,6 +24,7 @@
   # Specify binaries to build in the form { foo.src = "src/foo.cr"; }
   # The default `crystal build` options can be overridden with { foo.options = [ "--optionname" ]; }
 , crystalBinaries ? { }
+, enableParallelBuilding ? true
 , ...
 }@args:
 
@@ -51,6 +52,20 @@ let
 
   buildDirectly = shardsFile == null || crystalBinaries != { };
 
+  mkCrystalBuildArgs = bin: attrs:
+    lib.concatStringsSep " " ([
+      "crystal"
+      "build"
+    ] ++ lib.optionals enableParallelBuilding [
+      "--threads"
+      "$NIX_BUILD_CORES"
+    ] ++ [
+      "-o"
+      bin
+      (attrs.src or (throw "No source file for crystal binary ${bin} provided"))
+      (lib.concatStringsSep " " (attrs.options or defaultOptions))
+    ]);
+
 in
 stdenv.mkDerivation (mkDerivationArgs // {
 
@@ -72,6 +87,7 @@ stdenv.mkDerivation (mkDerivationArgs // {
 
   PREFIX = placeholder "out";
 
+  inherit enableParallelBuilding;
   strictDeps = true;
   buildInputs = args.buildInputs or [ ] ++ [ crystal ];
 
@@ -88,16 +104,7 @@ stdenv.mkDerivation (mkDerivationArgs // {
     "runHook preBuild"
   ] ++ lib.optional (format == "make")
     "make \${buildTargets:-build} $makeFlags"
-  ++ lib.optionals (format == "crystal") (lib.mapAttrsToList
-    (bin: attrs: ''
-      crystal ${lib.escapeShellArgs ([
-        "build"
-        "-o"
-        bin
-        (attrs.src or (throw "No source file for crystal binary ${bin} provided"))
-      ] ++ (attrs.options or defaultOptions))}
-    '')
-    crystalBinaries)
+  ++ lib.optionals (format == "crystal") (lib.mapAttrsToList mkCrystalBuildArgs crystalBinaries)
   ++ lib.optional (format == "shards")
     "shards build --local --production ${lib.concatStringsSep " " (args.options or defaultOptions)}"
   ++ [ "runHook postBuild" ]));