-
-
Notifications
You must be signed in to change notification settings - Fork 13.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc: explain assert condition -> package != null; #41650
Comments
|
This comment has been minimized.
This comment has been minimized.
OK. Now I know that the whole tail expression after assert in those cases is a resulting expression if the whole OK, thank you. |
They are both are { enableFeature ? false, package ? null
}:
assert enableFeature -> package !=null;
stdenv.mkDerivation rec {} is: if (if enableFeature then package !=null else True)
then stdenv.mkDerivation rec {}
else False |
There is no such thing as You could compare the if (if enableFeature then package !=null else True)
then stdenv.mkDerivation rec {}
else error "assertion failed" |
Yes. This is in a more strict terms. |
So all this volume (first round of explanations was in a chatroom), seems to indicate the need to explain example of this often used, but strangely looking case of Assumption that people would/should deduce it themselves with full understanding, is a very long shot. |
Well the |
I read it, it was more than a half year ago. assert e1; e2 #;? and assert in real life looks like this: { enableFeature ? false, package ? null
}:
assert enableFeature -> package !=null; I deliberately over exaggerate. Asked maybe to add live example. If you think this is obvious, ok. |
Issue description
There are a plethora of:
And this assertion broke my head for a long time. Major part of the year.
I know some Haskell.
I was a Haskell/NixPkgs/Nix/NixOps DevOps, contributed to some number of Nixpkgs, become a maintainer of some packages.
I dig into this question a couple of times, and extracted sort-of answer.
I found Dolstra explanation somewhere on GitHub couple of times. That is hard to find, even when you specifically look for it.
But. I still didn't understood that assertion fully.
Until I admitted dumbness and asked in the chat room.
->
can be a sign of a function, a sign of a binding, and a sign of implication.But because of what is the resulting expression:
package !=null;
- it is not a result, it does not evaluate to anything, it is not used. I thought that->
is probably or a binding, or a function sign, but it behaved as an assertion, which broke my head completely.Please write something in lines:
There are number of option->dependency, option->option checks in the code.
->
is the sign of implicationSo assertion can be read as (if enableFeature == True then test that package !=null).
This
accert
structure checks that when condition is true package must be used in the expression.And if, after binding values to variables, expression
package !=null
evaluates toFalse
, so all thatassert
expression evaluates toFalse
, which puts False in the global scope on that Nix (package) expression, which as result throws Error, so evaluation/build stops.That is how that
accert
structure guides the options conditions.If that
accert
is one - it is probably useless, as it tests the already working code that has logical expressions (optional
) in it and that evaluates normally.Number of
accert
s are needed to sort-out collisions between options of the package, for example when one option requires package to be included, and other option - to be excluded, and the third...And moreover.
Manual shows:
Which is the same as
Which multiplies confusion, that
->
must be some special sign for some special case ofaccert
.Steps to reproduce
Read the Nixpkgs code.
The text was updated successfully, but these errors were encountered: