* Move the implementation of the ‘derivation’ primop into a separate

file.
This commit is contained in:
Eelco Dolstra 2012-01-03 14:01:47 +00:00
parent 6c31232e14
commit 921111d197
4 changed files with 35 additions and 26 deletions

View File

@ -1,6 +1,6 @@
all-local: config.nix
files = nar.nix buildenv.nix buildenv.pl unpack-channel.nix unpack-channel.sh
files = nar.nix buildenv.nix buildenv.pl unpack-channel.nix unpack-channel.sh derivation.nix
install-exec-local:
$(INSTALL) -d $(DESTDIR)$(datadir)/nix/corepkgs

31
corepkgs/derivation.nix Normal file
View File

@ -0,0 +1,31 @@
attrs:
let
strict = derivationStrict attrs;
attrValues = attrs:
map (name: builtins.getAttr name attrs) (builtins.attrNames attrs);
outputToAttrListElement = output:
{ name = output;
value = attrs // {
outPath = builtins.getAttr (output + "Path") strict;
drvPath = strict.drvPath;
type = "derivation";
currentOutput = output;
} // outputsAttrs // { all = allList; };
};
outputsList =
if attrs ? outputs
then map outputToAttrListElement attrs.outputs
else [ (outputToAttrListElement "out") ];
outputsAttrs = builtins.listToAttrs outputsList;
allList = attrValues outputsAttrs;
head = if attrs ? outputs then builtins.head attrs.outputs else "out";
in builtins.getAttr head outputsAttrs

View File

@ -148,8 +148,6 @@ EvalState::EvalState()
nrAttrsets = nrOpUpdates = nrOpUpdateValuesCopied = 0;
deepestStack = (char *) -1;
createBaseEnv();
allowUnsafeEquality = getEnv("NIX_NO_UNSAFE_EQ", "") == "";
#if HAVE_BOEHMGC
@ -188,6 +186,8 @@ EvalState::EvalState()
foreach (Strings::iterator, i, paths) addToSearchPath(*i);
addToSearchPath("nix=" + nixDataDir + "/nix/corepkgs");
searchPathInsertionPoint = searchPath.begin();
createBaseEnv();
}

View File

@ -1099,29 +1099,7 @@ void EvalState::createBaseEnv()
/* Add a wrapper around the derivation primop that computes the
`drvPath' and `outPath' attributes lazily. */
string s = "attrs: \
let \
strict = derivationStrict attrs; \
attrValues = attrs: \
map (name: builtins.getAttr name attrs) (builtins.attrNames attrs); \
outputToAttrListElement = output: \
{ \
name = output; \
value = attrs // { \
outPath = builtins.getAttr (output + \"Path\") strict; \
drvPath = strict.drvPath; \
type = \"derivation\"; \
currentOutput = output; \
} // outputsAttrs // { all = allList; }; \
}; \
outputsList = if attrs ? outputs then \
map outputToAttrListElement attrs.outputs else \
[ (outputToAttrListElement \"out\") ]; \
outputsAttrs = builtins.listToAttrs outputsList; \
allList = attrValues outputsAttrs; \
head = if attrs ? outputs then builtins.head attrs.outputs else \"out\"; \
in builtins.getAttr head outputsAttrs";
mkThunk_(v, parseExprFromString(s, "/"));
mkThunk_(v, parseExprFromFile(findFile("nix/derivation.nix")));
addConstant("derivation", v);
/* Now that we've added all primops, sort the `builtins' attribute