diff options
Diffstat (limited to 'nixos/doc/manual/from_md/development')
13 files changed, 81 insertions, 69 deletions
diff --git a/nixos/doc/manual/from_md/development/activation-script.section.xml b/nixos/doc/manual/from_md/development/activation-script.section.xml index 8672ab8afe54..429b45c93def 100644 --- a/nixos/doc/manual/from_md/development/activation-script.section.xml +++ b/nixos/doc/manual/from_md/development/activation-script.section.xml @@ -22,7 +22,7 @@ these dependencies into account and order the snippets accordingly. As a simple example: </para> - <programlisting language="bash"> + <programlisting language="nix"> system.activationScripts.my-activation-script = { deps = [ "etc" ]; # supportsDryActivation = true; diff --git a/nixos/doc/manual/from_md/development/assertions.section.xml b/nixos/doc/manual/from_md/development/assertions.section.xml index 0844d484d60f..13f04d5d1883 100644 --- a/nixos/doc/manual/from_md/development/assertions.section.xml +++ b/nixos/doc/manual/from_md/development/assertions.section.xml @@ -18,7 +18,7 @@ <para> This is an example of using <literal>warnings</literal>. </para> - <programlisting language="bash"> + <programlisting language="nix"> { config, lib, ... }: { config = lib.mkIf config.services.foo.enable { @@ -42,7 +42,7 @@ assertion is useful to prevent such a broken system from being built. </para> - <programlisting language="bash"> + <programlisting language="nix"> { config, lib, ... }: { config = lib.mkIf config.services.syslogd.enable { diff --git a/nixos/doc/manual/from_md/development/bootspec.chapter.xml b/nixos/doc/manual/from_md/development/bootspec.chapter.xml index acf8ca76bf5c..9ecbe1d1beed 100644 --- a/nixos/doc/manual/from_md/development/bootspec.chapter.xml +++ b/nixos/doc/manual/from_md/development/bootspec.chapter.xml @@ -43,7 +43,7 @@ <literal>/etc/os-release</literal> in order to bake it into a unified kernel image: </para> - <programlisting language="bash"> + <programlisting language="nix"> { config, lib, ... }: { boot.bootspec.extensions = { "org.secureboot.osRelease" = config.environment.etc."os-release".source; diff --git a/nixos/doc/manual/from_md/development/freeform-modules.section.xml b/nixos/doc/manual/from_md/development/freeform-modules.section.xml index 86a9cf3140d8..c51bc76ff966 100644 --- a/nixos/doc/manual/from_md/development/freeform-modules.section.xml +++ b/nixos/doc/manual/from_md/development/freeform-modules.section.xml @@ -30,7 +30,7 @@ type-checked <literal>settings</literal> attribute</link> for a more complete example. </para> - <programlisting language="bash"> + <programlisting language="nix"> { lib, config, ... }: { options.settings = lib.mkOption { @@ -52,7 +52,7 @@ <para> And the following shows what such a module then allows </para> - <programlisting language="bash"> + <programlisting language="nix"> { # Not a declared option, but the freeform type allows this settings.logLevel = "debug"; @@ -72,7 +72,7 @@ Freeform attributes cannot depend on other attributes of the same set without infinite recursion: </para> - <programlisting language="bash"> + <programlisting language="nix"> { # This throws infinite recursion encountered settings.logLevel = lib.mkIf (config.settings.port == 80) "debug"; diff --git a/nixos/doc/manual/from_md/development/importing-modules.section.xml b/nixos/doc/manual/from_md/development/importing-modules.section.xml index cb04dde67c83..96e5e1bb16b8 100644 --- a/nixos/doc/manual/from_md/development/importing-modules.section.xml +++ b/nixos/doc/manual/from_md/development/importing-modules.section.xml @@ -4,7 +4,7 @@ Sometimes NixOS modules need to be used in configuration but exist outside of Nixpkgs. These modules can be imported: </para> - <programlisting language="bash"> + <programlisting language="nix"> { config, lib, pkgs, ... }: { @@ -23,18 +23,18 @@ Nixpkgs NixOS modules. Like any NixOS module, this module can import additional modules: </para> - <programlisting language="bash"> + <programlisting language="nix"> # ./module-list/default.nix [ ./example-module1 ./example-module2 ] </programlisting> - <programlisting language="bash"> + <programlisting language="nix"> # ./extra-module/default.nix { imports = import ./module-list.nix; } </programlisting> - <programlisting language="bash"> + <programlisting language="nix"> # NIXOS_EXTRA_MODULE_PATH=/absolute/path/to/extra-module { config, lib, pkgs, ... }: diff --git a/nixos/doc/manual/from_md/development/meta-attributes.section.xml b/nixos/doc/manual/from_md/development/meta-attributes.section.xml index 1eb6e0f30368..9cc58afa1fdd 100644 --- a/nixos/doc/manual/from_md/development/meta-attributes.section.xml +++ b/nixos/doc/manual/from_md/development/meta-attributes.section.xml @@ -15,7 +15,7 @@ Each of the meta-attributes must be defined at most once per module file. </para> - <programlisting language="bash"> + <programlisting language="nix"> { config, lib, pkgs, ... }: { options = { diff --git a/nixos/doc/manual/from_md/development/option-declarations.section.xml b/nixos/doc/manual/from_md/development/option-declarations.section.xml index 602b7623c07f..2e6a12d53095 100644 --- a/nixos/doc/manual/from_md/development/option-declarations.section.xml +++ b/nixos/doc/manual/from_md/development/option-declarations.section.xml @@ -6,7 +6,7 @@ hasn’t been declared in any module. An option declaration generally looks like this: </para> - <programlisting language="bash"> + <programlisting language="nix"> options = { name = mkOption { type = type specification; @@ -127,7 +127,7 @@ options = { For example: </para> <anchor xml:id="ex-options-declarations-util-mkEnableOption-magic" /> - <programlisting language="bash"> + <programlisting language="nix"> lib.mkEnableOption "magic" # is like lib.mkOption { @@ -142,7 +142,7 @@ lib.mkOption { <para> Usage: </para> - <programlisting language="bash"> + <programlisting language="nix"> mkPackageOption pkgs "name" { default = [ "path" "in" "pkgs" ]; example = "literal example"; } </programlisting> <para> @@ -177,7 +177,7 @@ mkPackageOption pkgs "name" { default = [ "path" "in&qu Examples: </para> <anchor xml:id="ex-options-declarations-util-mkPackageOption-hello" /> - <programlisting language="bash"> + <programlisting language="nix"> lib.mkPackageOption pkgs "hello" { } # is like lib.mkOption { @@ -188,7 +188,7 @@ lib.mkOption { } </programlisting> <anchor xml:id="ex-options-declarations-util-mkPackageOption-ghc" /> - <programlisting language="bash"> + <programlisting language="nix"> lib.mkPackageOption pkgs "GHC" { default = [ "ghc" ]; example = "pkgs.haskell.packages.ghc92.ghc.withPackages (hkgs: [ hkgs.primes ])"; @@ -287,7 +287,7 @@ lib.mkOption { <emphasis role="strong">Example: Extensible type placeholder in the service module</emphasis> </para> - <programlisting language="bash"> + <programlisting language="nix"> services.xserver.displayManager.enable = mkOption { description = "Display manager to use"; type = with types; nullOr (enum [ ]); @@ -299,7 +299,7 @@ services.xserver.displayManager.enable = mkOption { <literal>services.xserver.displayManager.enable</literal> in the <literal>gdm</literal> module</emphasis> </para> - <programlisting language="bash"> + <programlisting language="nix"> services.xserver.displayManager.enable = mkOption { type = with types; nullOr (enum [ "gdm" ]); }; @@ -310,7 +310,7 @@ services.xserver.displayManager.enable = mkOption { <literal>services.xserver.displayManager.enable</literal> in the <literal>sddm</literal> module</emphasis> </para> - <programlisting language="bash"> + <programlisting language="nix"> services.xserver.displayManager.enable = mkOption { type = with types; nullOr (enum [ "sddm" ]); }; diff --git a/nixos/doc/manual/from_md/development/option-def.section.xml b/nixos/doc/manual/from_md/development/option-def.section.xml index 3c1a979e70f3..87b290ec39c6 100644 --- a/nixos/doc/manual/from_md/development/option-def.section.xml +++ b/nixos/doc/manual/from_md/development/option-def.section.xml @@ -4,7 +4,7 @@ Option definitions are generally straight-forward bindings of values to option names, like </para> - <programlisting language="bash"> + <programlisting language="nix"> config = { services.httpd.enable = true; }; @@ -21,7 +21,7 @@ config = { another option, you may need to use <literal>mkIf</literal>. Consider, for instance: </para> - <programlisting language="bash"> + <programlisting language="nix"> config = if config.services.httpd.enable then { environment.systemPackages = [ ... ]; ... @@ -34,7 +34,7 @@ config = if config.services.httpd.enable then { value being constructed here. After all, you could also write the clearly circular and contradictory: </para> - <programlisting language="bash"> + <programlisting language="nix"> config = if config.services.httpd.enable then { services.httpd.enable = false; } else { @@ -44,7 +44,7 @@ config = if config.services.httpd.enable then { <para> The solution is to write: </para> - <programlisting language="bash"> + <programlisting language="nix"> config = mkIf config.services.httpd.enable { environment.systemPackages = [ ... ]; ... @@ -55,7 +55,7 @@ config = mkIf config.services.httpd.enable { of the conditional to be <quote>pushed down</quote> into the individual definitions, as if you had written: </para> - <programlisting language="bash"> + <programlisting language="nix"> config = { environment.systemPackages = if config.services.httpd.enable then [ ... ] else []; ... @@ -72,7 +72,7 @@ config = { option defaults have priority 1500. You can specify an explicit priority by using <literal>mkOverride</literal>, e.g. </para> - <programlisting language="bash"> + <programlisting language="nix"> services.openssh.enable = mkOverride 10 false; </programlisting> <para> @@ -94,7 +94,7 @@ services.openssh.enable = mkOverride 10 false; <literal>mkOrder 500</literal> and <literal>mkOrder 1500</literal>, respectively. As an example, </para> - <programlisting language="bash"> + <programlisting language="nix"> hardware.firmware = mkBefore [ myFirmware ]; </programlisting> <para> @@ -117,7 +117,7 @@ hardware.firmware = mkBefore [ myFirmware ]; to be merged together as if they were declared in separate modules. This can be done using <literal>mkMerge</literal>: </para> - <programlisting language="bash"> + <programlisting language="nix"> config = mkMerge [ # Unconditional stuff. { environment.systemPackages = [ ... ]; diff --git a/nixos/doc/manual/from_md/development/option-types.section.xml b/nixos/doc/manual/from_md/development/option-types.section.xml index c53d630caca3..363399b08661 100644 --- a/nixos/doc/manual/from_md/development/option-types.section.xml +++ b/nixos/doc/manual/from_md/development/option-types.section.xml @@ -81,14 +81,14 @@ <para> Two definitions of this type like </para> - <programlisting language="bash"> + <programlisting language="nix"> { str = lib.mkDefault "foo"; pkg.hello = pkgs.hello; fun.fun = x: x + 1; } </programlisting> - <programlisting language="bash"> + <programlisting language="nix"> { str = lib.mkIf true "bar"; pkg.gcc = pkgs.gcc; @@ -98,7 +98,7 @@ <para> will get merged to </para> - <programlisting language="bash"> + <programlisting language="nix"> { str = "bar"; pkg.gcc = pkgs.gcc; @@ -732,7 +732,7 @@ <emphasis role="strong">Example: Directly defined submodule</emphasis> </para> - <programlisting language="bash"> + <programlisting language="nix"> options.mod = mkOption { description = "submodule example"; type = with types; submodule { @@ -752,7 +752,7 @@ options.mod = mkOption { <emphasis role="strong">Example: Submodule defined as a reference</emphasis> </para> - <programlisting language="bash"> + <programlisting language="nix"> let modOptions = { options = { @@ -787,7 +787,7 @@ options.mod = mkOption { <emphasis role="strong">Example: Declaration of a list of submodules</emphasis> </para> - <programlisting language="bash"> + <programlisting language="nix"> options.mod = mkOption { description = "submodule example"; type = with types; listOf (submodule { @@ -807,7 +807,7 @@ options.mod = mkOption { <emphasis role="strong">Example: Definition of a list of submodules</emphasis> </para> - <programlisting language="bash"> + <programlisting language="nix"> config.mod = [ { foo = 1; bar = "one"; } { foo = 2; bar = "two"; } @@ -827,7 +827,7 @@ config.mod = [ <emphasis role="strong">Example: Declaration of attribute sets of submodules</emphasis> </para> - <programlisting language="bash"> + <programlisting language="nix"> options.mod = mkOption { description = "submodule example"; type = with types; attrsOf (submodule { @@ -847,7 +847,7 @@ options.mod = mkOption { <emphasis role="strong">Example: Definition of attribute sets of submodules</emphasis> </para> - <programlisting language="bash"> + <programlisting language="nix"> config.mod.one = { foo = 1; bar = "one"; }; config.mod.two = { foo = 2; bar = "two"; }; </programlisting> @@ -878,7 +878,7 @@ config.mod.two = { foo = 2; bar = "two"; }; <emphasis role="strong">Example: Adding a type check</emphasis> </para> - <programlisting language="bash"> + <programlisting language="nix"> byte = mkOption { description = "An integer between 0 and 255."; type = types.addCheck types.int (x: x >= 0 && x <= 255); @@ -889,7 +889,7 @@ byte = mkOption { <emphasis role="strong">Example: Overriding a type check</emphasis> </para> - <programlisting language="bash"> + <programlisting language="nix"> nixThings = mkOption { description = "words that start with 'nix'"; type = types.str // { diff --git a/nixos/doc/manual/from_md/development/replace-modules.section.xml b/nixos/doc/manual/from_md/development/replace-modules.section.xml index d5115092bf61..d8aaf59df366 100644 --- a/nixos/doc/manual/from_md/development/replace-modules.section.xml +++ b/nixos/doc/manual/from_md/development/replace-modules.section.xml @@ -22,7 +22,7 @@ only overrides the module definition, this won’t use postgresql from nixos-unstable unless explicitly configured to do so. </para> - <programlisting language="bash"> + <programlisting language="nix"> { config, lib, pkgs, ... }: { @@ -42,7 +42,7 @@ for an existing module. Importing this module will disable the original module without having to know its implementation details. </para> - <programlisting language="bash"> + <programlisting language="nix"> { config, lib, pkgs, ... }: with lib; diff --git a/nixos/doc/manual/from_md/development/settings-options.section.xml b/nixos/doc/manual/from_md/development/settings-options.section.xml index 9e57d070e26e..898cd3b2b6e9 100644 --- a/nixos/doc/manual/from_md/development/settings-options.section.xml +++ b/nixos/doc/manual/from_md/development/settings-options.section.xml @@ -317,7 +317,7 @@ used, along with some other related best practices. See the comments for explanations. </para> - <programlisting language="bash"> + <programlisting language="nix"> { options, config, lib, pkgs, ... }: let cfg = config.services.foo; @@ -390,7 +390,7 @@ in { <emphasis role="strong">Example: Declaring a type-checked <literal>settings</literal> attribute</emphasis> </para> - <programlisting language="bash"> + <programlisting language="nix"> settings = lib.mkOption { type = lib.types.submodule { diff --git a/nixos/doc/manual/from_md/development/writing-modules.chapter.xml b/nixos/doc/manual/from_md/development/writing-modules.chapter.xml index ec061a31892c..35e94845c97e 100644 --- a/nixos/doc/manual/from_md/development/writing-modules.chapter.xml +++ b/nixos/doc/manual/from_md/development/writing-modules.chapter.xml @@ -32,7 +32,7 @@ In <xref linkend="sec-configuration-syntax" />, we saw the following structure of NixOS modules: </para> - <programlisting language="bash"> + <programlisting language="nix"> { config, pkgs, ... }: { option definitions @@ -50,7 +50,7 @@ <emphasis role="strong">Example: Structure of NixOS Modules</emphasis> </para> - <programlisting language="bash"> + <programlisting language="nix"> { config, pkgs, ... }: { @@ -146,7 +146,7 @@ <emphasis role="strong">Example: NixOS Module for the <quote>locate</quote> Service</emphasis> </para> - <programlisting language="bash"> + <programlisting language="nix"> { config, lib, pkgs, ... }: with lib; @@ -208,7 +208,7 @@ in { <emphasis role="strong">Example: Escaping in Exec directives</emphasis> </para> - <programlisting language="bash"> + <programlisting language="nix"> { config, lib, pkgs, utils, ... }: with lib; diff --git a/nixos/doc/manual/from_md/development/writing-nixos-tests.section.xml b/nixos/doc/manual/from_md/development/writing-nixos-tests.section.xml index 8e91b683f44a..dc921dad9749 100644 --- a/nixos/doc/manual/from_md/development/writing-nixos-tests.section.xml +++ b/nixos/doc/manual/from_md/development/writing-nixos-tests.section.xml @@ -3,7 +3,7 @@ <para> A NixOS test is a module that has the following structure: </para> - <programlisting language="bash"> + <programlisting language="nix"> { # One or more machines: @@ -58,14 +58,14 @@ Tests that are part of NixOS are added to <link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/all-tests.nix"><literal>nixos/tests/all-tests.nix</literal></link>. </para> - <programlisting language="bash"> + <programlisting language="nix"> hostname = runTest ./hostname.nix; </programlisting> <para> Overrides can be added by defining an anonymous module in <literal>all-tests.nix</literal>. </para> - <programlisting language="bash"> + <programlisting language="nix"> hostname = runTest { imports = [ ./hostname.nix ]; defaults.networking.firewall.enable = false; @@ -87,7 +87,7 @@ nix-build -A nixosTests.hostname Outside the <literal>nixpkgs</literal> repository, you can instantiate the test by first importing the NixOS library, </para> - <programlisting language="bash"> + <programlisting language="nix"> let nixos-lib = import (nixpkgs + "/nixos/lib") { }; in @@ -633,7 +633,7 @@ machine.wait_for_unit("xautolock.service", "x-session-user") For faster dev cycles it’s also possible to disable the code-linters (this shouldn’t be committed though): </para> - <programlisting language="bash"> + <programlisting language="nix"> { skipLint = true; nodes.machine = @@ -653,7 +653,7 @@ machine.wait_for_unit("xautolock.service", "x-session-user") disable the Black linter directly (again, don’t commit this within the Nixpkgs repository): </para> - <programlisting language="bash"> + <programlisting language="nix"> testScript = '' # fmt: off @@ -665,7 +665,7 @@ machine.wait_for_unit("xautolock.service", "x-session-user") Similarly, the type checking of test scripts can be disabled in the following way: </para> - <programlisting language="bash"> + <programlisting language="nix"> { skipTypeCheck = true; nodes.machine = @@ -700,25 +700,37 @@ with foo_running: <literal>polling_condition</literal> takes the following (optional) arguments: </para> - <para> - <literal>seconds_interval</literal> - </para> - <para> - : specifies how often the condition should be polled: - </para> + <variablelist> + <varlistentry> + <term> + <literal>seconds_interval</literal> + </term> + <listitem> + <para> + specifies how often the condition should be polled: + </para> + </listitem> + </varlistentry> + </variablelist> <programlisting language="python"> @polling_condition(seconds_interval=10) def foo_running(): machine.succeed("pgrep -x foo") </programlisting> - <para> - <literal>description</literal> - </para> - <para> - : is used in the log when the condition is checked. If this is not - provided, the description is pulled from the docstring of the - function. These two are therefore equivalent: - </para> + <variablelist> + <varlistentry> + <term> + <literal>description</literal> + </term> + <listitem> + <para> + is used in the log when the condition is checked. If this is + not provided, the description is pulled from the docstring + of the function. These two are therefore equivalent: + </para> + </listitem> + </varlistentry> + </variablelist> <programlisting language="python"> @polling_condition def foo_running(): @@ -739,7 +751,7 @@ def foo_running(): <literal>extraPythonPackages</literal>. For example, you could add <literal>numpy</literal> like this: </para> - <programlisting language="bash"> + <programlisting language="nix"> { extraPythonPackages = p: [ p.numpy ]; |