···2323 this unit automatically at certain points in time, for instance,
2424 every night at 03:15:
2525 </para>
2626- <programlisting language="bash">
2626+ <programlisting language="nix">
2727nix.gc.automatic = true;
2828nix.gc.dates = "03:15";
2929</programlisting>
···3131 address. This can be accomplished using the following configuration
3232 on the host:
3333 </para>
3434- <programlisting language="bash">
3434+ <programlisting language="nix">
3535networking.nat.enable = true;
3636networking.nat.internalInterfaces = ["ve-+"];
3737networking.nat.externalInterface = "eth0";
···4545 If you are using Network Manager, you need to explicitly prevent it
4646 from managing container interfaces:
4747 </para>
4848- <programlisting language="bash">
4848+ <programlisting language="nix">
4949networking.networkmanager.unmanaged = [ "interface-name:ve-*" ];
5050</programlisting>
5151 <para>
···4242 process would get 1/1001 of the cgroup’s CPU time.) You can limit a
4343 service’s CPU share in <literal>configuration.nix</literal>:
4444 </para>
4545- <programlisting language="bash">
4545+ <programlisting language="nix">
4646systemd.services.httpd.serviceConfig.CPUShares = 512;
4747</programlisting>
4848 <para>
···5757 <literal>configuration.nix</literal>; for instance, to limit
5858 <literal>httpd.service</literal> to 512 MiB of RAM (excluding swap):
5959 </para>
6060- <programlisting language="bash">
6060+ <programlisting language="nix">
6161systemd.services.httpd.serviceConfig.MemoryLimit = "512M";
6262</programlisting>
6363 <para>
···66 following specifies that there shall be a container named
77 <literal>database</literal> running PostgreSQL:
88 </para>
99- <programlisting language="bash">
99+ <programlisting language="nix">
1010containers.database =
1111 { config =
1212 { config, pkgs, ... }:
···2929 However, they cannot change the network configuration. You can give
3030 a container its own network as follows:
3131 </para>
3232- <programlisting language="bash">
3232+ <programlisting language="nix">
3333containers.database = {
3434 privateNetwork = true;
3535 hostAddress = "192.168.100.10";
···9191 In order to enable a systemd <emphasis>system</emphasis> service
9292 with provided upstream package, use (e.g):
9393 </para>
9494- <programlisting language="bash">
9494+ <programlisting language="nix">
9595systemd.packages = [ pkgs.packagekit ];
9696</programlisting>
9797 <para>
···44 If you find yourself repeating yourself over and over, it’s time to
55 abstract. Take, for instance, this Apache HTTP Server configuration:
66 </para>
77- <programlisting language="bash">
77+ <programlisting language="nix">
88{
99 services.httpd.virtualHosts =
1010 { "blog.example.org" = {
···2929 the only difference is the document root directories. To prevent
3030 this duplication, we can use a <literal>let</literal>:
3131 </para>
3232- <programlisting language="bash">
3232+ <programlisting language="nix">
3333let
3434 commonConfig =
3535 { adminAddr = "alice@example.org";
···5555 You can write a <literal>let</literal> wherever an expression is
5656 allowed. Thus, you also could have written:
5757 </para>
5858- <programlisting language="bash">
5858+ <programlisting language="nix">
5959{
6060 services.httpd.virtualHosts =
6161 let commonConfig = ...; in
···7474 of different virtual hosts, all with identical configuration except
7575 for the document root. This can be done as follows:
7676 </para>
7777- <programlisting language="bash">
7777+ <programlisting language="nix">
7878{
7979 services.httpd.virtualHosts =
8080 let
···77 network configuration not covered by the existing NixOS modules. For
88 instance, to statically configure an IPv6 address:
99 </para>
1010- <programlisting language="bash">
1010+ <programlisting language="nix">
1111networking.localCommands =
1212 ''
1313 ip -6 addr add 2001:610:685:1::1/64 dev eth0
···33 <para>
44 The NixOS configuration file generally looks like this:
55 </para>
66- <programlisting language="bash">
66+ <programlisting language="nix">
77{ config, pkgs, ... }:
8899{ option definitions
···2121 the name of an option and <literal>value</literal> is its value. For
2222 example,
2323 </para>
2424- <programlisting language="bash">
2424+ <programlisting language="nix">
2525{ config, pkgs, ... }:
26262727{ services.httpd.enable = true;
···4444 <literal>true</literal>. This means that the example above can also
4545 be written as:
4646 </para>
4747- <programlisting language="bash">
4747+ <programlisting language="nix">
4848{ config, pkgs, ... }:
49495050{ services = {
···9696 <para>
9797 Strings are enclosed in double quotes, e.g.
9898 </para>
9999- <programlisting language="bash">
9999+ <programlisting language="nix">
100100networking.hostName = "dexter";
101101</programlisting>
102102 <para>
···107107 Multi-line strings can be enclosed in <emphasis>double single
108108 quotes</emphasis>, e.g.
109109 </para>
110110- <programlisting language="bash">
110110+ <programlisting language="nix">
111111networking.extraHosts =
112112 ''
113113 127.0.0.2 other-localhost
···135135 These can be <literal>true</literal> or
136136 <literal>false</literal>, e.g.
137137 </para>
138138- <programlisting language="bash">
138138+ <programlisting language="nix">
139139networking.firewall.enable = true;
140140networking.firewall.allowPing = false;
141141</programlisting>
···149149 <para>
150150 For example,
151151 </para>
152152- <programlisting language="bash">
152152+ <programlisting language="nix">
153153boot.kernel.sysctl."net.ipv4.tcp_keepalive_time" = 60;
154154</programlisting>
155155 <para>
···171171 Sets were introduced above. They are name/value pairs enclosed
172172 in braces, as in the option definition
173173 </para>
174174- <programlisting language="bash">
174174+ <programlisting language="nix">
175175fileSystems."/boot" =
176176 { device = "/dev/sda1";
177177 fsType = "ext4";
···189189 The important thing to note about lists is that list elements
190190 are separated by whitespace, like this:
191191 </para>
192192- <programlisting language="bash">
192192+ <programlisting language="nix">
193193boot.kernelModules = [ "fuse" "kvm-intel" "coretemp" ];
194194</programlisting>
195195 <para>
196196 List elements can be any other type, e.g. sets:
197197 </para>
198198- <programlisting language="bash">
198198+ <programlisting language="nix">
199199swapDevices = [ { device = "/dev/disk/by-label/swap"; } ];
200200</programlisting>
201201 </listitem>
···211211 through the function argument <literal>pkgs</literal>. Typical
212212 uses:
213213 </para>
214214- <programlisting language="bash">
214214+ <programlisting language="nix">
215215environment.systemPackages =
216216 [ pkgs.thunderbird
217217 pkgs.emacs
···2222 a dependency on GTK 2. If you want to build it against GTK 3, you
2323 can specify that as follows:
2424 </para>
2525- <programlisting language="bash">
2525+ <programlisting language="nix">
2626environment.systemPackages = [ (pkgs.emacs.override { gtk = pkgs.gtk3; }) ];
2727</programlisting>
2828 <para>
···4646 the package, such as the source code. For instance, if you want to
4747 override the source code of Emacs, you can say:
4848 </para>
4949- <programlisting language="bash">
4949+ <programlisting language="nix">
5050environment.systemPackages = [
5151 (pkgs.emacs.overrideAttrs (oldAttrs: {
5252 name = "emacs-25.0-pre";
···7272 everything depend on your customised instance, you can apply a
7373 <emphasis>global</emphasis> override as follows:
7474 </para>
7575- <programlisting language="bash">
7575+ <programlisting language="nix">
7676nixpkgs.config.packageOverrides = pkgs:
7777 { emacs = pkgs.emacs.override { gtk = pkgs.gtk3; };
7878 };
···77 adding the following line to <literal>configuration.nix</literal>
88 enables the Mozilla Thunderbird email application:
99 </para>
1010- <programlisting language="bash">
1010+ <programlisting language="nix">
1111environment.systemPackages = [ pkgs.thunderbird ];
1212</programlisting>
1313 <para>
···66 both IPv4 and IPv6 traffic. It is enabled by default. It can be
77 disabled as follows:
88 </para>
99- <programlisting language="bash">
99+ <programlisting language="nix">
1010networking.firewall.enable = false;
1111</programlisting>
1212 <para>
1313 If the firewall is enabled, you can open specific TCP ports to the
1414 outside world:
1515 </para>
1616- <programlisting language="bash">
1616+ <programlisting language="nix">
1717networking.firewall.allowedTCPPorts = [ 80 443 ];
1818</programlisting>
1919 <para>
···2626 <para>
2727 To open ranges of TCP ports:
2828 </para>
2929- <programlisting language="bash">
2929+ <programlisting language="nix">
3030networking.firewall.allowedTCPPortRanges = [
3131 { from = 4000; to = 4007; }
3232 { from = 8000; to = 8010; }
···6262 <xref linkend="opt-hardware.opengl.extraPackages" /> enables
6363 OpenCL support:
6464 </para>
6565- <programlisting language="bash">
6565+ <programlisting language="nix">
6666hardware.opengl.extraPackages = [
6767 rocm-opencl-icd
6868];
···8585 enable OpenCL support. For example, for Gen8 and later GPUs, the
8686 following configuration can be used:
8787 </para>
8888- <programlisting language="bash">
8888+ <programlisting language="nix">
8989hardware.opengl.extraPackages = [
9090 intel-compute-runtime
9191];
···162162 makes amdvlk the default driver and hides radv and lavapipe from
163163 the device list. A specific driver can be forced as follows:
164164 </para>
165165- <programlisting language="bash">
165165+ <programlisting language="nix">
166166hardware.opengl.extraPackages = [
167167 pkgs.amdvlk
168168];
···206206 Modern Intel GPUs use the iHD driver, which can be installed
207207 with:
208208 </para>
209209- <programlisting language="bash">
209209+ <programlisting language="nix">
210210hardware.opengl.extraPackages = [
211211 intel-media-driver
212212];
···215215 Older Intel GPUs use the i965 driver, which can be installed
216216 with:
217217 </para>
218218- <programlisting language="bash">
218218+ <programlisting language="nix">
219219hardware.opengl.extraPackages = [
220220 vaapiIntel
221221];
···66 interfaces. However, you can configure an interface manually as
77 follows:
88 </para>
99- <programlisting language="bash">
99+ <programlisting language="nix">
1010networking.interfaces.eth0.ipv4.addresses = [ {
1111 address = "192.168.1.2";
1212 prefixLength = 24;
···1616 Typically you’ll also want to set a default gateway and set of name
1717 servers:
1818 </para>
1919- <programlisting language="bash">
1919+ <programlisting language="nix">
2020networking.defaultGateway = "192.168.1.1";
2121networking.nameservers = [ "8.8.8.8" ];
2222</programlisting>
···3232 The host name is set using
3333 <xref linkend="opt-networking.hostName" />:
3434 </para>
3535- <programlisting language="bash">
3535+ <programlisting language="nix">
3636networking.hostName = "cartman";
3737</programlisting>
3838 <para>
···1010 <xref linkend="opt-networking.interfaces._name_.tempAddress" />. You
1111 can disable IPv6 support globally by setting:
1212 </para>
1313- <programlisting language="bash">
1313+ <programlisting language="nix">
1414networking.enableIPv6 = false;
1515</programlisting>
1616 <para>
1717 You can disable IPv6 on a single interface using a normal sysctl (in
1818 this example, we use interface <literal>eth0</literal>):
1919 </para>
2020- <programlisting language="bash">
2020+ <programlisting language="nix">
2121boot.kernel.sysctl."net.ipv6.conf.eth0.disable_ipv6" = true;
2222</programlisting>
2323 <para>
2424 As with IPv4 networking interfaces are automatically configured via
2525 DHCPv6. You can configure an interface manually:
2626 </para>
2727- <programlisting language="bash">
2727+ <programlisting language="nix">
2828networking.interfaces.eth0.ipv6.addresses = [ {
2929 address = "fe00:aa:bb:cc::2";
3030 prefixLength = 64;
···3434 For configuring a gateway, optionally with explicitly specified
3535 interface:
3636 </para>
3737- <programlisting language="bash">
3737+ <programlisting language="nix">
3838networking.defaultGateway6 = {
3939 address = "fe00::1";
4040 interface = "enp0s3";
···44 To facilitate network configuration, some desktop environments use
55 NetworkManager. You can enable NetworkManager by setting:
66 </para>
77- <programlisting language="bash">
77+ <programlisting language="nix">
88networking.networkmanager.enable = true;
99</programlisting>
1010 <para>
···1515 All users that should have permission to change network settings
1616 must belong to the <literal>networkmanager</literal> group:
1717 </para>
1818- <programlisting language="bash">
1818+ <programlisting language="nix">
1919users.users.alice.extraGroups = [ "networkmanager" ];
2020</programlisting>
2121 <para>
···3636 used together if desired. To do this you need to instruct
3737 NetworkManager to ignore those interfaces like:
3838 </para>
3939- <programlisting language="bash">
3939+ <programlisting language="nix">
4040networking.networkmanager.unmanaged = [
4141 "*" "except:type:wwan" "except:type:gsm"
4242];
···99 to say, expected usage is to add them to the imports list of your
1010 <literal>/etc/configuration.nix</literal> as such:
1111 </para>
1212- <programlisting language="bash">
1212+ <programlisting language="nix">
1313imports = [
1414 <nixpkgs/nixos/modules/profiles/profile-name.nix>
1515];
···33 <para>
44 Secure shell (SSH) access to your machine can be enabled by setting:
55 </para>
66- <programlisting language="bash">
66+ <programlisting language="nix">
77services.openssh.enable = true;
88</programlisting>
99 <para>
···1616 You can declaratively specify authorised RSA/DSA public keys for a
1717 user as follows:
1818 </para>
1919- <programlisting language="bash">
1919+ <programlisting language="nix">
2020users.users.alice.openssh.authorizedKeys.keys =
2121 [ "ssh-dss AAAAB3NzaC1kc3MAAACBAPIkGWVEt4..." ];
2222</programlisting>
···5454 <link linkend="opt-fileSystems">fileSystems</link> option. Here’s
5555 a typical setup:
5656 </para>
5757- <programlisting language="bash">
5757+ <programlisting language="nix">
5858{
5959 system.fsPackages = [ pkgs.sshfs ];
6060···8080 well, for example you can change the default SSH port or specify a
8181 jump proxy:
8282 </para>
8383- <programlisting language="bash">
8383+ <programlisting language="nix">
8484{
8585 options =
8686 [ "ProxyJump=bastion@example.com"
···9292 It’s also possible to change the <literal>ssh</literal> command
9393 used by SSHFS to connect to the server. For example:
9494 </para>
9595- <programlisting language="bash">
9595+ <programlisting language="nix">
9696{
9797 options =
9898 [ (builtins.replaceStrings [" "] ["\\040"]
···77 states that a user account named <literal>alice</literal> shall
88 exist:
99 </para>
1010- <programlisting language="bash">
1010+ <programlisting language="nix">
1111users.users.alice = {
1212 isNormalUser = true;
1313 home = "/home/alice";
···4545 A user ID (uid) is assigned automatically. You can also specify a
4646 uid manually by adding
4747 </para>
4848- <programlisting language="bash">
4848+ <programlisting language="nix">
4949uid = 1000;
5050</programlisting>
5151 <para>
···5555 Groups can be specified similarly. The following states that a group
5656 named <literal>students</literal> shall exist:
5757 </para>
5858- <programlisting language="bash">
5858+ <programlisting language="nix">
5959users.groups.students.gid = 1000;
6060</programlisting>
6161 <para>
···1010 Compositor such as sway without separately enabling a Wayland
1111 server:
1212 </para>
1313- <programlisting language="bash">
1313+ <programlisting language="nix">
1414programs.sway.enable = true;
1515</programlisting>
1616 <para>
···2222 be able to share your screen, you might want to activate this
2323 option:
2424 </para>
2525- <programlisting language="bash">
2525+ <programlisting language="nix">
2626xdg.portal.wlr.enable = true;
2727</programlisting>
2828 <para>
···44 The X Window System (X11) provides the basis of NixOS’ graphical
55 user interface. It can be enabled as follows:
66 </para>
77- <programlisting language="bash">
77+ <programlisting language="nix">
88services.xserver.enable = true;
99</programlisting>
1010 <para>
···1313 and <literal>intel</literal>). You can also specify a driver
1414 manually, e.g.
1515 </para>
1616- <programlisting language="bash">
1616+ <programlisting language="nix">
1717services.xserver.videoDrivers = [ "r128" ];
1818</programlisting>
1919 <para>
···2525 <literal>xterm</literal> window. Thus you should pick one or more of
2626 the following lines:
2727 </para>
2828- <programlisting language="bash">
2828+ <programlisting language="nix">
2929services.xserver.desktopManager.plasma5.enable = true;
3030services.xserver.desktopManager.xfce.enable = true;
3131services.xserver.desktopManager.gnome.enable = true;
···4242 LightDM. You can select an alternative one by picking one of the
4343 following lines:
4444 </para>
4545- <programlisting language="bash">
4545+ <programlisting language="nix">
4646services.xserver.displayManager.sddm.enable = true;
4747services.xserver.displayManager.gdm.enable = true;
4848</programlisting>
4949 <para>
5050 You can set the keyboard layout (and optionally the layout variant):
5151 </para>
5252- <programlisting language="bash">
5252+ <programlisting language="nix">
5353services.xserver.layout = "de";
5454services.xserver.xkbVariant = "neo";
5555</programlisting>
···5757 The X server is started automatically at boot time. If you don’t
5858 want this to happen, you can set:
5959 </para>
6060- <programlisting language="bash">
6060+ <programlisting language="nix">
6161services.xserver.autorun = false;
6262</programlisting>
6363 <para>
···7070 On 64-bit systems, if you want OpenGL for 32-bit programs such as in
7171 Wine, you should also set the following:
7272 </para>
7373- <programlisting language="bash">
7373+ <programlisting language="nix">
7474hardware.opengl.driSupport32Bit = true;
7575</programlisting>
7676 <section xml:id="sec-x11-auto-login">
···9090 manager and desktop environment. If you wanted no desktop
9191 environment and i3 as your your window manager, you’d define:
9292 </para>
9393- <programlisting language="bash">
9393+ <programlisting language="nix">
9494services.xserver.displayManager.defaultSession = "none+i3";
9595</programlisting>
9696 <para>
9797 Every display manager in NixOS supports auto-login, here is an
9898 example using lightdm for a user <literal>alice</literal>:
9999 </para>
100100- <programlisting language="bash">
100100+ <programlisting language="nix">
101101services.xserver.displayManager.lightdm.enable = true;
102102services.xserver.displayManager.autoLogin.enable = true;
103103services.xserver.displayManager.autoLogin.user = "alice";
···131131 <xref linkend="opt-services.xserver.videoDrivers" /> to set one.
132132 The recommended configuration for modern systems is:
133133 </para>
134134- <programlisting language="bash">
134134+ <programlisting language="nix">
135135services.xserver.videoDrivers = [ "modesetting" ];
136136</programlisting>
137137 <para>
138138 If you experience screen tearing no matter what, this
139139 configuration was reported to resolve the issue:
140140 </para>
141141- <programlisting language="bash">
141141+ <programlisting language="nix">
142142services.xserver.videoDrivers = [ "intel" ];
143143services.xserver.deviceSection = ''
144144 Option "DRI" "2"
···159159 enabled by default because it’s not free software. You can enable
160160 it as follows:
161161 </para>
162162- <programlisting language="bash">
162162+ <programlisting language="nix">
163163services.xserver.videoDrivers = [ "nvidia" ];
164164</programlisting>
165165 <para>
166166 Or if you have an older card, you may have to use one of the
167167 legacy drivers:
168168 </para>
169169- <programlisting language="bash">
169169+ <programlisting language="nix">
170170services.xserver.videoDrivers = [ "nvidiaLegacy390" ];
171171services.xserver.videoDrivers = [ "nvidiaLegacy340" ];
172172services.xserver.videoDrivers = [ "nvidiaLegacy304" ];
···185185 features or performance. If you still want to use it anyway, you
186186 need to explicitly set:
187187 </para>
188188- <programlisting language="bash">
188188+ <programlisting language="nix">
189189services.xserver.videoDrivers = [ "amdgpu-pro" ];
190190</programlisting>
191191 <para>
···199199 Support for Synaptics touchpads (found in many laptops such as the
200200 Dell Latitude series) can be enabled as follows:
201201 </para>
202202- <programlisting language="bash">
202202+ <programlisting language="nix">
203203services.xserver.libinput.enable = true;
204204</programlisting>
205205 <para>
206206 The driver has many options (see <xref linkend="ch-options" />).
207207 For instance, the following disables tap-to-click behavior:
208208 </para>
209209- <programlisting language="bash">
209209+ <programlisting language="nix">
210210services.xserver.libinput.touchpad.tapping = false;
211211</programlisting>
212212 <para>
···222222 applications look similar to GTK ones, you can use the following
223223 configuration:
224224 </para>
225225- <programlisting language="bash">
225225+ <programlisting language="nix">
226226qt5.enable = true;
227227qt5.platformTheme = "gtk2";
228228qt5.style = "gtk2";
···247247 <literal>symbols</literal>; it’s an XKB peculiarity that will help
248248 with testing):
249249 </para>
250250- <programlisting language="bash">
250250+ <programlisting language="nix">
251251xkb_symbols "us-greek"
252252{
253253 include "us(basic)" // includes the base US keys
···263263 <para>
264264 A minimal layout specification must include the following:
265265 </para>
266266- <programlisting language="bash">
266266+ <programlisting language="nix">
267267services.xserver.extraLayouts.us-greek = {
268268 description = "US layout with alt-gr greek";
269269 languages = [ "eng" ];
···312312 interest, then create a <literal>media-key</literal> file to hold
313313 the keycodes definitions
314314 </para>
315315- <programlisting language="bash">
315315+ <programlisting language="nix">
316316xkb_keycodes "media"
317317{
318318 <volUp> = 123;
···322322 <para>
323323 Now use the newly define keycodes in <literal>media-sym</literal>:
324324 </para>
325325- <programlisting language="bash">
325325+ <programlisting language="nix">
326326xkb_symbols "media"
327327{
328328 key.type = "ONE_LEVEL";
···333333 <para>
334334 As before, to install the layout do
335335 </para>
336336- <programlisting language="bash">
336336+ <programlisting language="nix">
337337services.xserver.extraLayouts.media = {
338338 description = "Multimedia keys remapping";
339339 languages = [ "eng" ];
···357357 default. As a workaround, you can set the keymap using
358358 <literal>setxkbmap</literal> at the start of the session with:
359359 </para>
360360- <programlisting language="bash">
360360+ <programlisting language="nix">
361361services.xserver.displayManager.sessionCommands = "setxkbmap -keycodes media";
362362</programlisting>
363363 <para>
···1818 <para>
1919 This is an example of using <literal>warnings</literal>.
2020 </para>
2121- <programlisting language="bash">
2121+ <programlisting language="nix">
2222{ config, lib, ... }:
2323{
2424 config = lib.mkIf config.services.foo.enable {
···4242 assertion is useful to prevent such a broken system from being
4343 built.
4444 </para>
4545- <programlisting language="bash">
4545+ <programlisting language="nix">
4646{ config, lib, ... }:
4747{
4848 config = lib.mkIf config.services.syslogd.enable {
···3030 type-checked <literal>settings</literal> attribute</link> for a more
3131 complete example.
3232 </para>
3333- <programlisting language="bash">
3333+ <programlisting language="nix">
3434{ lib, config, ... }: {
35353636 options.settings = lib.mkOption {
···5252 <para>
5353 And the following shows what such a module then allows
5454 </para>
5555- <programlisting language="bash">
5555+ <programlisting language="nix">
5656{
5757 # Not a declared option, but the freeform type allows this
5858 settings.logLevel = "debug";
···7272 Freeform attributes cannot depend on other attributes of the same
7373 set without infinite recursion:
7474 </para>
7575- <programlisting language="bash">
7575+ <programlisting language="nix">
7676{
7777 # This throws infinite recursion encountered
7878 settings.logLevel = lib.mkIf (config.settings.port == 80) "debug";
···1515 Each of the meta-attributes must be defined at most once per module
1616 file.
1717 </para>
1818- <programlisting language="bash">
1818+ <programlisting language="nix">
1919{ config, lib, pkgs, ... }:
2020{
2121 options = {
···44 Option definitions are generally straight-forward bindings of values
55 to option names, like
66 </para>
77- <programlisting language="bash">
77+ <programlisting language="nix">
88config = {
99 services.httpd.enable = true;
1010};
···2121 another option, you may need to use <literal>mkIf</literal>.
2222 Consider, for instance:
2323 </para>
2424- <programlisting language="bash">
2424+ <programlisting language="nix">
2525config = if config.services.httpd.enable then {
2626 environment.systemPackages = [ ... ];
2727 ...
···3434 value being constructed here. After all, you could also write the
3535 clearly circular and contradictory:
3636 </para>
3737- <programlisting language="bash">
3737+ <programlisting language="nix">
3838config = if config.services.httpd.enable then {
3939 services.httpd.enable = false;
4040} else {
···4444 <para>
4545 The solution is to write:
4646 </para>
4747- <programlisting language="bash">
4747+ <programlisting language="nix">
4848config = mkIf config.services.httpd.enable {
4949 environment.systemPackages = [ ... ];
5050 ...
···5555 of the conditional to be <quote>pushed down</quote> into the
5656 individual definitions, as if you had written:
5757 </para>
5858- <programlisting language="bash">
5858+ <programlisting language="nix">
5959config = {
6060 environment.systemPackages = if config.services.httpd.enable then [ ... ] else [];
6161 ...
···7272 option defaults have priority 1500. You can specify an explicit
7373 priority by using <literal>mkOverride</literal>, e.g.
7474 </para>
7575- <programlisting language="bash">
7575+ <programlisting language="nix">
7676services.openssh.enable = mkOverride 10 false;
7777</programlisting>
7878 <para>
···9494 <literal>mkOrder 500</literal> and
9595 <literal>mkOrder 1500</literal>, respectively. As an example,
9696 </para>
9797- <programlisting language="bash">
9797+ <programlisting language="nix">
9898hardware.firmware = mkBefore [ myFirmware ];
9999</programlisting>
100100 <para>
···117117 to be merged together as if they were declared in separate
118118 modules. This can be done using <literal>mkMerge</literal>:
119119 </para>
120120- <programlisting language="bash">
120120+ <programlisting language="nix">
121121config = mkMerge
122122 [ # Unconditional stuff.
123123 { environment.systemPackages = [ ... ];
···2222 only overrides the module definition, this won’t use postgresql from
2323 nixos-unstable unless explicitly configured to do so.
2424 </para>
2525- <programlisting language="bash">
2525+ <programlisting language="nix">
2626{ config, lib, pkgs, ... }:
27272828{
···4242 for an existing module. Importing this module will disable the
4343 original module without having to know its implementation details.
4444 </para>
4545- <programlisting language="bash">
4545+ <programlisting language="nix">
4646{ config, lib, pkgs, ... }:
47474848with lib;
···33 <para>
44 A NixOS test is a module that has the following structure:
55 </para>
66- <programlisting language="bash">
66+ <programlisting language="nix">
77{
8899 # One or more machines:
···5858 Tests that are part of NixOS are added to
5959 <link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/all-tests.nix"><literal>nixos/tests/all-tests.nix</literal></link>.
6060 </para>
6161- <programlisting language="bash">
6161+ <programlisting language="nix">
6262 hostname = runTest ./hostname.nix;
6363</programlisting>
6464 <para>
6565 Overrides can be added by defining an anonymous module in
6666 <literal>all-tests.nix</literal>.
6767 </para>
6868- <programlisting language="bash">
6868+ <programlisting language="nix">
6969 hostname = runTest {
7070 imports = [ ./hostname.nix ];
7171 defaults.networking.firewall.enable = false;
···8787 Outside the <literal>nixpkgs</literal> repository, you can
8888 instantiate the test by first importing the NixOS library,
8989 </para>
9090- <programlisting language="bash">
9090+ <programlisting language="nix">
9191let nixos-lib = import (nixpkgs + "/nixos/lib") { };
9292in
9393···633633 For faster dev cycles it’s also possible to disable the
634634 code-linters (this shouldn’t be committed though):
635635 </para>
636636- <programlisting language="bash">
636636+ <programlisting language="nix">
637637{
638638 skipLint = true;
639639 nodes.machine =
···653653 disable the Black linter directly (again, don’t commit this within
654654 the Nixpkgs repository):
655655 </para>
656656- <programlisting language="bash">
656656+ <programlisting language="nix">
657657 testScript =
658658 ''
659659 # fmt: off
···665665 Similarly, the type checking of test scripts can be disabled in
666666 the following way:
667667 </para>
668668- <programlisting language="bash">
668668+ <programlisting language="nix">
669669{
670670 skipTypeCheck = true;
671671 nodes.machine =
···700700 <literal>polling_condition</literal> takes the following
701701 (optional) arguments:
702702 </para>
703703- <para>
704704- <literal>seconds_interval</literal>
705705- </para>
706706- <para>
707707- : specifies how often the condition should be polled:
708708- </para>
703703+ <variablelist>
704704+ <varlistentry>
705705+ <term>
706706+ <literal>seconds_interval</literal>
707707+ </term>
708708+ <listitem>
709709+ <para>
710710+ specifies how often the condition should be polled:
711711+ </para>
712712+ </listitem>
713713+ </varlistentry>
714714+ </variablelist>
709715 <programlisting language="python">
710716@polling_condition(seconds_interval=10)
711717def foo_running():
712718 machine.succeed("pgrep -x foo")
713719</programlisting>
714714- <para>
715715- <literal>description</literal>
716716- </para>
717717- <para>
718718- : is used in the log when the condition is checked. If this is not
719719- provided, the description is pulled from the docstring of the
720720- function. These two are therefore equivalent:
721721- </para>
720720+ <variablelist>
721721+ <varlistentry>
722722+ <term>
723723+ <literal>description</literal>
724724+ </term>
725725+ <listitem>
726726+ <para>
727727+ is used in the log when the condition is checked. If this is
728728+ not provided, the description is pulled from the docstring
729729+ of the function. These two are therefore equivalent:
730730+ </para>
731731+ </listitem>
732732+ </varlistentry>
733733+ </variablelist>
722734 <programlisting language="python">
723735@polling_condition
724736def foo_running():
···739751 <literal>extraPythonPackages</literal>. For example, you could add
740752 <literal>numpy</literal> like this:
741753 </para>
742742- <programlisting language="bash">
754754+ <programlisting language="nix">
743755{
744756 extraPythonPackages = p: [ p.numpy ];
745757
···9494 unless you have set <literal>mutableUsers = false</literal>. Another
9595 way is to temporarily add the following to your configuration:
9696 </para>
9797- <programlisting language="bash">
9797+ <programlisting language="nix">
9898users.users.your-user.initialHashedPassword = "test";
9999</programlisting>
100100 <para>
···5858 There are a few modifications you should make in configuration.nix.
5959 Enable booting:
6060 </para>
6161- <programlisting language="bash">
6161+ <programlisting language="nix">
6262boot.loader.grub.device = "/dev/sda";
6363</programlisting>
6464 <para>
6565 Also remove the fsck that runs at startup. It will always fail to
6666 run, stopping your boot until you press <literal>*</literal>.
6767 </para>
6868- <programlisting language="bash">
6868+ <programlisting language="nix">
6969boot.initrd.checkJournalingFS = false;
7070</programlisting>
7171 <para>
···7676 If you do not add <literal>"nofail"</literal>, the system
7777 will not boot properly.
7878 </para>
7979- <programlisting language="bash">
7979+ <programlisting language="nix">
8080{ config, pkgs, ...} :
8181{
8282 fileSystems."/virtualboxshare" = {
···128128 You can keep a NixOS system up-to-date automatically by adding the
129129 following to <literal>configuration.nix</literal>:
130130 </para>
131131- <programlisting language="bash">
131131+ <programlisting language="nix">
132132system.autoUpgrade.enable = true;
133133system.autoUpgrade.allowReboot = true;
134134</programlisting>
···145145 contains a different kernel, initrd or kernel modules. You can
146146 also specify a channel explicitly, e.g.
147147 </para>
148148- <programlisting language="bash">
148148+ <programlisting language="nix">
149149system.autoUpgrade.channel = https://nixos.org/channels/nixos-22.11;
150150</programlisting>
151151 </section>
···7979 the NixOS configuration. For instance, if a package
8080 <literal>foo</literal> provides systemd units, you can say:
8181 </para>
8282- <programlisting language="bash">
8282+ <programlisting language="nix">
8383{
8484 systemd.packages = [ pkgs.foo ];
8585}
···8888 to enable those units. You can then set or override unit options
8989 in the usual way, e.g.
9090 </para>
9191- <programlisting language="bash">
9191+ <programlisting language="nix">
9292{
9393 systemd.services.foo.wantedBy = [ "multi-user.target" ];
9494 systemd.services.foo.serviceConfig.MemoryLimit = "512M";
···105105 NixOS configuration requires unfree packages from Nixpkgs, you
106106 need to enable support for them explicitly by setting:
107107 </para>
108108- <programlisting language="bash">
108108+ <programlisting language="nix">
109109{
110110 nixpkgs.config.allowUnfree = true;
111111}
···123123 The Adobe Flash player is no longer enabled by default in the
124124 Firefox and Chromium wrappers. To enable it, you must set:
125125 </para>
126126- <programlisting language="bash">
126126+ <programlisting language="nix">
127127{
128128 nixpkgs.config.allowUnfree = true;
129129 nixpkgs.config.firefox.enableAdobeFlash = true; # for Firefox
···136136 The firewall is now enabled by default. If you don’t want this,
137137 you need to disable it explicitly:
138138 </para>
139139- <programlisting language="bash">
139139+ <programlisting language="nix">
140140{
141141 networking.firewall.enable = false;
142142}
···370370 documentation</link> for details. If you wish to continue to use
371371 httpd 2.2, add the following line to your NixOS configuration:
372372 </para>
373373- <programlisting language="bash">
373373+ <programlisting language="nix">
374374{
375375 services.httpd.package = pkgs.apacheHttpd_2_2;
376376}
···378378 You will need to add an import statement to your NixOS
379379 configuration in order to use it, e.g.
380380 </para>
381381- <programlisting language="bash">
381381+ <programlisting language="nix">
382382{
383383 imports = [ <nixpkgs/nixos/modules/services/misc/gitit.nix> ];
384384}
···395395 to be built in. All modules now reside in
396396 <literal>nginxModules</literal> set. Example configuration:
397397 </para>
398398- <programlisting language="bash">
398398+ <programlisting language="nix">
399399nginx.override {
400400 modules = [ nginxModules.rtmp nginxModules.dav nginxModules.moreheaders ];
401401}
···468468 continue to work, but print a warning, until the 16.09 release.
469469 An example of the new style:
470470 </para>
471471- <programlisting language="bash">
471471+ <programlisting language="nix">
472472{
473473 fileSystems."/example" = {
474474 device = "/dev/sdc";
···524524 used input method name, <literal>"ibus"</literal> for
525525 ibus. An example of the new style:
526526 </para>
527527- <programlisting language="bash">
527527+ <programlisting language="nix">
528528{
529529 i18n.inputMethod.enabled = "ibus";
530530 i18n.inputMethod.ibus.engines = with pkgs.ibus-engines; [ anthy mozc ];
···533533 <para>
534534 That is equivalent to the old version:
535535 </para>
536536- <programlisting language="bash">
536536+ <programlisting language="nix">
537537{
538538 programs.ibus.enable = true;
539539 programs.ibus.plugins = with pkgs; [ ibus-anthy mozc ];
···587587 point to exact folder where syncthing is writing to. Example
588588 configuration should look something like:
589589 </para>
590590- <programlisting language="bash">
590590+ <programlisting language="nix">
591591{
592592 services.syncthing = {
593593 enable = true;
···192192 interface has been streamlined. Desktop users should be able to
193193 simply set
194194 </para>
195195- <programlisting language="bash">
195195+ <programlisting language="nix">
196196{
197197 security.grsecurity.enable = true;
198198}
···2929 head. Apart from that, it’s now possible to also set
3030 additional options by using an attribute set, for example:
3131 </para>
3232- <programlisting language="bash">
3232+ <programlisting language="nix">
3333{ services.xserver.xrandrHeads = [
3434 "HDMI-0"
3535 {
···5454 <para>
5555 For example
5656 </para>
5757- <programlisting language="bash">
5757+ <programlisting language="nix">
5858{
5959 programs.firejail = {
6060 enable = true;
···695695 A NixOS system can now be constructed more easily based on a
696696 preexisting invocation of Nixpkgs. For example:
697697 </para>
698698- <programlisting language="bash">
698698+ <programlisting language="nix">
699699{
700700 inherit (pkgs.nixos {
701701 boot.loader.grub.enable = false;
···791791 <para>
792792 An example usage of this would be:
793793 </para>
794794- <programlisting language="bash">
794794+ <programlisting language="nix">
795795{ config, ... }:
796796797797{
···330330 <literal>mediatomb</literal> package. If you want to keep the
331331 old behavior, you must declare it with:
332332 </para>
333333- <programlisting language="bash">
333333+ <programlisting language="nix">
334334{
335335 services.mediatomb.package = pkgs.mediatomb;
336336}
···341341 service declaration to add the firewall rules itself before,
342342 you should now declare it with:
343343 </para>
344344- <programlisting language="bash">
344344+ <programlisting language="nix">
345345{
346346 services.mediatomb.openFirewall = true;
347347}
···368368 <link xlink:href="options.html#opt-services.uwsgi.capabilities">services.uwsgi.capabilities</link>.
369369 The previous behaviour can be restored by setting:
370370 </para>
371371- <programlisting language="bash">
371371+ <programlisting language="nix">
372372{
373373 services.uwsgi.user = "root";
374374 services.uwsgi.group = "root";
···552552 has been removed. To enable Privoxy, and to configure it to
553553 use Tor’s faster port, use the following configuration:
554554 </para>
555555- <programlisting language="bash">
555555+ <programlisting language="nix">
556556{
557557 opt-services.privoxy.enable = true;
558558 opt-services.privoxy.enableTor = true;
···689689 <literal>mpich</literal> instead of the default
690690 <literal>openmpi</literal> can now be achived like this:
691691 </para>
692692- <programlisting language="bash">
692692+ <programlisting language="nix">
693693self: super:
694694{
695695 mpi = super.mpich;
···850850 kodiPackages.inputstream-adaptive and kodiPackages.vfs-sftp
851851 addons:
852852 </para>
853853- <programlisting language="bash">
853853+ <programlisting language="nix">
854854{
855855 environment.systemPackages = [
856856 pkgs.kodi
···867867 and as a result the above configuration should now be written
868868 as:
869869 </para>
870870- <programlisting language="bash">
870870+ <programlisting language="nix">
871871{
872872 environment.systemPackages = [
873873 (pkgs.kodi.withPackages (p: with p; [
···11581158 users to declare autoscan media directories from their nixos
11591159 configuration:
11601160 </para>
11611161- <programlisting language="bash">
11611161+ <programlisting language="nix">
11621162{
11631163 services.mediatomb.mediaDirectories = [
11641164 { path = "/var/lib/mediatomb/pictures"; recursive = false; hidden-files = false; }
···15191519 been dropped. Users that still want it should add the
15201520 following to their system configuration:
15211521 </para>
15221522- <programlisting language="bash">
15221522+ <programlisting language="nix">
15231523{
15241524 services.gvfs.package = pkgs.gvfs.override { samba = null; };
15251525}
···10821082 removed. This option was an association of environment
10831083 variables for Grafana. If you had an expression like
10841084 </para>
10851085- <programlisting language="bash">
10851085+ <programlisting language="nix">
10861086{
10871087 services.grafana.extraOptions.SECURITY_ADMIN_USER = "foobar";
10881088}
···10961096 For the migration, it is recommended to turn it into the
10971097 INI format, i.e. to declare
10981098 </para>
10991099- <programlisting language="bash">
10991099+ <programlisting language="nix">
11001100{
11011101 services.grafana.settings.security.admin_user = "foobar";
11021102}
+1-1
nixos/doc/manual/md-to-db.sh
···11#! /usr/bin/env nix-shell
22-#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/tarball/21.11 -i bash -p pandoc
22+#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/tarball/22.11 -i bash -p pandoc
3344# This script is temporarily needed while we transition the manual to
55# CommonMark. It converts the .md files in the regular manual folder