about summary refs log tree commit diff
path: root/tests/lang
AgeCommit message (Collapse)AuthorFilesLines
2014-07-04 Add builtin function ‘fromJSON’Eelco Dolstra2-0/+33
Fixes #294.
2014-06-10 == operator: Ignore string contextEelco Dolstra1-1/+1
There really is no case I can think of where taking the context into account is useful. Mostly it's just very inconvenient.
2014-05-29 Fix testEelco Dolstra2-2/+2
2014-05-26 Make the Nix search path declarativeEelco Dolstra2-1/+2
Nix search path lookups like <nixpkgs> are now desugared to ‘findFile nixPath <nixpkgs>’, where ‘findFile’ is a new primop. Thus you can override the search path simply by saying let nixPath = [ { prefix = "nixpkgs"; path = "/my-nixpkgs"; } ]; in ... <nixpkgs> ... In conjunction with ‘scopedImport’ (commit c273c15cb13bb86420dda1e5341a4e19517532b5), the Nix search path can be propagated across imports, e.g. let overrides = { nixPath = [ ... ] ++ builtins.nixPath; import = fn: scopedImport overrides fn; scopedImport = attrs: fn: scopedImport (overrides // attrs) fn; builtins = builtins // overrides; }; in scopedImport overrides ./nixos
2014-05-26 Ensure that -I flags get included in nixPathEelco Dolstra1-1/+1
Also fixes #261.
2014-05-26 Add constant ‘nixPath’Eelco Dolstra1-1/+8
It contains the Nix expression search path as a list of { prefix, path } sets, e.g. [ { path = "/nix/var/nix/profiles/per-user/root/channels/nixos"; prefix = ""; } { path = "/etc/nixos/configuration.nix"; prefix = "nixos-config"; } { path = "/home/eelco/Dev/nix/inst/share/nix/corepkgs"; prefix = "nix"; } ]
2014-05-26 Add primop ‘scopedImport’Eelco Dolstra4-0/+16
‘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-03-10 If a dynamic attribute name evaluates to null, remove it from the setShea Levy2-0/+2
2014-02-26 Test some more primopsEelco Dolstra8-6/+21
2014-01-14 Allow "bare" dynamic attrsShea Levy2-0/+18
Now, in addition to a."${b}".c, you can write a.${b}.c (applicable wherever dynamic attributes are valid). Signed-off-by: Shea Levy <shea@shealevy.com>
2014-01-06 Merge branch 'dynamic-attrs-no-sugar' of github.com:shlevy/nixEelco Dolstra6-0/+24
2014-01-06 Disable the tail call testEelco Dolstra1-0/+0
On i686-linux, GCC stubbornly refuses to do tail-call optimisation. Don't know why. http://hydra.nixos.org/build/7300170
2013-12-31 Fold dynamic binds handling into addAttrShea Levy2-0/+2
Since addAttr has to iterate through the AttrPath we pass it, it makes more sense to just iterate through the AttrNames in addAttr instead. As an added bonus, this allows attrsets where two dynamic attribute paths have the same static leading part (see added test case for an example that failed previously). Signed-off-by: Shea Levy <shea@shealevy.com>
2013-12-31 Dynamic attrsShea Levy2-0/+18
This adds new syntax for attribute names: * attrs."${name}" => getAttr name attrs * attrs ? "${name}" => isAttrs attrs && hasAttr attrs name * attrs."${name}" or def => if attrs ? "${name}" then attrs."${name}" else def * { "${name}" = value; } => listToAttrs [{ inherit name value; }] Of course, it's a bit more complicated than that. The attribute chains can be arbitrarily long and contain combinations of static and dynamic parts (e.g. attrs."${foo}".bar."${baz}" or qux), which is relatively straightforward for the getAttrs/hasAttrs cases but is more complex for the listToAttrs case due to rules about duplicate attribute definitions. For attribute sets with dynamic attribute names, duplicate static attributes are detected at parse time while duplicate dynamic attributes are detected when the attribute set is forced. So, for example, { a = null; a.b = null; "${"c"}" = true; } will be a parse-time error, while { a = {}; "${"a"}".b = null; c = true; } will be an eval-time error (technically that case could theoretically be detected at parse time, but the general case would require full evaluation). Moreover, duplicate dynamic attributes are not allowed even in cases where they would be with static attributes ({ a.b.d = true; a.b.c = false; } is legal, but { a."${"b"}".d = true; a."${"b"}".c = false; } is not). This restriction might be relaxed in the future in cases where the static variant would not be an error, but it is not obvious that that is desirable. Finally, recursive attribute sets with dynamic attributes have the static attributes in scope but not the dynamic ones. So rec { a = true; "${"b"}" = a; } is equivalent to { a = true; b = true; } but rec { "${"a"}" = true; b = a; } would be an error or use a from the surrounding scope if it exists. Note that the getAttr, getAttr or default, and hasAttr are all implemented purely in the parser as syntactic sugar, while attribute sets with dynamic attribute names required changes to the AST to be implemented cleanly. This is an alternative solution to and closes #167 Signed-off-by: Shea Levy <shea@shealevy.com>
2013-12-31 Add the ExprBuiltin Expr type to the ASTShea Levy2-0/+4
Certain desugaring schemes may require the parser to use some builtin function to do some of the work (e.g. currently `throw` is used to lazily cause an error if a `<>`-style path is not in the search path) Unfortunately, these names are not reserved keywords, so an expression that uses such a syntactic sugar will not see the expected behavior (see tests/lang/eval-okay-redefine-builtin.nix for an example). This adds the ExprBuiltin AST type, which when evaluated uses the value from the rootmost variable scope (which of course is initialized internally and can't shadow any of the builtins). Signed-off-by: Shea Levy <shea@shealevy.com>
2013-11-19 Add a toJSON primopEelco Dolstra2-0/+12
2013-11-18 Add a primop unsafeGetAttrPos to return the position of an attributeEelco Dolstra2-0/+7
2013-11-18 Add a symbol __curPos that expands to the current source locationEelco Dolstra2-0/+6
I.e. an attribute set { file = <string>; line = <int>; column = <int>; }.
2013-11-12 Add a test to check that tail calls run in bounded stack spaceEelco Dolstra2-0/+4
2013-10-24 Rename "attribute sets" to "sets"Eelco Dolstra1-1/+1
We don't have any other kind of sets so calling them attribute sets is unnecessarily verbose.
2013-10-24 Add a test of the type primopsEelco Dolstra2-0/+24
2013-10-17 Add a test for type correctness of antiquotesEelco Dolstra3-0/+3
Antiquotes should evaluate to strings or paths. This is usually checked, except in the case where the antiquote makes up the entire string, as in "${expr}". This is optimised to expr, which discards the runtime type checks / coercions.
2013-10-16 Add a regression test for correct path antiquotation behaviorEelco Dolstra1-0/+4
This broke in Nix 1.6.
2013-08-26 Simplify inherited attribute handlingShea Levy2-0/+25
This reduces the difference between inherited and non-inherited attribute handling to the choice of which env to use (in recs and lets) by setting the AttrDef::e to a new ExprVar in the parser rather than carrying a separate AttrDef::v VarRef member. As an added bonus, this allows inherited attributes that inherit from a with to delay forcing evaluation of the with's attributes. Signed-off-by: Shea Levy <shea@shealevy.com>
2013-08-26 Fix typos, especially those that end up in the Nix manualIvan Kozik1-1/+1
2013-08-02 Let the ordering operators also work on stringsEelco Dolstra2-1/+6
E.g. ‘"foo" < "bar"’ now works.
2013-08-02 Add comparison operators ‘<’, ‘<=’, ‘>’ and ‘>=’Eelco Dolstra2-1/+24
2013-08-02 Add integer ‘-’, ‘*’ and ‘/’ operatorsEelco Dolstra3-1/+11
2013-08-02 Add a unary integer negation operatorEelco Dolstra2-2/+7
This allows saying "-1" instead of "builtins.sub 0 1".
2013-08-02 Overload the ‘+’ operator to support integer additionEelco Dolstra2-4/+4
2013-07-31 Test the delayed with a bit moreEelco Dolstra2-4/+7
2013-07-31 Delay evaulation of `with` attrs until a variable lookup needs themShea Levy2-0/+27
Evaluation of attribute sets is strict in the attribute names, which means immediate evaluation of `with` attribute sets rules out some potentially interesting use cases (e.g. where the attribute names of one set depend in some way on another but we want to bring those names into scope for some values in the second set). The major example of this is overridable self-referential package sets (e.g. all-packages.nix). With immediate `with` evaluation, the only options for such sets are to either make them non-recursive and explicitly use the name of the overridden set in non-overridden one every time you want to reference another package, or make the set recursive and use the `__overrides` hack. As shown in the test case that comes with this commit, though, delayed `with` evaluation allows a nicer third alternative. Signed-off-by: Shea Levy <shea@shealevy.com>
2013-02-08 Rename "hash" to "hashString" and handle SHA-1Eelco Dolstra2-5/+6
2013-02-08 experimental/hashMarc Weber2-0/+7
adding primop function calculating hash of a string Signed-off-by: Marc Weber <marco-oweber@gmx.de>
2012-09-27 Allow dashes in identifiersEelco Dolstra1-2/+2
In Nixpkgs, the attribute in all-packages.nix corresponding to a package is usually equal to the package name. However, this doesn't work if the package contains a dash, which is fairly common. The convention is to replace the dash with an underscore (e.g. "dbus-lib" becomes "dbus_glib"), but that's annoying. So now dashes are valid in variable / attribute names, allowing you to write: dbus-glib = callPackage ../development/libraries/dbus-glib { }; and buildInputs = [ dbus-glib ]; Since we don't have a negation or subtraction operation in Nix, this is unambiguous.
2012-01-19 * Add a test case for comparing derivations.Eelco Dolstra2-0/+11
2012-01-03 * Refactoring: Get rid of a few subdirectories in corepkgs/, and someEelco Dolstra1-1/+1
other simplifications. * Use <nix/...> to locate the corepkgs. This allows them to be overriden through $NIX_PATH. * Use bash's pipefail option in the NAR builder so that we don't need to create a temporary file.
2011-12-21 * Add some accidentally committed files.Eelco Dolstra2-2/+0
2011-08-06 * Add the Nix corepkgs to the end of the search path. This makes itEelco Dolstra2-3/+3
possible for other Nix expressions to use corepkgs (mostly useful for the buildenv function).
2011-08-06 * Allow redirections in search path entries. E.g. if you have aEelco Dolstra3-3/+3
directory /home/eelco/src/stdenv-updates that you want to use as the directory for import such as with (import <nixpkgs> { }); then you can say $ nix-build -I nixpkgs=/home/eelco/src/stdenv-updates
2011-08-06 * Add a Nix expression search path feature. Paths between angleEelco Dolstra13-0/+15
brackets, e.g. import <nixpkgs/pkgs/lib> are resolved by looking them up relative to the elements listed in the search path. This allows us to get rid of hacks like import "${builtins.getEnv "NIXPKGS_ALL"}/pkgs/lib" The search path can be specified through the ‘-I’ command-line flag and through the colon-separated ‘NIX_PATH’ environment variable, e.g., $ nix-build -I /etc/nixos ... If a file is not found in the search path, an error message is lazily thrown.
2011-07-13 * Allow attribute names to be strings. Based on theEelco Dolstra2-0/+21
allow-arbitrary-strinsg-in-names patch by Marc Weber.
2011-07-13 * Allow a default value in attribute selection by writingEelco Dolstra2-0/+22
x.y.z or default (as originally proposed in https://mail.cs.uu.nl/pipermail/nix-dev/2009-September/002989.html). For instance, an expression like stdenv.lib.attrByPath ["features" "ckSched"] false args can now be written as args.features.ckSched or false
2011-07-06 * Test case.Eelco Dolstra2-0/+8
2011-01-14 * builtins.substring: if "start" is beyond the end of the string,Eelco Dolstra2-1/+3
return the empty string.
2010-10-24 * Keep attribute sets in sorted order to speed up attribute lookups.Eelco Dolstra1-1/+1
* Simplify the representation of attributes in the AST. * Change the behaviour of listToAttrs() in case of duplicate names.
2010-10-23 * Regression test for listToAttr's behaviour if an attribute nameEelco Dolstra2-2/+3
occurs multiple times.
2010-10-22 * Regression test for __overrides.Eelco Dolstra2-0/+10
2010-05-12 * Print attributes in sorted order.Eelco Dolstra1-1/+1
2010-05-12 * Implemented tryEval, the last missing primop in the fast-evalEelco Dolstra2-0/+6
branch. Also added a test for tryEval.