From 8deaf41d60144551cc1ba98d695cc8390b85662b Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Fri, 29 Nov 2019 16:27:11 +0100 Subject: pkgs/build-support/trivial-builders: add runCommandLocal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- pkgs/build-support/trivial-builders.nix | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'pkgs/build-support/trivial-builders.nix') diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix index 55df09121b4..263320ca6d9 100644 --- a/pkgs/build-support/trivial-builders.nix +++ b/pkgs/build-support/trivial-builders.nix @@ -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 derivation’s 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. -- cgit 1.4.1