From 921111d1972388a0aa1841c545c753cb996c9257 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 3 Jan 2012 14:01:47 +0000 Subject: * Move the implementation of the ‘derivation’ primop into a separate file. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- corepkgs/Makefile.am | 2 +- corepkgs/derivation.nix | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 corepkgs/derivation.nix (limited to 'corepkgs') diff --git a/corepkgs/Makefile.am b/corepkgs/Makefile.am index 86d7027ed06e..a8de601657b1 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 000000000000..0e16ad6fa300 --- /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 -- cgit 1.4.1