nix-gh/src
Eelco Dolstra 647291cd6c
Add basic impure derivations
Impure derivations are derivations that can produce a different result
every time they're built. Example:

  stdenv.mkDerivation {
    name = "impure";
    __impure = true; # marks this derivation as impure
    buildCommand = "date > $out";
  };

Some important characteristics:

* Impure derivations are not "cached". Thus, running "nix-build" on
  the example above multiple times will cause a rebuild every time. In
  the future, we could implement some mechanism for reusing impure
  builds across invocations.

* The outputs of impure derivations are moved to a content-addressed
  location after the build (i.e., the resulting store path will
  correspond to the hash of the contents of the path). This way,
  multiple builds of the same impure derivation do not collide.

* Because of content-addressability, the output paths of an impure
  derivation recorded in its .drv file are "virtual" placeholders for
  the actual outputs which are not known in advance. This also means
  that "nix-store -q bla.drv" gives a meaningless path.

* Pure derivations are not allowed to depend on impure
  derivations. The only exception is fixed-output derivations. Because
  the latter always produce a known output, they can depend on impure
  shenanigans just fine. Also, repeatedly running "nix-build" on such
  a fixed-output derivation will *not* cause a rebuild of the impure
  dependency. After all, if the fixed output exists, its dependencies
  are no longer relevant. Thus, fixed-output derivations form an
  "impurity barrier" in the dependency graph.

* When sandboxing is enabled, impure derivations can access the
  network in the same way as fixed-output derivations. In relaxed
  sandboxing mode, they can access the local filesystem.

* Currently, the output of an impure derivation must have no
  references. This is because the content-addressing scheme must be
  extended to handle references, in particular self-references (as
  described in the ASE-2005 paper.)

* Currently, impure derivations can only have a single output. No real
  reason for this.

* "nix-build" on an impure derivation currently creates a result
  symlink to the incorrect, virtual output.

A motivating example is the problem of using "fetchurl" on a
dynamically generated tarball whose contents are deterministic, but
where the tarball does not have a canonical form. Previously, this
required "fetchurl" to do the unpacking in the same
derivation. (That's what "fetchzip" does.) But now we can say:

  tarball = stdenv.mkDerivation {
    __impure = true;
    name = "tarball";
    buildInputs = [ curl ];
    buildCommand =
      "curl --fail -Lk c1f89c077e > $out";
  };

  unpacked = stdenv.mkDerivation {
    name = "unpacked";
    outputHashAlgo = "sha256";
    outputHashMode = "recursive";
    outputHash = "1jl8n1n36w63wffkm56slcfa7vj9fxkv4ax0fr0mcfah55qj5l8s";
    buildCommand =
      "mkdir $out; tar xvf ${tarball} -C $out";
  };

I needed this because <nix/fetchurl.nix> does not support unpacking,
and adding untar/unzip functionality would be annoying (especially
since we can't just call "tar" or "unzip" in a sandbox).

https://github.com/NixOS/nix/issues/520
2017-02-24 19:36:26 +01:00
..
boost Force stack trace for boost format errors 2016-03-02 15:46:07 +01:00
build-remote Merge branch 'nix-copy-closure-c++' of https://github.com/shlevy/nix 2017-02-07 20:47:45 +01:00
buildenv Fix Fedora build 2016-08-30 13:56:22 +02:00
libexpr Include config.h implicitly with '-include config.h' in CFLAGS 2017-02-08 21:51:02 +02:00
libmain Move netrcFile to Settings 2017-02-16 14:50:41 +01:00
libstore Add basic impure derivations 2017-02-24 19:36:26 +01:00
libutil Support netrc in <nix/fetchurl.nix> 2017-02-16 15:51:50 +01:00
nix exportReferencesGraph: Export more complete info in JSON format 2017-01-26 20:41:08 +01:00
nix-build nix-shell: Better error message when the shell can't be started 2017-02-24 17:25:00 +01:00
nix-channel nix-channel: Fix --update <CHANNELS> 2016-11-21 15:54:19 +01:00
nix-collect-garbage printMsg(lvlError, ...) -> printError(...) etc. 2016-09-21 16:54:53 +02:00
nix-copy-closure nix-copy-closure: Use computeFSClosure() and LegacySSHStore 2017-02-07 20:55:47 +01:00
nix-daemon RemoteStore::addToStore(): Pass content-addressability assertion 2017-02-22 16:58:00 +01:00
nix-env printMsg(lvlError, ...) -> printError(...) etc. 2016-09-21 16:54:53 +02:00
nix-instantiate Allow setting the state directory as a store parameter 2016-06-02 16:02:48 +02:00
nix-prefetch-url printMsg(lvlError, ...) -> printError(...) etc. 2016-09-21 16:54:53 +02:00
nix-store Provide default implementations for a couple of Store methods 2017-02-07 19:29:21 +01:00
resolve-system-dependencies printMsg(lvlError, ...) -> printError(...) etc. 2016-09-21 16:54:53 +02:00