@philiptaron's lix workspace
Find a file
Eelco Dolstra c273c15cb1 Add primop ‘scopedImport’
‘scopedImport’ works like ‘import’, except that it takes a set of
attributes to be added to the lexical scope of the expression,
essentially extending or overriding the builtin variables.  For
instance, the expression

  scopedImport { x = 1; } ./foo.nix

where foo.nix contains ‘x’, will evaluate to 1.

This has a few applications:

* It allows getting rid of function argument specifications in package
  expressions. For instance, a package expression like:

    { stdenv, fetchurl, libfoo }:

    stdenv.mkDerivation { ... buildInputs = [ libfoo ]; }

  can now we written as just

    stdenv.mkDerivation { ... buildInputs = [ libfoo ]; }

  and imported in all-packages.nix as:

    bar = scopedImport pkgs ./bar.nix;

  So whereas we once had dependencies listed in three places
  (buildInputs, the function, and the call site), they now only need
  to appear in one place.

* It allows overriding builtin functions. For instance, to trace all
  calls to ‘map’:

  let
    overrides = {
      map = f: xs: builtins.trace "map called!" (map f xs);

      # Ensure that our override gets propagated by calls to
      # import/scopedImport.
      import = fn: scopedImport overrides fn;

      scopedImport = attrs: fn: scopedImport (overrides // attrs) fn;

      # Also update ‘builtins’.
      builtins = builtins // overrides;
    };
  in scopedImport overrides ./bla.nix

* Similarly, it allows extending the set of builtin functions. For
  instance, during Nixpkgs/NixOS evaluation, the Nixpkgs library
  functions could be added to the default scope.

There is a downside: calls to scopedImport are not memoized, unlike
import. So importing a file multiple times leads to multiple parsings
/ evaluations. It would be possible to construct the AST only once,
but that would require careful handling of variables/environments.
2014-05-26 14:26:29 +02:00
config Add config.guess, config.sub and install-sh 2013-11-25 11:26:02 +00:00
corepkgs derivation: Don't require certain function arguments 2014-04-04 21:53:47 +02:00
doc nix-store -l: Fetch build logs from the Internet 2014-05-21 17:19:36 +02:00
misc Prepare nix-mode to be uploaded to marmalade 2014-05-13 12:58:13 +02:00
mk Sync with make-rules repo 2014-04-03 17:37:14 +02:00
perl Fix "make dist" 2014-02-01 14:38:12 +01:00
scripts Don't barf when installing as root 2014-04-10 23:42:48 +02:00
src Add primop ‘scopedImport’ 2014-05-26 14:26:29 +02:00
tests Add primop ‘scopedImport’ 2014-05-26 14:26:29 +02:00
.gitignore Install an Upstart service 2014-05-02 13:14:10 +02:00
AUTHORS * Put something in here. 2004-11-07 20:30:02 +00:00
bootstrap.sh bootstrap: Simplify & make more robust. 2011-09-06 12:11:05 +00:00
build.nix Add an experimental nix-make file 2012-05-21 09:43:01 -04:00
configure.ac Build/install manual 2014-02-01 11:30:21 +01:00
COPYING * Change this to LGPL to keep the government happy. 2006-04-25 16:41:06 +00:00
dev-shell Hack to clean up tests/test-tmp 2013-08-21 12:53:46 +02:00
INSTALL * Autoconf / Automake configuration and building. 2003-04-04 16:14:56 +00:00
local.mk Remove redundant code 2014-05-14 22:25:25 +02:00
Makefile Install an Upstart service 2014-05-02 13:14:10 +02:00
Makefile.config.in nix-store -l: Fetch build logs from the Internet 2014-05-21 17:19:36 +02:00
nix.spec.in Really fix the RPM builds 2014-05-06 10:51:16 +02:00
README * Install documentation in $(docdir) (i.e. share/doc/nix). 2008-11-19 13:19:09 +00:00
release.nix Add ubuntu 14.04 2014-05-03 17:54:48 +02:00
version Bump version to 1.8 2014-04-11 11:15:24 +02:00

Nix is a purely functional package manager.  For installation and
usage instructions, please read the manual, which can be found in
`docs/manual/manual.html', and additionally at the Nix website at
<http://nixos.org/>.


Acknowledgments

This product includes software developed by the OpenSSL Project for
use in the OpenSSL Toolkit (http://www.OpenSSL.org/).