[Nix-dev] mkDefaultValue

Nicolas Pierron nicolas.b.pierron at gmail.com
Fri Jul 10 13:42:57 CEST 2009


Hi nixers,

Today I've made a patch on my computer configuration which highlight
what we often want to do.  A while ago I've implemented a small filter
similar to mkIf which allow you to add a priority number to each
definition (mkOverride).  Recently (rev 16304), I have made a small
modification on this mkOverride which entirely change our way of
thinking of such priorities.

The first implementation of mkOverride was made to override previous
definitions by higher priority definitions.  All definitions of higher
priorities are kept together and merge with the merge function where
lower priority definitions are dropped.  I've remarked that mkOverride
syntax is not what you want to add inside your
/etc/nixos/configuration.nix because this is not common.  In my case,
I arose with an ACPI issue with the kernel 2.6.28 and I wanted to use
a default kernel version which is not the default value defined in the
option declaration and still being able to override it in my
/etc/nixos/configuration.nix.  I found a nice solution which is to
allow mkOverride to work with lower priorities than the default
priority.

All definitions have an implicit priority field which is set to 100.
Before rev 16304, only higher priories were accepted (below 100).
Now, you can define priorities which are lower than the default
priority (above 100).  This means if someone defines the same
attribute without any mkOverride, the value will take precedence over
the value defined with a lower priority.  A small sugar over the
mkOverride function is called mkDefaultValue.

On Fri, Jul 10, 2009 at 13:11, Nicolas
Pierron<nicolas.b.pierron at gmail.com> wrote:
> Log:
> Compaq presario 2144EA:
> - Set a default kernel version (2.6.25)
> - Activate the PCMCIA by default.
>
> Changes:
>
> Modified: configurations/trunk/computer/compaq/presario/2144EA/default.nix
> ===================================================================
> --- configurations/trunk/computer/compaq/presario/2144EA/default.nix    2009-07-10 11:11:10 UTC (rev 16308)
> +++ configurations/trunk/computer/compaq/presario/2144EA/default.nix    2009-07-10 11:11:15 UTC (rev 16309)
> @@ -1,16 +1,29 @@
>  {pkgs, config, ...}:
>
> +with { inherit (pkgs.lib) mkDefaultValue; };
> +
>  {
>   boot = {
> -    grubDevice = "/dev/hda";
> +    grubDevice = mkDefaultValue "/dev/hda";
>
> +    # 2.6.28 has some problems to detect ACPI configuration.
> +    kernelPackages = mkDefaultValue pkgs.kernelPackages_2_6_25;
> +
>
> @@ -29,7 +41,7 @@
>
>   hardware = {
>     pcmcia = {
> -      enable = true;
> +      enable = mkDefaultValue true;
>       config = ./etc/pcmcia/config.opts;
>     };
>   };

So if my /etc/nixos/configuration.nix were:

{
  require = [
    /etc/nixos/configurations/computer/compaq/presario/2144EA/default.nix
  ];

  ...

  hardware.pcmcia.enable = false;
}

Then this will disable the PCMCIA which is (by default) enabled by the
computer configuration.

-- 
Nicolas Pierron
http://www.linkedin.com/in/nicolasbpierron
The Hitchhiker's Guide to the Galaxy - What do you get if you multiply
six by nine?



More information about the nix-dev mailing list