[Nix-dev] Nixos: mkOverride
Nicolas Pierron
nicolas.b.pierron at gmail.com
Sat Feb 28 19:47:32 CET 2009
Hi Nixers,
I have introduced a new concept which behave as mkIf in order to
Override option definitions. The reason was that Mickael Raskin ask
me to do so because he has a problem with liveDVD expressions. I
think the following example may give you all the detail about how to
use it and what it does:
# nixos/upstart-jobs/foo.nix
# This file is implicitly imported.
# default priority is 100
{
services = {
showManual = {
enable = true;
tty = 7;
};
};
}
# /etc/nixos/default_config.nix
mkOverride 70
{ # option mask
hardware = {
pcmcia = {}; # Override all options contained in pcmcia.
};
}
{
hardware = {
pcmcia = {
enable = true;
};
};
}
# /etc/nixos/configuration.nix
mkOverride 80
{ # option mask
hardware = {
pcmcia = {}; # Override all options contained in pcmcia.
};
services = {
showManual = {};
};
}
{
require = [
(import ./default_config.nix)
];
hardware = {
pcmcia = {
enable = true;
};
};
services = {
showManual = {
enable = false;
};
};
}
$ nix-instantiate --xml --strict --eval-only -A config nixos/default.nix
...
<attr name="pcmcia">
<attrs>
<attr name="enable">
<bool value="true" /> # coming from
/etc/nixos/default_config.nix (priority 70)
</attr>
</attrs>
</attr>
...
<attr name="showManual">
<attrs>
<attr name="enable">
<bool value="false" /> # coming from
/etc/nixos/configuration.nix (priority 80)
</attr>
# tty is not overriden because no other definition exists with a
lower priority number.
<attr name="tty">
<int value="7" /> # coming from
/etc/nixos/nixos/upstart-jobs/foo.nix (priority 100)
</attr>
</attrs>
</attr>
...
Priorities are higher it the priority number is lesser than the other.
All higher priorities values are merged together and lower priority
values are ignored (enable options). The template is used to define
which (attribute/attribute set) have a higher priority because you may
not want to override extraPackages when you just want to add your
favorite shell in it. If an attribute with a higher priority is not
defined, then it keeps lower priority values (tty option).
--
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