pkgs/build-support/trivial-builders: add runCommandLocal

A definition I’ve been copy-pasting everywhere so far, so it’s finally
time to add it to nixpkgs.

I’m using a remote builder for my regular nix builds, so trivial
`runCommand`s which first try a substitution and then copy the inputs
to the builder to run for 0.2s are quite noticable.

If we just always build these, we gain some build time, so let’s make
it easy to switch from remote to local.
This commit is contained in:
Profpatsch 2019-11-29 16:27:11 +01:00
parent 03ad033f97
commit 8deaf41d60

View File

@ -2,11 +2,16 @@
let
runCommand' = stdenv: name: env: buildCommand:
runCommand' = runLocal: stdenv: name: env: buildCommand:
stdenv.mkDerivation ({
inherit name buildCommand;
passAsFile = [ "buildCommand" ];
} // env);
}
// (lib.optionalAttrs runLocal {
preferLocalBuild = true;
allowSubstitutes = false;
})
// env);
in
@ -21,10 +26,26 @@ rec {
* runCommand "name" {envVariable = true;} ''echo hello > $out''
* runCommandNoCC "name" {envVariable = true;} ''echo hello > $out'' # equivalent to prior
* runCommandCC "name" {} ''gcc -o myfile myfile.c; cp myfile $out'';
*
* The `*Local` variants force a derivation to be built locally,
* it is not substituted.
*
* This is intended for very cheap commands (<1s execution time).
* It saves on the network roundrip and can speed up a build.
*
* It is the same as adding the special fields
* `preferLocalBuild = true;`
* `allowSubstitutes = false;`
* to a derivations attributes.
*/
runCommand = runCommandNoCC;
runCommandNoCC = runCommand' stdenvNoCC;
runCommandCC = runCommand' stdenv;
runCommandLocal = runCommandNoCCLocal;
runCommandNoCC = runCommand' false stdenvNoCC;
runCommandNoCCLocal = runCommand' true stdenvNoCC;
runCommandCC = runCommand' false stdenv;
runCommandCCLocal = runCommand' true stdenv;
/* Writes a text file to the nix store.