Merge pull request #41 from nmattia/nm-restricted-eval

Fix evaluation for restrict-eval
This commit is contained in:
Nicolas Mattia 2019-11-21 15:47:10 +01:00 committed by GitHub
commit 7f30aa64ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 12 deletions

View file

@ -48,6 +48,7 @@
, remarshal
, crateDependencies
, zstd
, fetchurl
}:
let
@ -214,7 +215,7 @@ let
# file that cargo itself uses to double check the sha256
unpackCrate = name: version: sha256:
let
crate = builtins.fetchurl {
crate = fetchurl {
url = "https://crates.io/api/v1/crates/${name}/${version}/download";
inherit sha256;
};

View file

@ -39,7 +39,7 @@ rec
# TODO: use `builtins.pathExists` once
# https://github.com/NixOS/nix/pull/3012 has landed and is generally
# available
pathExists = path:
pathExists = if lib.versionAtLeast builtins.nixVersion "2.3" then builtins.pathExists else path:
let
all = lib.all (x: x);
isOk = part:

View file

@ -7,8 +7,39 @@ let
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; };
# if the argument is not an attribute set, then assume it's the 'root'.
attrs = if argIsAttrs then arg else { root = arg; };
# 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.
# Below we try to come up with some good values for src and root if they're
# not defined.
sr =
let
hasRoot = builtins.hasAttr "root" attrs;
hasSrc = builtins.hasAttr "src" attrs;
isPath = x: builtins.typeOf x == "path";
root = attrs.root;
src = attrs.src;
in
# src: yes, root: no
if hasSrc && ! hasRoot then
if isPath src then
{ src = lib.cleanSource src; root = src; }
else { inherit src; root = src; }
# src: yes, root: yes
else if hasRoot && hasSrc then
{ inherit src root; }
# src: no, root: yes
else if hasRoot && ! hasSrc then
if isPath root then
{ inherit root; src = lib.cleanSource root; }
else
{ inherit root; src = root; }
# src: no, root: yes
else throw "please specify either 'src' or 'root'";
usePureFromTOML = attrs.usePureFromTOML or true;
readTOML = builtinz.readTOML usePureFromTOML;
@ -39,7 +70,7 @@ let
# config used when planning the builds
buildPlanConfig = rec {
inherit (attrs) src;
inherit (sr) src root;
# Whether we skip pre-building the deps
isSingleStep = attrs.singleStep or false;
@ -77,7 +108,7 @@ let
member:
{
name = member;
value = readTOML (src + "/${member}/Cargo.toml");
value = readTOML (root + "/${member}/Cargo.toml");
}
)
(toplevelCargotoml.workspace.members or [])
@ -104,10 +135,10 @@ let
isWorkspace = builtins.hasAttr "workspace" toplevelCargotoml;
# The top level Cargo.toml, either a workspace or package
toplevelCargotoml = readTOML (src + "/Cargo.toml");
toplevelCargotoml = readTOML (root + "/Cargo.toml");
# The cargo lock
cargolock = readTOML (src + "/Cargo.lock");
cargolock = readTOML (root + "/Cargo.lock");
packageName = attrs.name or toplevelCargotoml.package.name or
(if isWorkspace then "rust-workspace" else "rust-package");

View file

@ -10,6 +10,7 @@
, cargo
, rustc
, zstd
, fetchurl
}:
let
@ -29,6 +30,7 @@ let
cargo
rustc
zstd
fetchurl
;
};
@ -64,8 +66,8 @@ let
{
src = libb.dummySrc {
cargoconfig =
if builtinz.pathExists (toString config.src + "/.cargo/config")
then builtins.readFile (config.src + "/.cargo/config")
if builtinz.pathExists (toString config.root + "/.cargo/config")
then builtins.readFile (config.root + "/.cargo/config")
else null;
cargolock = config.cargolock;
cargotomls = config.cargotomls;

View file

@ -87,12 +87,12 @@ rec
"my-bin > $out";
workspace = naersk.buildPackage {
src = pkgs.lib.cleanSource ./test/workspace;
src = ./test/workspace;
doDoc = false;
};
workspace-patched = naersk.buildPackage {
src = pkgs.lib.cleanSource ./test/workspace-patched;
src = ./test/workspace-patched;
doDoc = false;
};