Allow path or attrset as arguments

This commit is contained in:
Nicolas Mattia 2019-11-18 14:49:27 +01:00
parent 79ccb516e9
commit 4714fb8ac1
4 changed files with 44 additions and 35 deletions

View file

@ -1,5 +1,5 @@
src:
{ preBuild
{ src
, preBuild
#| What command to run during the build phase
, cargoBuild
, #| What command to run during the test phase

View file

@ -1,5 +1,14 @@
{ lib, libb, builtinz, src, attrs }:
{ lib, libb, builtinz, arg }:
let
argIsAttrs =
if lib.isDerivation arg then false
else if lib.isString arg then false
else if builtins.typeOf arg == "path" then false
else if builtins.hasAttr "outPath" arg then false
else true;
attrs = if argIsAttrs then arg else
{ src = if builtins.typeOf arg == "path" then lib.cleanSource arg else arg; };
usePureFromTOML = attrs.usePureFromTOML or true;
readTOML = builtinz.readTOML usePureFromTOML;
@ -31,7 +40,7 @@ let
# config used when planning the builds
buildPlanConfig = rec
{
{ inherit (attrs) src;
# Whether we skip pre-building the deps
isSingleStep = attrs.singleStep or false;

View file

@ -36,11 +36,11 @@ let
in
# Crate building
let
mkConfig = src: attrs:
import ./config.nix { inherit lib src attrs libb builtinz; };
buildPackage = src: attrs:
let config = (mkConfig src attrs); in
import ./build.nix src
mkConfig = arg:
import ./config.nix { inherit lib arg libb builtinz; };
buildPackage = arg:
let config = (mkConfig arg); in
import ./build.nix
(defaultBuildAttrs //
{ pname = config.packageName;
version = config.packageVersion;
@ -50,21 +50,23 @@ let
if [ -f src/lib.rs ] ; then touch src/lib.rs; fi
if [ -f src/main.rs ] ; then touch src/main.rs; fi
'';
inherit (config) cargoTestCommands copyTarget copyBins copyDocsToSeparateOutput ;
inherit (config) src cargoTestCommands copyTarget copyBins copyDocsToSeparateOutput ;
} // config.buildConfig //
{ builtDependencies = lib.optional (! config.isSingleStep)
(
import ./build.nix
(
{ src =
(libb.dummySrc
{ cargoconfig =
if builtinz.pathExists (toString src + "/.cargo/config")
then builtins.readFile (src + "/.cargo/config")
if builtinz.pathExists (toString config.src + "/.cargo/config")
then builtins.readFile (config.src + "/.cargo/config")
else null;
cargolock = config.cargolock;
cargotomls = config.cargotomls;
inherit (config) patchedSources;
}
)
); } //
(defaultBuildAttrs //
{ pname = "${config.packageName}-deps";
version = config.packageVersion;
@ -77,7 +79,7 @@ let
copyDocsToSeparateOutput = false;
builtDependencies = [];
}
)
))
);
});
in { inherit buildPackage; }

View file

@ -25,13 +25,14 @@ rec
# { buildInputs = [ ripgrep ]; }
# "rg --help && touch $out";
ripgrep-all = naersk.buildPackage sources.ripgrep-all {};
ripgrep-all = naersk.buildPackage sources.ripgrep-all;
ripgrep-all_test = pkgs.runCommand "ripgrep-all-test"
{ buildInputs = [ ripgrep-all ]; }
"rga --help && touch $out";
lorri = naersk.buildPackage sources.lorri
{ override = _oldAttrs:
lorri = naersk.buildPackage
{ src = sources.lorri;
override = _oldAttrs:
{ BUILD_REV_COUNT = 1;
RUN_TIME_CLOSURE = "${sources.lorri}/nix/runtime.nix";
};
@ -40,11 +41,12 @@ rec
lorri_test = pkgs.runCommand "lorri-test" { buildInputs = [ lorri ]; }
"lorri --help && touch $out";
talent-plan-1 = naersk.buildPackage "${sources.talent-plan}/rust/projects/project-1" {};
talent-plan-2 = naersk.buildPackage "${sources.talent-plan}/rust/projects/project-2" {};
talent-plan-1 = naersk.buildPackage "${sources.talent-plan}/rust/projects/project-1";
talent-plan-2 = naersk.buildPackage "${sources.talent-plan}/rust/projects/project-2";
talent-plan-3 = naersk.buildPackage
"${sources.talent-plan}/rust/projects/project-3"
{ doCheck = false; };
{ src = "${sources.talent-plan}/rust/projects/project-3";
doCheck = false;
};
# TODO: support for git deps
#test_talent-plan-4 = buildPackage "${sources.talent-plan}/rust/projects/project-4" {};
@ -74,29 +76,25 @@ rec
# Error: Cannot parse as TOML (<string>(92, 14): msg)
#rust = naersk.buildPackage sources.rust {};
rustlings = naersk.buildPackage sources.rustlings {};
rustlings = naersk.buildPackage sources.rustlings;
simple-dep = naersk.buildPackage
(pkgs.lib.cleanSource ./test/simple-dep)
{};
simple-dep = naersk.buildPackage ./test/simple-dep;
simple-dep-patched = naersk.buildPackage
(pkgs.lib.cleanSource ./test/simple-dep-patched)
{};
simple-dep-patched = naersk.buildPackage ./test/simple-dep-patched;
dummyfication = naersk.buildPackage
(pkgs.lib.cleanSource ./test/dummyfication)
{};
dummyfication = naersk.buildPackage ./test/dummyfication;
dummyfication_test = pkgs.runCommand "dummyfication-test" { buildInputs = [ dummyfication ]; }
"my-bin > $out";
workspace = naersk.buildPackage
(pkgs.lib.cleanSource ./test/workspace)
{ doDoc = false; };
{ src = pkgs.lib.cleanSource ./test/workspace;
doDoc = false;
};
workspace-patched = naersk.buildPackage
(pkgs.lib.cleanSource ./test/workspace-patched)
{ doDoc = false; };
{ src = pkgs.lib.cleanSource ./test/workspace-patched;
doDoc = false;
};
# Fails with some remarshal error
#servo = naersk.buildPackage