[Nix-dev] Re: NixOS: New scheme
Nicolas Pierron
nicolas.b.pierron at gmail.com
Wed Jan 7 15:28:07 CET 2009
Hi,
On Wed, Jan 7, 2009 at 15:00, Ludovic Courtès <ludo at gnu.org> wrote:
> "Nicolas Pierron" <nicolas.b.pierron at gmail.com> writes:
>> http://nicolas.b.pierron.free.fr/nixos/manual.html#id2476872
>
> I looked into it again and I find the `mkIf' thing non obvious:
>
> This line is used to declare a special IF statement. If you had put a
> usual IF statement here, with the same condition, then you will get an
> infinite loop. The reason is that your condition ask for the value of
> the option config.services.locate.enable but in order to get this
> value you have to evaluate all configuration sets including the
> configuration set contained inside your file.
>
> To remove this extra complexity, mkIf has been introduced to get rid
> of possible infinite loop and to factor your writing.
>
> Given the description, I'd have called it `delayedIf', but OTOH, in a
> lazily-evaluated language, everything is "delayed".
No mkIf produce some kind of if-statement which can be put move inside
an attribute set by the mean of the function named delayIf.
> I expect the need
> for special conditional constructs would make it harder to write Upstart
> jobs.
If fact, this construct is more general. The idea is only to factor
conditions on top of your configuration. Even, if this puts
configuration files a bit away from the original syntax and even if
this may be confusing for new users, this feature is really useful.
It is useful because it factor the condition (maintainable), it
introduces empty options if the condition is not verified (sugar), it
allow you to have multiple then-else statements for one condition and
all of that without copying every time the same piece of code (error
prone).
--
Nicolas Pierron
http://www.linkedin.com/in/nicolasbpierron
- If you are doing something twice then you should try to do it once.
More information about the nix-dev
mailing list