* 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 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-exec-local:
$(INSTALL) -d $(DESTDIR)$(datadir)/nix/corepkgs $(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; nrAttrsets = nrOpUpdates = nrOpUpdateValuesCopied = 0;
deepestStack = (char *) -1; deepestStack = (char *) -1;
createBaseEnv();
allowUnsafeEquality = getEnv("NIX_NO_UNSAFE_EQ", "") == ""; allowUnsafeEquality = getEnv("NIX_NO_UNSAFE_EQ", "") == "";
#if HAVE_BOEHMGC #if HAVE_BOEHMGC
@ -188,6 +186,8 @@ EvalState::EvalState()
foreach (Strings::iterator, i, paths) addToSearchPath(*i); foreach (Strings::iterator, i, paths) addToSearchPath(*i);
addToSearchPath("nix=" + nixDataDir + "/nix/corepkgs"); addToSearchPath("nix=" + nixDataDir + "/nix/corepkgs");
searchPathInsertionPoint = searchPath.begin(); searchPathInsertionPoint = searchPath.begin();
createBaseEnv();
} }

View file

@ -1099,29 +1099,7 @@ void EvalState::createBaseEnv()
/* Add a wrapper around the derivation primop that computes the /* Add a wrapper around the derivation primop that computes the
`drvPath' and `outPath' attributes lazily. */ `drvPath' and `outPath' attributes lazily. */
string s = "attrs: \ mkThunk_(v, parseExprFromFile(findFile("nix/derivation.nix")));
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, "/"));
addConstant("derivation", v); addConstant("derivation", v);
/* Now that we've added all primops, sort the `builtins' attribute /* Now that we've added all primops, sort the `builtins' attribute