trivial-builders: rework runCommand' into runCommandWith && expose
runCommandWith receives an attribute set with options which previously were positional arguments of runCommand' and a buildCommand. This allows for overriding the used stdenv freely (so stuff like llvmPackages.stdenv can be used). Additionally the possibility to change arguments passed to stdenv.mkDerivation is made more explicit via the derivationArgs argument.
This commit is contained in:
parent
b398d00903
commit
de78745bdd
@ -1,28 +1,12 @@
|
||||
{ lib, stdenv, stdenvNoCC, lndir, runtimeShell }:
|
||||
|
||||
let
|
||||
|
||||
runCommand' = runLocal: stdenv: name: env: buildCommand:
|
||||
stdenv.mkDerivation ({
|
||||
name = lib.strings.sanitizeDerivationName name;
|
||||
inherit buildCommand;
|
||||
passAsFile = [ "buildCommand" ]
|
||||
++ (env.passAsFile or []);
|
||||
}
|
||||
// (lib.optionalAttrs runLocal {
|
||||
preferLocalBuild = true;
|
||||
allowSubstitutes = false;
|
||||
})
|
||||
// builtins.removeAttrs env [ "passAsFile" ]);
|
||||
|
||||
in
|
||||
|
||||
rec {
|
||||
|
||||
/* Run the shell command `buildCommand' to produce a store path named
|
||||
* `name'. The attributes in `env' are added to the environment
|
||||
* prior to running the command. By default `runCommand' runs using
|
||||
* stdenv with no compiler environment. `runCommandCC`
|
||||
* prior to running the command. By default `runCommand` runs in a
|
||||
* stdenv with no compiler environment. `runCommandCC` uses the default
|
||||
* stdenv, `pkgs.stdenv`.
|
||||
*
|
||||
* Examples:
|
||||
* runCommand "name" {envVariable = true;} ''echo hello > $out''
|
||||
@ -43,13 +27,64 @@ rec {
|
||||
runCommand = runCommandNoCC;
|
||||
runCommandLocal = runCommandNoCCLocal;
|
||||
|
||||
runCommandNoCC = runCommand' false stdenvNoCC;
|
||||
runCommandNoCCLocal = runCommand' true stdenvNoCC;
|
||||
runCommandNoCC = name: env: runCommandWith {
|
||||
stdenv = stdenvNoCC;
|
||||
runLocal = false;
|
||||
inherit name;
|
||||
derivationArgs = env;
|
||||
};
|
||||
runCommandNoCCLocal = name: env: runCommandWith {
|
||||
stdenv = stdenvNoCC;
|
||||
runLocal = true;
|
||||
inherit name;
|
||||
derivationArgs = env;
|
||||
};
|
||||
|
||||
runCommandCC = runCommand' false stdenv;
|
||||
runCommandCC = name: env: runCommandWith {
|
||||
stdenv = stdenv;
|
||||
runLocal = false;
|
||||
inherit name;
|
||||
derivationArgs = env;
|
||||
};
|
||||
# `runCommandCCLocal` left out on purpose.
|
||||
# We shouldn’t force the user to have a cc in scope.
|
||||
|
||||
/* Generalized version of the `runCommand`-variants
|
||||
* which does customized behavior via a single
|
||||
* attribute set passed as the first argument
|
||||
* instead of having a lot of variants like
|
||||
* `runCommand*`. Additionally it allows changing
|
||||
* the used `stdenv` freely and has a more explicit
|
||||
* approach to changing the arguments passed to
|
||||
* `stdenv.mkDerivation`.
|
||||
*/
|
||||
runCommandWith =
|
||||
let
|
||||
# prevent infinite recursion for the default stdenv value
|
||||
defaultStdenv = stdenv;
|
||||
in
|
||||
{ stdenv ? defaultStdenv
|
||||
# which stdenv to use, defaults to a stdenv with a C compiler, pkgs.stdenv
|
||||
, runLocal ? false
|
||||
# whether to build this derivation locally instead of substituting
|
||||
, derivationArgs ? {}
|
||||
# extra arguments to pass to stdenv.mkDerivation
|
||||
, name
|
||||
# name of the resulting derivation
|
||||
}: buildCommand:
|
||||
stdenv.mkDerivation ({
|
||||
name = lib.strings.sanitizeDerivationName name;
|
||||
inherit buildCommand;
|
||||
passAsFile = [ "buildCommand" ]
|
||||
++ (derivationArgs.passAsFile or []);
|
||||
}
|
||||
// (lib.optionalAttrs runLocal {
|
||||
preferLocalBuild = true;
|
||||
allowSubstitutes = false;
|
||||
})
|
||||
// builtins.removeAttrs derivationArgs [ "passAsFile" ]);
|
||||
|
||||
|
||||
/* Writes a text file to the nix store.
|
||||
* The contents of text is added to the file in the store.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user