@ -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 = [ " b u i l d C o m m a n d " ]
++ ( env . passAsFile or [ ] ) ;
}
// ( lib . optionalAttrs runLocal {
preferLocalBuild = true ;
allowSubstitutes = false ;
} )
// builtins . removeAttrs env [ " p a s s A s F i l e " ] ) ;
in
rec {
/* R u n t h e s h e l l c o m m a n d ` b u i l d C o m m a n d ' t o p r o d u c e a s t o r e p a t h n a m e d
* ` 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 " n a m e " { envVariable = true ; } '' e c h o h e l l o > $o u t ''
@ -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.
/* G e n e r a l i z e d v e r s i o n o f t h e ` r u n C o m m a n d ` - v a r i a n t s
* 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 = [ " b u i l d C o m m a n d " ]
++ ( derivationArgs . passAsFile or [ ] ) ;
}
// ( lib . optionalAttrs runLocal {
preferLocalBuild = true ;
allowSubstitutes = false ;
} )
// builtins . removeAttrs derivationArgs [ " p a s s A s F i l e " ] ) ;
/* W r i t e s a t e x t f i l e t o t h e n i x s t o r e .
* The contents of text is added to the file in the store .
*