aboutsummaryrefslogtreecommitdiff
path: root/src
AgeCommit message (Collapse)Author
2014-01-06Merge branch 'dynamic-attrs-no-sugar' of github.com:shlevy/nixEelco Dolstra
2014-01-06wordingDomen Kožar
2013-12-31Don't use any syntactic sugar for dynamic attrsShea Levy
This doesn't change any functionality but moves some behavior out of the parser and into the evaluator in order to simplify the code. Signed-off-by: Shea Levy <shea@shealevy.com>
2013-12-31Fold dynamic binds handling into addAttrShea Levy
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-31Dynamic attrsShea Levy
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-31Add the ExprBuiltin Expr type to the ASTShea Levy
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-12-20DohEelco Dolstra
2013-12-20nix-env --set-flag: Barf if a selector doesn't match any installed packageEelco Dolstra
Fixes #184.
2013-12-20nix-shell: Don't warn about the lack of a GC rootEelco Dolstra
2013-12-20nix-shell: Handle --option correctlyEelco Dolstra
Fixes #181.
2013-12-10Bump language version for new storePath featureShea Levy
This will allow e.g. channel expressions to use builtins.storePath IFF it is safe to do so without knowing if the path is valid yet. Signed-off-by: Shea Levy <shea@shealevy.com>
2013-12-10builtins.storePath: Try to substitute the path if it is not yet validShea Levy
Signed-off-by: Shea Levy <shea@shealevy.com>
2013-12-10Garbage collector: Release locks on temporary root filesEelco Dolstra
This allows processes waiting for such locks to proceed during the trash deletion phase of the garbage collector.
2013-12-05Print a trace message if a build fails due to the platform being unknownEelco Dolstra
2013-11-22Include <cstring> for memsetEelco Dolstra
This should fix building on Illumos.
2013-11-19Check meta values and warn about bad onesEelco Dolstra
2013-11-19Generalise meta attributesEelco Dolstra
2013-11-19Shorter error messageEelco Dolstra
2013-11-19Drop support for user environment manifests in ATerm formatEelco Dolstra
2013-11-19nix-env -q: Add a --json flagEelco Dolstra
2013-11-19Refactor JSON outputEelco Dolstra
2013-11-19Add a toJSON primopEelco Dolstra
2013-11-18Add a primop unsafeGetAttrPos to return the position of an attributeEelco Dolstra
2013-11-18Add a symbol __curPos that expands to the current source locationEelco Dolstra
I.e. an attribute set { file = <string>; line = <int>; column = <int>; }.
2013-11-18Support quoted attribute names in -AEelco Dolstra
This is requires if you have attribute names with dots in them. So you can now say: $ nix-instantiate '<nixos>' -A 'config.systemd.units."postgresql.service".text' --eval-only Fixes #151.
2013-11-14Remove nix-setuid-helperEelco Dolstra
AFAIK, nobody uses it, it's not maintained, and it has no tests.
2013-11-12Make function calls show up in stack traces againEelco Dolstra
Note that adding --show-trace prevents functions calls from being tail-recursive, so an expression that evaluates without --show-trace may fail with a stack overflow if --show-trace is given.
2013-11-12Make function calls tail-recursiveEelco Dolstra
2013-11-12Make ifs and asserts tail-recursiveEelco Dolstra
The local Value object prevented g++ from making a tail call. Not clear why. In any case, not using a temporary makes g++ do the tail call.
2013-11-12Get rid of an intermediary on the stackEelco Dolstra
2013-10-28Fix building without a garbage collectorEelco Dolstra
http://hydra.nixos.org/build/6695350
2013-10-28Fix a segfault in genericClosureEelco Dolstra
It kept temporary data in STL containers that were not scanned by Boehm GC, so Nix programs using genericClosure could randomly crash if the garbage collector kicked in at a bad time. Also make it a bit more efficient by copying points to values rather than values.
2013-10-28Slightly optimize listToAttrsEelco Dolstra
2013-10-24Rename "attribute sets" to "sets"Eelco Dolstra
We don't have any other kind of sets so calling them attribute sets is unnecessarily verbose.
2013-10-24Remove unnecessary call to forceStringNoCtxEelco Dolstra
2013-10-24Add a typeOf primopEelco Dolstra
We already have some primops for determining the type of a value, such as isString, but they're incomplete: for instance, there is no isPath. Rather than adding more isBla functions, the generic typeOf function returns a string representing the type of the argument (e.g. "int").
2013-10-24Don't require NIX_SHOW_STATS for NIX_COUNT_CALLSEelco Dolstra
2013-10-23Memoize evalFile() lookups under both the original and resolved nameEelco Dolstra
Previously we only used the resolved name, causing repeated resolution (e.g. /dir to /dir/default.nix).
2013-10-22For auto roots, show the intermediate linkEelco Dolstra
I.e. "nix-store -q --roots" will now show (for example) /home/eelco/Dev/nixpkgs/result rather than /nix/var/nix/gcroots/auto/53222qsppi12s2hkap8dm2lg8xhhyk6v
2013-10-17Fold two stack trace messages in derivationsEelco Dolstra
Combined with the previous changes, stack traces involving derivations are now much less verbose, since something like while evaluating the builtin function `getAttr': while evaluating the builtin function `derivationStrict': while instantiating the derivation named `gtk+-2.24.20' at `/home/eelco/Dev/nixpkgs/pkgs/development/libraries/gtk+/2.x.nix:11:3': while evaluating the derivation attribute `propagatedNativeBuildInputs' at `/home/eelco/Dev/nixpkgs/pkgs/stdenv/generic/default.nix:78:17': while evaluating the attribute `outPath' at `/nix/store/212ngf4ph63mp6p1np2bapkfikpakfv7-nix-1.6/share/nix/corepkgs/derivation.nix:18:9': ... now reads while evaluating the attribute `propagatedNativeBuildInputs' of the derivation `gtk+-2.24.20' at `/home/eelco/Dev/nixpkgs/pkgs/development/libraries/gtk+/2.x.nix:11:3': ...
2013-10-17Don't show <nix/derivation.nix> in stack tracesEelco Dolstra
Messages like while evaluating the attribute `outPath' at `/nix/store/212ngf4ph63mp6p1np2bapkfikpakfv7-nix-1.6/share/nix/corepkgs/derivation.nix:18:9': are redundant, because Nix already shows that it's evaluating a derivation: while instantiating the derivation named `firefox-24.0' at `/home/eelco/Dev/nixpkgs/pkgs/applications/networking/browsers/firefox/default.nix:131:5': while evaluating the derivation attribute `nativeBuildInputs' at `/home/eelco/Dev/nixpkgs/pkgs/stdenv/generic/default.nix:76:17':
2013-10-17Ensure proper type checking/coercion of "${expr}"Eelco Dolstra
Now we only rewrite "${expr}" to expr if expr is a string literal.
2013-10-17Revert the behaviour of antiquoted paths to pre-Nix 1.6Eelco Dolstra
Commit 159e621d1a9c4391b53f3d822109c36931934698 accidentally changed the behaviour of antiquoted paths, e.g. "${/foo}/bar" used to evaluate to "/nix/store/<hash>-foo/bar" (where /foo gets copied to the store), but in Nix 1.6 it evaluates to "/foo/bar". This is inconsistent, since " ${/foo}/bar" evaluates to " /nix/store/<hash>-foo/bar". So revert to the old behaviour.
2013-10-16Retry all SQLite operationsEelco Dolstra
To deal with SQLITE_PROTOCOL, we also need to retry read-only operations.
2013-10-16Fix a race in registerFailedPath()Eelco Dolstra
Registering the path as failed can fail if another process does the same thing after the call to hasPathFailed(). This is extremely unlikely though.
2013-10-16Convenience macros for retrying a SQLite transactionEelco Dolstra
2013-10-16Don't wrap read-only queries in a transactionEelco Dolstra
There is no risk of getting an inconsistent result here: if the ID returned by queryValidPathId() is deleted from the database concurrently, subsequent queries involving that ID will simply fail (since IDs are never reused).
2013-10-16Print a distinct warning for SQLITE_PROTOCOLEelco Dolstra
2013-10-16Treat SQLITE_PROTOCOL as SQLITE_BUSYEelco Dolstra
In the Hydra build farm we fairly regularly get SQLITE_PROTOCOL errors (e.g., "querying path in database: locking protocol"). The docs for this error code say that it "is returned if some other process is messing with file locks and has violated the file locking protocol that SQLite uses on its rollback journal files." However, the SQLite source code reveals that this error can also occur under high load: if( cnt>5 ){ int nDelay = 1; /* Pause time in microseconds */ if( cnt>100 ){ VVA_ONLY( pWal->lockError = 1; ) return SQLITE_PROTOCOL; } if( cnt>=10 ) nDelay = (cnt-9)*238; /* Max delay 21ms. Total delay 996ms */ sqlite3OsSleep(pWal->pVfs, nDelay); } i.e. if certain locks cannot be not acquired, SQLite will retry a number of times before giving up and returing SQLITE_PROTOCOL. The comments say: Circumstances that cause a RETRY should only last for the briefest instances of time. No I/O or other system calls are done while the locks are held, so the locks should not be held for very long. But if we are unlucky, another process that is holding a lock might get paged out or take a page-fault that is time-consuming to resolve, during the few nanoseconds that it is holding the lock. In that case, it might take longer than normal for the lock to free. ... The total delay time before giving up is less than 1 second. On a heavily loaded machine like lucifer (the main Hydra server), which often has dozens of processes waiting for I/O, it seems to me that a page fault could easily take more than a second to resolve. So, let's treat SQLITE_PROTOCOL as SQLITE_BUSY and retry the transaction. Issue NixOS/hydra#14.
2013-10-08printStats(): Print the size of the symbol table in bytesEelco Dolstra