I want to change the Environment parameter of the systemd-logind service. This isn't covered by the logind options available in configuration.nix, so instead I've tried
systemd = {
services.systemd-logind.serviceConfig = {
environment = {
SYSTEMD_LOG_LEVEL = "debug";
};
};
};
However, when building I get an error, which I think is complaining that I'm trying to define systemd-logind in two places - once here and once in the internals of NixOS. The error looks like
$ nixos-rebuild switch --show-trace
building Nix...
building the system configuration...
error: while evaluating the attribute ‘buildCommand’ of the derivation ‘nixos-15.08pre67312.2c933ad’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/nixos/modules/system/activation/top-level.nix:102:7:
while evaluating the attribute ‘sources’ of the derivation ‘etc’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/nixos/modules/system/etc/etc.nix:12:5:
while evaluating anonymous function at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/nixos/modules/system/etc/etc.nix:20:20, called from undefined position:
while evaluating the attribute ‘source’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/attrsets.nix:134:44:
while evaluating anonymous function at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/modules.nix:74:45, called from /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/attrsets.nix:134:52:
while evaluating the attribute ‘value’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/modules.nix:287:9:
while evaluating the option `environment.etc.systemd/system.source':
while evaluating the attribute ‘mergedValue’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/modules.nix:314:5:
while evaluating ‘foldl’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/lists.nix:31:20, called from /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/modules.nix:314:19:
while evaluating ‘foldl'’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/lists.nix:34:16, called from /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/lists.nix:38:8:
while evaluating anonymous function at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/modules.nix:314:32, called from /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/lists.nix:37:14:
while evaluating ‘check’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/types.nix:106:15, called from /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/modules.nix:315:10:
while evaluating the attribute ‘buildCommand’ of the derivation ‘system-units’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/pkgs/build-support/trivial-builders.nix:10:14:
while evaluating the attribute ‘text’ of the derivation ‘unit-systemd-logind.service’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/pkgs/build-support/trivial-builders.nix:10:14:
while evaluating the attribute ‘text’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/attrsets.nix:134:44:
while evaluating anonymous function at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/modules.nix:74:45, called from /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/attrsets.nix:134:52:
while evaluating the attribute ‘value’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/modules.nix:287:9:
while evaluating the option `systemd.units.systemd-logind.service.text':
while evaluating the attribute ‘isDefined’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/modules.nix:319:5:
while evaluating ‘fold’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/lists.nix:20:19, called from /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/modules.nix:308:14:
while evaluating ‘fold'’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/lists.nix:23:15, called from /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/lists.nix:27:8:
while evaluating ‘filterOverrides’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/modules.nix:391:21, called from /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/modules.nix:303:18:
while evaluating ‘concatMap’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/lists.nix:62:18, called from /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/modules.nix:397:8:
while evaluating ‘concatMap’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/lists.nix:62:18, called from /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/modules.nix:298:17:
while evaluating anonymous function at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/modules.nix:298:28, called from undefined position:
while evaluating ‘dischargeProperties’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/modules.nix:361:25, called from /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/modules.nix:299:62:
while evaluating the attribute ‘value’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/modules.nix:199:48:
while evaluating the attribute ‘config.text’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/nixos/modules/system/boot/systemd.nix:295:7:
while evaluating ‘attrsToSection’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/nixos/modules/system/boot/systemd-lib.nix:90:20, called from /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/nixos/modules/system/boot/systemd.nix:309:13:
while evaluating ‘foldl’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/lists.nix:31:20, called from /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/nixos/modules/system/boot/systemd-lib.nix:91:5:
while evaluating ‘foldl'’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/lists.nix:34:16, called from /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/lists.nix:38:8:
while evaluating anonymous function at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/strings.nix:19:22, called from /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/lib/lists.nix:37:14:
while evaluating anonymous function at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/nixos/modules/system/boot/systemd-lib.nix:92:12, called from undefined position:
while evaluating ‘toOption’ at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/nixos/modules/system/boot/systemd-lib.nix:85:14, called from /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/nixos/modules/system/boot/systemd-lib.nix:93:21:
cannot coerce a set to a string, at /nix/store/m803kk24n58kkkzf2y26ws89jpx69czf-nixos-15.08pre67312.2c933ad/nixos/nixpkgs/nixos/modules/system/boot/systemd-lib.nix:88:10
In light of this, how can I set the Environment parameter in the systemd-logind unit file?
services.systemd-logind.environment.SYSTEMD_LOG_LEVEL, not services.systemd-logind.serviceConfig.environment.SYSTEMD_LOG_LEVEL
Related
I'm reading the source code of the main json11 header file.
It contains the following declaration:
template <class T, class = decltype(&T::to_json)>
Json(const T & t) : Json(t.to_json()) {}
I'm trying to find some documentation about this usage of decltype and class inside a template declaration but no success.
Does this construction/usage has a name in C++? Any good reference about it?
It's using SFINAE ("Substitution Failure Is Not An Error"), a common technique for advanced template stuff. In this case, it's used as a crude(1) test whether the type T has a function named to_json.
How it works: if the expression T::to_json is well-formed (there is something named to_json inside the type T), decltype(T::to_json) denotes a valid type and the constructor template can be used normally.
However, if T::to_json is ill-formed (i.e. if there is no to_json member inside T), it means substituting the template argument for T has failed. Per SFINAE, this is not an error of the entire program; it just means that the template is removed from further consideration (as if it was never part of the class).
The effect is thus that if type T has a member to_json, you can use an object of type T to initialise a Json object. If there is no such member in T, the constructor will not exist.
(1) I'm saying crude test because this only checks that T has such a member. It doesn't check that the member is a function which can be invoked without arguments and returns something another constructor of Json can accept. A tighter-fitting test might look something like this:
template <class T, class = std::enable_if_t<std::is_constructible<Json, decltype(std::declval<const T>().to_json())>::value>>
Json(const T & t) : Json(t.to_json()) {}
[Live example]
Looking at the C++11 Spec (n3485) section 5.3.7, note 3 says that the result of noexcept(expr) is false if:
... a potentially-evaluated call to a function... that does not have a
non-throwing exception-specification ... a potentially-evaluated
throw-expression ... a potentially-evaluated dynamic_cast ... a
potentially-evaluated typeid expression...
Does "potentially evaluated" mean that it drills down (not at all? a little?) to determine if one of the conditions can result in false?
I'm finding that (in test code, not an application) a function that claims to be noexcept but does, in fact, throw (even if in all cases) will still be considered to be noexcept. Am misunderstanding the spec or is the code in the following example all wrong?
double calculate(....) noexcept { throw "haha"; } // using simpsons::nelson
bool does_not_throw = noexcept(calculate());
According to Clang 3.3 this test says that calculate() does not throw.
All it's doing is checking what the expression does to see if the terms of the expression would throw an exception. It doesn't check the actual code that would potentially be called. If one of the expression terms is a function call that is not explicitly noexcept, then it is assumed to be able to throw exceptions.
Or, to put it another way, it checks to see if all of the functions being called in the expression are noexcept. That's all.
According to Clang 3.3 this test says that calculate() does not throw.
And that's true. Because calculate is defined as noexcept, if it tries to emit an exception, std::terminate will be called. Therefore, no exceptions will be emitted by the function.
I'm trying to see if there's a way to get a refference of an object which is outside the local (and global) scope, but who exists in memory.
Let's say in my program, i've instantiated an object whose reference is this:
{O:9*\PROGRAM=ZAVG_DELETE_THIS\CLASS=LCL_SMTH}
Far away after tons of calls, in a context where i wouldn't be able to access this object, could i do something like getting the reference of this object simply by knowing the above string?
I was looking into the cl_abap_*descr classes, but i haven't found a method that takes the 'program_name', 'class_name' and 'instance_number', to return the reference of an object.
I'm trying to do this for the purpose of debugging, not to build something that works.
[EDIT 1]:
I assumed that the o:9 string was required in order to get the reference of the object. As pointed out in the response of #mydoghasworms, this isn't the case. It seems that i only need the local name of the variable which holds the reference.
I hope I understand your question correctly, because I am not sure what you mean with "for the purpose of debugging", but here goes:
You can access the variables of another program that are loaded in the memory of the same session (I am pretty sure it does not need to be in the call stack) using:
ASSIGN ('(PROGRAM)VARIABLE') TO LV_LOCAL.
With reference variables, it becomes a bit more tricky, but here is an example that will help to demonstrate.
Here is our calling program that contains a reference variable LR_TEST which we want to access somewhere else. For the purpose of the demonstration, I make reference to a locally defined class (because that's what I gather from your question).
REPORT ZCALLER.
class lcl_test definition.
public section.
data: myval type i.
methods: my_meth exporting e_val type i.
endclass.
data: lr_test type ref to lcl_test.
CREATE OBJECT lr_test.
lr_test->MYVAL = 22.
perform call_me(zcallee).
class lcl_test implementation.
method my_meth.
* Export the attribute myval as param e_val.
e_val = myval.
endmethod.
endclass.
Here is the program in which we want to access a variable from the above program.
REPORT ZCALLEE.
form call_me.
field-symbols: <ref>.
data: ld_test type ref to object.
data: lv_val type i.
* Exhibit A: Gettinf a reference to a 'foreign' object instance
assign ('(ZCALLER)LR_TEST') to <ref>.
* <ref> now contains a reference to the class instance from the program
* ZCALLER (not very useful, except for passing around maybe)
* Exhibit B: Getting a public attribute from a 'foreign' class instance
assign ('(ZCALLER)LR_TEST->MYVAL') to <ref>.
* <ref> now contains the value of the attribute MYVAL
* Exhibit C: Getting a reference to an instance and calling a method
assign ('(ZCALLER)LR_TEST') to <ref>. "Again the class reference
if sy-subrc = 0. "Rule: Always check sy-subrc after assign before
"accessing a field symbol! (but you know that)
ld_test = <ref>. "Now we have a concrete handle
* Now we make a dynamic method call using our instance handle
CALL METHOD ld_test->('MY_METH')
IMPORTING
e_val = lv_val.
endif.
endform.
Consider the following code:
int main (void) {
int i = xyzzy();
return i;
}
int xyzzy (void) {
return 42;
}
Now, although the prototype for xyyzy is unkown at the point of use, this works in c89 mode because the default return type of a function that has no prototype is int so the implicit function prototype and actual function are compatible.
And, in fact, if you change the return type of the function to float, you get (as expected):
testprog.c:6: error: conflicting types for 'xyzzy'
testprog.c:2: error: previous implicit declaration of 'xyzzy' was here
because the implicit prototype and actual function no longer match.
The original code compiled with gcc --std=c89 --pedantic -Wall -Wextra only gives me the warning:
testprog.c: In function 'main':
testprog.c:2: warning: implicit declaration of function 'xyzzy'
which is expected, because c89 has this to say in 3.7.1 Function definitions:
extern int max(int a, int b) { ... }: Here extern is the storage-class specifier and int is the type specifier (each of which may be omitted as those are the defaults).
and in 3.3.2.2 Function calls:
If the expression that precedes the parenthesized argument list in a function call consists solely of an identifier, and if no declaration is visible for this identifier, the identifier is implicitly declared exactly as if, in the innermost block containing
the function call, the declaration extern int identifier(); appeared.
So the use of a function before declaring it definitely results in the default prototype being created.
However, both those phrases have been removed in c99 and we instead find in 6.5.2.2 Function calls (my bold):
If the expression that denotes the called function has type pointer to function returning an object type, the function call expression has the same type as that object type, and has the value determined as specified in 6.8.6.4. Otherwise, the function call has type void.
I understand it to mean that, if there's no declaration in view when you try to call a function, it's implicitly declared with a void return type.
Yet, when compiling with gcc --std=c99 --pedantic -Wall -Wextra, I get just the same warning about the implicit declaration.
Shouldn't c99 have declared that function implicitly as returning void? If it had, I would have expected a previous implicit declaration error similar to the one I got when I tried to redeclare it as returning float.
Is gcc broken here, or am I missing something in the standard?
You are reading the standard incorrectly. There's no such thing as implicit function declaration in C. It is removed from the language by C99.
GCC issues a warning when it sees an erroneous construct that looks like an implicit function declaration. This is OK as far as the standard is concerned. The standard requires a diagnostic here, and a warning is a diagnostic. You may use -Werror=implicit-function-declaration flag to GCC to turn this into an error.
This is covered in a note to 6.5.1 Primary expressions:
2 - An identifier is a primary expression, provided it has been declared as designating an
object (in which case it is an lvalue) or a function (in which case it is a function
designator). 79)
79) Thus, an undeclared identifier is a violation of the syntax.
A conforming implementation is required by 5.1.1.3 Diagnostics to produce a diagnostic message in response to the syntax violation of a function call expression involving an undeclared identifier as the expression denoting the called function. It is of course free to proceed to compile the program as if the identifier had been declared in the implicit-int C89 style.
The paragraph 6.5.2.2p5 must be read with reference to the constraint 6.5.2.2p1:
1 - The expression that denotes the called function shall have type pointer to function
returning void or returning an object type other than an array type.
So, if the "expression that denotes the called function" does not have type "pointer to function returning an object type", it must ipso facto (by the constraint 6.5.2.2p1) have type "pointer to function returning void", and it is this case which the "Otherwise" in 6.5.2.2p5 covers. That is, with my insertion in [square brackets]:
5 - If the expression that denotes the called function has type pointer to function returning an object type, the function call expression has the same type as that object type, and has the value determined as specified in 6.8.6.4. Otherwise, [i.e. if the expression that denotes the called function has type pointer to function returning void,] the function call has type void.
This is a case of special language being required for void as opposed to object types; is not a licence for the called function expression to be or contain an undeclared identifier.
I am trying to pass some Html constructed by using razor's #: operator to a helper method, but I can not figure out how to do this. The compiler states that the Razor expression is a lambda expression, but it does not say, what is this lambda expression like... no clues at all!
If I try to do this:
#(MyClass.MyMethod(new
{
Html = #:<div></div>
}
))
The error is as follows:
Cannot assign lambda expression to anonymous type property
If I try this instead, then it states it as being a lambda again:
#(MyClass.MyMethod(
#:<div></div>
))
If the MyMethod receives a string: i.e. public string MyMethod(string razorConstructedString)
, then the compiler says: Cannot convert lambda expression to type 'string' because it is not a delegate type.
The question is: what type should I declare MyMethod, so that it can receive the razor constructed parameter?
Thanks!
This is called an inline helper.
It's a Func<AnyType, HelperResult>.
You can call this delegate with a parameter, and the parameter will be accessible in the helper, named item.