From 921111d1972388a0aa1841c545c753cb996c9257 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 3 Jan 2012 14:01:47 +0000 Subject: [PATCH] =?UTF-8?q?*=20Move=20the=20implementation=20of=20the=20?= =?UTF-8?q?=E2=80=98derivation=E2=80=99=20primop=20into=20a=20separate=20?= =?UTF-8?q?=20=20file.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- corepkgs/Makefile.am | 2 +- corepkgs/derivation.nix | 31 +++++++++++++++++++++++++++++++ src/libexpr/eval.cc | 4 ++-- src/libexpr/primops.cc | 24 +----------------------- 4 files changed, 35 insertions(+), 26 deletions(-) create mode 100644 corepkgs/derivation.nix diff --git a/corepkgs/Makefile.am b/corepkgs/Makefile.am index 86d7027ed..a8de60165 100644 --- a/corepkgs/Makefile.am +++ b/corepkgs/Makefile.am @@ -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 diff --git a/corepkgs/derivation.nix b/corepkgs/derivation.nix new file mode 100644 index 000000000..0e16ad6fa --- /dev/null +++ b/corepkgs/derivation.nix @@ -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 diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 2b97b76fb..bba14bc35 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -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(); } diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index ca7766487..02c444cd6 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -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