diff --git a/lib/default.nix b/lib/default.nix index fe9a98a7d..f295eea78 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -5,7 +5,12 @@ rec { compileC = {main, localIncludes ? []}: stdenv.mkDerivation { name = "compile-c"; builder = ./compile-c.sh; - inherit main localIncludes; + localIncludes = + if localIncludes == "auto" then + import (findIncludes {main = toString main; hack = curTime;}) + else + localIncludes; + inherit main; }; /* @@ -16,10 +21,10 @@ rec { }; */ - findIncludes = {main}: stdenv.mkDerivation { + findIncludes = {main, hack}: stdenv.mkDerivation { name = "find-includes"; builder = ./find-includes.sh; - inherit main; + inherit main hack; }; link = {objects, programName ? "program"}: stdenv.mkDerivation { diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index af0ab913c..78b9c5572 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -28,6 +28,7 @@ EvalState::EvalState() addPrimOp0("true", primTrue); addPrimOp0("false", primFalse); addPrimOp0("null", primNull); + addPrimOp0("curTime", primCurTime); addPrimOp1("import", primImport); addPrimOp1("derivation", primDerivation); diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index aef4152b7..91636ea7b 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -1,3 +1,5 @@ +#include + #include "primops.hh" #include "normalise.hh" #include "globals.hh" @@ -321,3 +323,9 @@ Expr primIsNull(EvalState & state, Expr arg) ATMatcher m; return makeBool(atMatch(m, arg) >> "Null"); } + + +Expr primCurTime(EvalState & state) +{ + return ATmake("Int()", time(0)); +} diff --git a/src/libexpr/primops.hh b/src/libexpr/primops.hh index 6b9722dac..5af9cafc0 100644 --- a/src/libexpr/primops.hh +++ b/src/libexpr/primops.hh @@ -34,5 +34,10 @@ Expr primNull(EvalState & state); /* Determine whether the argument is the null value. */ Expr primIsNull(EvalState & state, Expr arg); +/* Return the current time. !!! hack, impure - although due to + memoization of evaluation results this should always yield the same + value for a particular run of the program. */ +Expr primCurTime(EvalState & state); + #endif /* !__PRIMOPS_H */