naersk/default.nix

76 lines
2 KiB
Nix
Raw Normal View History

2020-04-15 13:10:42 +00:00
{ cargo
2019-07-02 10:50:32 +00:00
, darwin
2020-04-15 13:10:42 +00:00
, fetchurl
, jq
, lib
, lndir
2019-07-02 10:50:32 +00:00
, remarshal
2020-04-15 13:10:42 +00:00
, rsync
, runCommand
2019-07-02 10:50:32 +00:00
, rustc
2020-04-15 13:10:42 +00:00
, stdenv
, writeText
2019-11-13 14:18:08 +00:00
, zstd
2020-04-15 13:10:42 +00:00
}@defaultBuildAttrs:
2019-06-13 11:26:19 +00:00
2019-08-28 17:21:13 +00:00
let
2019-11-18 15:16:46 +00:00
libb = import ./lib.nix { inherit lib writeText runCommand remarshal; };
builtinz = builtins // import ./builtins
{ inherit lib writeText remarshal runCommand; };
2020-04-15 13:10:42 +00:00
2019-11-18 13:49:27 +00:00
mkConfig = arg:
import ./config.nix { inherit lib arg libb builtinz; };
2019-11-18 13:49:27 +00:00
buildPackage = arg:
let
config = mkConfig arg;
gitDependencies =
2020-03-23 07:50:12 +00:00
libb.findGitDependencies { inherit (config) cargotomls cargolock; };
2020-04-15 13:10:42 +00:00
cargoconfig =
if builtinz.pathExists (toString config.root + "/.cargo/config")
then builtins.readFile (config.root + "/.cargo/config")
else null;
build = args: import ./build.nix (
{
inherit gitDependencies;
version = config.packageVersion;
} // config.buildConfig // defaultBuildAttrs // args
);
# the dependencies from crates.io
buildDeps =
build
{
pname = "${config.packageName}-deps";
src = libb.dummySrc {
inherit cargoconfig;
inherit (config) cargolock cargotomls copySources copySourcesFrom;
2020-04-15 13:10:42 +00:00
};
inherit (config) userAttrs;
# TODO: custom cargoTestCommands should not be needed here
cargoTestCommands = map (cmd: "${cmd} || true") config.buildConfig.cargoTestCommands;
copyTarget = true;
copyBins = false;
copyBinsFilter = ".";
copyDocsToSeparateOutput = false;
builtDependencies = [];
};
# the top-level build
buildTopLevel =
let
drv =
build
{
pname = config.packageName;
inherit (config) userAttrs src;
builtDependencies = lib.optional (! config.isSingleStep) buildDeps;
};
in
drv.overrideAttrs config.overrideMain;
2020-04-15 13:10:42 +00:00
in
buildTopLevel;
in
2020-04-15 13:10:42 +00:00
{ inherit buildPackage; }