about summary refs log tree commit diff
path: root/src/libexpr/primops.cc
AgeCommit message (Collapse)AuthorFilesLines
2014-12-10 builtins.readFile: realise context associated with the pathShea Levy1-2/+6
2014-12-02 Allow external code using libnixexpr to add typesShea Levy1-0/+3
Code that links to libnixexpr (e.g. plugins loaded with importNative, or nix-exec) may want to provide custom value types and operations on values of those types. For example, nix-exec is currently using sets where a custom IO value type would be more appropriate. This commit provides a generic hook for such types in the form of tExternal and the ExternalBase virtual class, which contains all functions necessary for libnixexpr's type-polymorphic functions (e.g. `showType`) to be implemented.
2014-11-25 Add a primop for regular expression pattern matchingEelco Dolstra1-1/+29
The function ‘builtins.match’ takes a POSIX extended regular expression and an arbitrary string. It returns ‘null’ if the string does not match the regular expression. Otherwise, it returns a list containing substring matches corresponding to parenthesis groups in the regex. The regex must match the entire string (i.e. there is an implied "^<pat>$" around the regex). For example: match "foo" "foobar" => null match "foo" "foo" => [] match "f(o+)(.*)" "foooobar" => ["oooo" "bar"] match "(.*/)?([^/]*)" "/dir/file.nix" => ["/dir/" "file.nix"] match "(.*/)?([^/]*)" "file.nix" => [null "file.nix"] The following example finds all regular files with extension .nix or .patch underneath the current directory: let findFiles = pat: dir: concatLists (mapAttrsToList (name: type: if type == "directory" then findFiles pat (dir + "/" + name) else if type == "regular" && match pat name != null then [(dir + "/" + name)] else []) (readDir dir)); in findFiles ".*\\.(nix|patch)" (toString ./.)
2014-11-25 forceString(): Accept pos argumentEelco Dolstra1-2/+2
2014-11-20 import derivation: cleanupShea Levy1-8/+11
Before this there was a bug where a `find` was being called on a not-yet-sorted set. The code was just a mess before anyway, so I cleaned it up while fixing it.
2014-11-15 realiseContext: Handle all context typesShea Levy1-2/+2
Avoids an assertion
2014-10-17 Export realiseContext in libnixexprShea Levy1-9/+3
Useful for importNative plugins
2014-10-04 Add primop ‘catAttrs’Eelco Dolstra1-0/+30
2014-10-04 Add primop ‘attrValues’Eelco Dolstra1-1/+23
2014-10-04 TweakEelco Dolstra1-1/+1
2014-10-03 Remove some duplicate codeEelco Dolstra1-15/+8
2014-10-03 Add readDir primopShea Levy1-0/+37
2014-09-23 Add missing staticEelco Dolstra1-2/+2
2014-09-22 Don't evaluate inside a "throw"Eelco Dolstra1-3/+4
Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41174. This caused hydra-eval-jobs to ignore SIGINT.
2014-09-22 Add ‘deepSeq’ primopEelco Dolstra1-0/+11
Note that unlike ‘lib.deepSeq’ in Nixpkgs, this handles cycles.
2014-09-22 Add ‘seq’ primopEelco Dolstra1-0/+12
2014-09-22 Add a function ‘valueSize’Eelco Dolstra1-0/+10
It returns the size of value, including all other values and environments reachable from it. It is intended for debugging memory consumption issues.
2014-09-19 attrNames: Don't allocate duplicates of the symbolsEelco Dolstra1-6/+4
2014-09-19 Fix off-by-oneEelco Dolstra1-1/+1
2014-09-17 Add some instrumentation for debugging GC leaksEelco Dolstra1-0/+27
2014-08-20 Use proper quotes everywhereEelco Dolstra1-40/+40
2014-07-30 Rename nixPath to __nixPathEelco Dolstra1-2/+2
The name ‘nixPath’ breaks existing code.
2014-07-09 Fix compilation error on some versions of GCCEelco Dolstra1-0/+1
src/libexpr/primops.cc:42:8: error: looser throw specifier for 'virtual nix::InvalidPathError::~InvalidPathError()' src/libexpr/nixexpr.hh:12:1: error: overriding 'virtual nix::EvalError::~EvalError() noexcept (true)' http://hydra.nixos.org/build/12385750
2014-07-04 Add builtin function ‘fromJSON’Eelco Dolstra1-0/+10
Fixes #294.
2014-06-24 Only add the importNative primop if the ↵Shea Levy1-1/+2
allow-arbitrary-code-during-evaluation option is true (default false)
2014-06-17 Add importNative primopShea Levy1-0/+42
This can be used to import a dynamic shared object and return an arbitrary value, including new primops. This can be used both to test new primops without having to recompile nix every time, and to build specialized primops that probably don't belong upstream (e.g. a function that calls out to gpg to decrypt a nixops secret as-needed). The imported function should initialize the Value & as needed. A single import can define multiple values by creating an attrset or list, of course. An example initialization function might look like: extern "C" void initialize(nix::EvalState & state, nix::Value & v) { v.type = nix::tPrimOp; v.primOp = NEW nix::PrimOp(myFun, 1, state.symbols.create("myFun")); } Then `builtins.importNative ./example.so "initialize"` will evaluate to the primop defined in the myFun function.
2014-06-12 Drop ImportError and FindErrorEelco Dolstra1-4/+0
We're not catching these anywhere.
2014-06-12 findFile: Realise the context of the path attributesShea Levy1-18/+44
2014-06-12 Share code between scopedImport and importShea Levy1-42/+44
In addition to reducing duplication, this fixes both import from derivation and import of derivation for scopedImport
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 Sort nixPath attributesEelco Dolstra1-0/+1
2014-05-26 Make the Nix search path declarativeEelco Dolstra1-0/+32
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 Add constant ‘nixPath’Eelco Dolstra1-0/+11
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 Dolstra1-0/+25
‘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 Shut up some signedness warningsEelco Dolstra1-2/+2
2014-04-08 If a .drv cannot be parsed, show its pathEelco Dolstra1-1/+1
Otherwise you just get ‘expected string `Derive(['’ which isn't very helpful.
2014-04-04 Show position info in Boolean operationsEelco Dolstra1-1/+1
2014-04-04 Show position info in string concatenation / addition errorsEelco Dolstra1-18/+18
2014-04-04 forceString: Show position infoEelco Dolstra1-12/+12
2014-04-04 forceAttrs: Show position infoEelco Dolstra1-12/+12
2014-04-04 forceList: Show position infoEelco Dolstra1-15/+15
2014-04-04 forceInt: Show position infoEelco Dolstra1-8/+8
2014-04-04 Pass position information to primop callsEelco Dolstra1-90/+90
For example: error: `tail' called on an empty list, at /home/eelco/Dev/nixpkgs/pkgs/applications/misc/hello/ex-2/default.nix:13:7
2014-04-04 Include position info in function applicationEelco Dolstra1-3/+3
This allows error messages like: error: the anonymous function at `/etc/nixos/configuration.nix:1:1' called without required argument `foo', at `/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:77:59'
2014-01-21 Merge branch 'master' into makeEelco Dolstra1-3/+3
Conflicts: src/libexpr/eval.cc
2013-12-10 Bump language version for new storePath featureShea Levy1-1/+1
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-10 builtins.storePath: Try to substitute the path if it is not yet validShea Levy1-2/+2
Signed-off-by: Shea Levy <shea@shealevy.com>
2013-11-23 Implement basic ‘make install’Eelco Dolstra1-0/+1
2013-11-19 Shorter error messageEelco Dolstra1-2/+1
2013-11-19 Add a toJSON primopEelco Dolstra1-0/+14