lix/src/libexpr
Eelco Dolstra 6de33a9c67
Add support for passing structured data to builders
Previously, all derivation attributes had to be coerced into strings
so that they could be passed via the environment. This is lossy
(e.g. lists get flattened, necessitating configureFlags
vs. configureFlagsArray, of which the latter cannot be specified as an
attribute), doesn't support attribute sets at all, and has size
limitations (necessitating hacks like passAsFile).

This patch adds a new mode for passing attributes to builders, namely
encoded as a JSON file ".attrs.json" in the current directory of the
builder. This mode is activated via the special attribute

  __structuredAttrs = true;

(The idea is that one day we can set this in stdenv.mkDerivation.)

For example,

  stdenv.mkDerivation {
    __structuredAttrs = true;
    name = "foo";
    buildInputs = [ pkgs.hello pkgs.cowsay ];
    doCheck = true;
    hardening.format = false;
  }

results in a ".attrs.json" file containing (sans the indentation):

  {
    "buildInputs": [],
    "builder": "/nix/store/ygl61ycpr2vjqrx775l1r2mw1g2rb754-bash-4.3-p48/bin/bash",
    "configureFlags": [
      "--with-foo",
      "--with-bar=1 2"
    ],
    "doCheck": true,
    "hardening": {
      "format": false
    },
    "name": "foo",
    "nativeBuildInputs": [
      "/nix/store/10h6li26i7g6z3mdpvra09yyf10mmzdr-hello-2.10",
      "/nix/store/4jnvjin0r6wp6cv1hdm5jbkx3vinlcvk-cowsay-3.03"
    ],
    "propagatedBuildInputs": [],
    "propagatedNativeBuildInputs": [],
    "stdenv": "/nix/store/f3hw3p8armnzy6xhd4h8s7anfjrs15n2-stdenv",
    "system": "x86_64-linux"
  }

"passAsFile" is ignored in this mode because it's not needed - large
strings are included directly in the JSON representation.

It is up to the builder to do something with the JSON
representation. For example, in bash-based builders, lists/attrsets of
string values could be mapped to bash (associative) arrays.
2017-01-26 20:40:33 +01:00
..
primops Support Git repos in the Nix path 2016-04-29 21:07:47 +02:00
attr-path.cc Optimize small lists 2015-07-23 22:05:09 +02:00
attr-path.hh Work on Values instead of Exprs 2013-09-03 13:17:51 +00:00
attr-set.cc Optimize empty sets 2015-07-23 23:11:08 +02:00
attr-set.hh Bindings: Add a method for iterating in lexicographically sorted order 2017-01-26 20:40:33 +01:00
common-opts.cc Enable HTTP/2 support 2016-09-14 16:36:02 +02:00
common-opts.hh StoreAPI -> Store 2016-02-04 14:48:42 +01:00
eval-inline.hh isFunctor: Simplify 2015-10-08 13:22:11 +02:00
eval.cc Add support for passing structured data to builders 2017-01-26 20:40:33 +01:00
eval.hh Add support for passing structured data to builders 2017-01-26 20:40:33 +01:00
get-drvs.cc Bindings: Add a method for iterating in lexicographically sorted order 2017-01-26 20:40:33 +01:00
get-drvs.hh nix-env: respect meta.outputsToInstall 2016-02-23 14:19:14 +01:00
json-to-value.cc Add builtin function "partition" 2016-08-29 19:36:54 +02:00
json-to-value.hh Add builtin function ‘fromJSON’ 2014-07-04 13:34:15 +02:00
lexer.l Tweak error message 2016-12-06 17:18:40 +01:00
local.mk Make primop registration pluggable 2016-04-14 12:50:01 +02:00
names.cc replace own regex class with std::regex 2016-10-18 20:22:25 +02:00
names.hh replace own regex class with std::regex 2016-10-18 20:22:25 +02:00
nix-expr.pc.in Install some pkgconfig files 2014-09-18 12:00:40 +02:00
nixexpr.cc First hit at providing support for floats in the language. 2016-01-05 00:40:40 +01:00
nixexpr.hh Throw a specific error for incomplete parse errors. 2016-02-24 04:32:21 -06:00
parser.y printMsg(lvlError, ...) -> printError(...) etc. 2016-09-21 16:54:53 +02:00
primops.cc Add support for passing structured data to builders 2017-01-26 20:40:33 +01:00
primops.hh Make primop registration pluggable 2016-04-14 12:50:01 +02:00
symbol-table.hh Improve printing of ASTs 2014-10-20 09:13:21 +02:00
value-to-json.cc nix path-info: Add --json flag 2016-08-29 17:29:24 +02:00
value-to-json.hh nix path-info: Add --json flag 2016-08-29 17:29:24 +02:00
value-to-xml.cc First hit at providing support for floats in the language. 2016-01-05 00:40:40 +01:00
value-to-xml.hh Use "#pragma once" to prevent repeated header file inclusion 2012-07-18 14:59:03 -04:00
value.hh Fix GC build 2016-08-30 13:12:12 +02:00