Forward extra arguments to mkDerivation

This commit is contained in:
Nicolas Mattia 2020-02-18 14:12:15 +01:00
parent 1b6b98d74f
commit d6ba33f942
6 changed files with 19 additions and 15 deletions

View file

@ -31,7 +31,9 @@ _NOTE_: `./path/to/rust/` should contain a `Cargo.lock`.
## Configuration
The `buildPackage` function also accepts an attribute set. The attributes are
described below. When the argument passed in _not_ an attribute set, e.g.
described below. Any attribute that is _not_ listed below will be forwarded _as
is_ to `stdenv.mkDerivation`. When the argument passed in _not_ an attribute
set, e.g.
``` nix
naersk.buildPackage theArg
@ -47,7 +49,6 @@ it is converted to an attribute set equivalent to `{ root = theArg; }`.
| `root` | Used by `naersk` to read the `Cargo.toml` and `Cargo.lock` files. May be different from `src`. When `src` is not set, `root` is (indirectly) used as `src`. |
| `cargoBuild` | The command to use for the build. The argument must be a function modifying the default value. <br/> Default: `''cargo $cargo_options build $cargo_build_options >> $cargo_build_output_json''` |
| `cargoBuildOptions` | Options passed to cargo build, i.e. `cargo build <OPTS>`. These options can be accessed during the build through the environment variable `cargo_build_options`. <br/> Note: naersk relies on the `--out-dir out` option and the `--message-format` option. The `$cargo_message_format` variable is set based on the cargo version.<br/> Note: these values are not (shell) escaped, meaning that you can use environment variables but must be careful when introducing e.g. spaces. <br/> The argument must be a function modifying the default value. <br/> Default: `[ "$cargo_release" ''-j "$NIX_BUILD_CORES"'' "--out-dir" "out" "--message-format=$cargo_message_format" ]` |
| `doCheck` | When true, `checkPhase` is run. Default: `true` |
| `cargoTestCommands` | The commands to run in the `checkPhase`. The argument must be a function modifying the default value. <br/> Default: `[ ''cargo $cargo_options test $cargo_test_options'' ]` |
| `cargoTestOptions` | Options passed to cargo test, i.e. `cargo test <OPTS>`. These options can be accessed during the build through the environment variable `cargo_test_options`. <br/> Note: these values are not (shell) escaped, meaning that you can use environment variables but must be careful when introducing e.g. spaces. <br/> The argument must be a function modifying the default value. <br/> Default: `[ "$cargo_release" ''-j "$NIX_BUILD_CORES"'' ]` |
| `buildInputs` | Extra `buildInputs` to all derivations. Default: `[]` |

View file

@ -31,7 +31,9 @@ _NOTE_: `./path/to/rust/` should contain a `Cargo.lock`.
## Configuration
The `buildPackage` function also accepts an attribute set. The attributes are
described below. When the argument passed in _not_ an attribute set, e.g.
described below. Any attribute that is _not_ listed below will be forwarded _as
is_ to `stdenv.mkDerivation`. When the argument passed in _not_ an attribute
set, e.g.
``` nix
naersk.buildPackage theArg

View file

@ -12,7 +12,6 @@
#| Whether or not to copy binaries to $out/bin
, copyBins
, copyBinsFilter
, doCheck
, doDoc
, doDocFail
, copyDocsToSeparateOutput
@ -54,6 +53,7 @@
, zstd
, fetchurl
, lndir
, userAttrs
}:
let
@ -121,11 +121,10 @@ let
} | jq -cMr '.[]')
'';
drv = stdenv.mkDerivation {
drvAttrs = {
name = "${pname}-${version}";
inherit
src
doCheck
version
preBuild
;
@ -399,5 +398,6 @@ let
done
${postBuild}
'';
drv = stdenv.mkDerivation (drvAttrs // userAttrs);
in
drv.overrideAttrs override

View file

@ -41,9 +41,6 @@ let
cargoBuildOptions =
allowFun attrs0 "cargoBuildOptions" [ "$cargo_release" ''-j "$NIX_BUILD_CORES"'' "--out-dir" "out" "--message-format=$cargo_message_format" ];
# When true, `checkPhase` is run.
doCheck = attrs0.doCheck or true;
# The commands to run in the `checkPhase`.
cargoTestCommands =
allowFun attrs0 "cargoTestCommands" [ ''cargo $cargo_options test $cargo_test_options'' ];
@ -128,6 +125,11 @@ let
then mkAttrs arg
else mkAttrs { root = arg; };
userAttrs =
if argIsAttrs
then removeAttrs arg (builtins.attrNames attrs)
else {};
# we differentiate 'src' and 'root'. 'src' is used as source for the build;
# 'root' is used to find files like 'Cargo.toml'. As often as possible 'root'
# should be a "path" to avoid reading values from the nix-store.
@ -176,7 +178,6 @@ let
copyBinsFilter
copyTarget
doCheck
cargoTestCommands
cargoTestOptions
@ -195,6 +196,7 @@ let
# config used when planning the builds
buildPlanConfig = rec {
inherit userAttrs;
inherit (sr) src root;
# Whether we skip pre-building the deps
isSingleStep = attrs.singleStep;

View file

@ -54,7 +54,7 @@ let
pname = config.packageName;
version = config.packageVersion;
preBuild = "";
inherit (config) src cargoTestCommands copyTarget copyBins copyBinsFilter copyDocsToSeparateOutput;
inherit (config) userAttrs src cargoTestCommands copyTarget copyBins copyBinsFilter copyDocsToSeparateOutput;
inherit gitDependencies;
} // config.buildConfig // {
builtDependencies = lib.optional (! config.isSingleStep)
@ -77,6 +77,7 @@ let
pname = "${config.packageName}-deps";
version = config.packageVersion;
} // config.buildConfig // {
inherit (config) userAttrs;
preBuild = "";
# TODO: custom cargoTestCommands should not be needed here
cargoTestCommands = map (cmd: "${cmd} || true") config.buildConfig.cargoTestCommands;

View file

@ -57,10 +57,8 @@ rec
lorri = naersk.buildPackage {
src = sources.lorri;
override = _oldAttrs: {
BUILD_REV_COUNT = 1;
RUN_TIME_CLOSURE = "${sources.lorri}/nix/runtime.nix";
};
BUILD_REV_COUNT = 1;
RUN_TIME_CLOSURE = "${sources.lorri}/nix/runtime.nix";
doCheck = false;
};