diff options
author | Alyssa Ross <hi@alyssa.is> | 2022-05-31 09:59:33 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2022-05-31 09:59:57 +0000 |
commit | 9ff36293d1e428cd7bf03e8d4b03611b6d361c28 (patch) | |
tree | 1ab51a42b868c55b83f6ccdb80371b9888739dd9 /nixos/doc/manual/from_md/development/option-def.section.xml | |
parent | 1c4fcd0d4b0541e674ee56ace1053e23e562cc80 (diff) | |
parent | ddc3c396a51918043bb0faa6f676abd9562be62c (diff) | |
download | nixpkgs-archive.tar nixpkgs-archive.tar.gz nixpkgs-archive.tar.bz2 nixpkgs-archive.tar.lz nixpkgs-archive.tar.xz nixpkgs-archive.tar.zst nixpkgs-archive.zip |
Last good Nixpkgs for Weston+nouveau? archive
I came this commit hash to terwiz[m] on IRC, who is trying to figure out what the last version of Spectrum that worked on their NUC with Nvidia graphics is.
Diffstat (limited to 'nixos/doc/manual/from_md/development/option-def.section.xml')
-rw-r--r-- | nixos/doc/manual/from_md/development/option-def.section.xml | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/nixos/doc/manual/from_md/development/option-def.section.xml b/nixos/doc/manual/from_md/development/option-def.section.xml new file mode 100644 index 00000000000..8c9ef181aff --- /dev/null +++ b/nixos/doc/manual/from_md/development/option-def.section.xml @@ -0,0 +1,104 @@ +<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-option-definitions"> + <title>Option Definitions</title> + <para> + Option definitions are generally straight-forward bindings of values + to option names, like + </para> + <programlisting language="bash"> +config = { + services.httpd.enable = true; +}; +</programlisting> + <para> + However, sometimes you need to wrap an option definition or set of + option definitions in a <emphasis>property</emphasis> to achieve + certain effects: + </para> + <section xml:id="sec-option-definitions-delaying-conditionals"> + <title>Delaying Conditionals</title> + <para> + If a set of option definitions is conditional on the value of + another option, you may need to use <literal>mkIf</literal>. + Consider, for instance: + </para> + <programlisting language="bash"> +config = if config.services.httpd.enable then { + environment.systemPackages = [ ... ]; + ... +} else {}; +</programlisting> + <para> + This definition will cause Nix to fail with an <quote>infinite + recursion</quote> error. Why? Because the value of + <literal>config.services.httpd.enable</literal> depends on the + value being constructed here. After all, you could also write the + clearly circular and contradictory: + </para> + <programlisting language="bash"> +config = if config.services.httpd.enable then { + services.httpd.enable = false; +} else { + services.httpd.enable = true; +}; +</programlisting> + <para> + The solution is to write: + </para> + <programlisting language="bash"> +config = mkIf config.services.httpd.enable { + environment.systemPackages = [ ... ]; + ... +}; +</programlisting> + <para> + The special function <literal>mkIf</literal> causes the evaluation + of the conditional to be <quote>pushed down</quote> into the + individual definitions, as if you had written: + </para> + <programlisting language="bash"> +config = { + environment.systemPackages = if config.services.httpd.enable then [ ... ] else []; + ... +}; +</programlisting> + </section> + <section xml:id="sec-option-definitions-setting-priorities"> + <title>Setting Priorities</title> + <para> + A module can override the definitions of an option in other + modules by setting a <emphasis>priority</emphasis>. All option + definitions that do not have the lowest priority value are + discarded. By default, option definitions have priority 1000. You + can specify an explicit priority by using + <literal>mkOverride</literal>, e.g. + </para> + <programlisting language="bash"> +services.openssh.enable = mkOverride 10 false; +</programlisting> + <para> + This definition causes all other definitions with priorities above + 10 to be discarded. The function <literal>mkForce</literal> is + equal to <literal>mkOverride 50</literal>. + </para> + </section> + <section xml:id="sec-option-definitions-merging"> + <title>Merging Configurations</title> + <para> + In conjunction with <literal>mkIf</literal>, it is sometimes + useful for a module to return multiple sets of option definitions, + to be merged together as if they were declared in separate + modules. This can be done using <literal>mkMerge</literal>: + </para> + <programlisting language="bash"> +config = mkMerge + [ # Unconditional stuff. + { environment.systemPackages = [ ... ]; + } + # Conditional stuff. + (mkIf config.services.bla.enable { + environment.systemPackages = [ ... ]; + }) + ]; +</programlisting> + </section> +</section> |