Merge master into staging-next

This commit is contained in:
github-actions[bot] 2023-02-10 12:01:38 +00:00 committed by GitHub
commit 9be52f693f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
182 changed files with 2198 additions and 32201 deletions

View File

@ -26,7 +26,6 @@ For new packages please briefly describe the package or provide a link to its ho
- [ ] (Package updates) Added a release notes entry if the change is major or breaking
- [ ] (Module updates) Added a release notes entry if the change is significant
- [ ] (Module addition) Added a release notes entry if adding a new NixOS module
- [ ] (Release notes changes) Ran `nixos/doc/manual/md-to-db.sh` to update generated release notes
- [ ] Fits [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md).
<!--

View File

@ -1,34 +0,0 @@
name: NixOS manual checks
permissions: read-all
on:
pull_request_target:
branches-ignore:
- 'release-**'
paths:
- 'nixos/**/*.xml'
- 'nixos/**/*.md'
jobs:
tests:
runs-on: ubuntu-latest
if: github.repository_owner == 'NixOS'
steps:
- uses: actions/checkout@v3
with:
# pull_request_target checks out the base branch by default
ref: refs/pull/${{ github.event.pull_request.number }}/merge
- uses: cachix/install-nix-action@v18
- name: Check DocBook files generated from Markdown are consistent
run: |
nixos/doc/manual/md-to-db.sh
git diff --exit-code || {
echo
echo 'Generated manual files are out of date.'
echo 'Please run'
echo
echo ' nixos/doc/manual/md-to-db.sh'
echo
exit 1
}

View File

@ -128,14 +128,17 @@ Anything that does not cause user or downstream dependency regressions can be ba
- Security critical applications (E.g. `firefox`)
## Generating 23.05 Release Notes
<!--
note: title unchanged even though we don't need regeneration because extant
PRs will link here. definitely change the title for 23.11 though.
-->
Documentation in nixpkgs is transitioning to a markdown-centric workflow. Release notes now require a translation step to convert from markdown to a compatible docbook document.
Documentation in nixpkgs is transitioning to a markdown-centric workflow. In the past release notes required a translation step to convert from markdown to a compatible docbook document, but this is no longer necessary.
Steps for updating 23.05 Release notes:
1. Edit `nixos/doc/manual/release-notes/rl-2305.section.md` with the desired changes
2. Run `./nixos/doc/manual/md-to-db.sh` to render `nixos/doc/manual/from_md/release-notes/rl-2305.section.xml`
3. Include changes to `rl-2305.section.md` and `rl-2305.section.xml` in the same commit.
2. Commit changes to `rl-2305.section.md`.
## Reviewing contributions

View File

@ -3,7 +3,7 @@ MD_TARGETS=$(addsuffix .xml, $(basename $(shell find . -type f -regex '.*\.md$$'
PANDOC ?= pandoc
pandoc_media_dir = media
# NOTE: Keep in sync with NixOS manual (/nixos/doc/manual/md-to-db.sh) and conversion script (/maintainers/scripts/db-to-md.sh).
# NOTE: Keep in sync with conversion script (/maintainers/scripts/db-to-md.sh).
# TODO: Remove raw-attribute when we can get rid of DocBook altogether.
pandoc_commonmark_enabled_extensions = +attributes+fenced_divs+footnotes+bracketed_spans+definition_lists+pipe_tables+raw_attribute
# Not needed:

View File

@ -1,11 +0,0 @@
--[[
Converts some HTML elements commonly used in Markdown to corresponding DocBook elements.
]]
function RawInline(elem)
if elem.format == 'html' and elem.text == '<kbd>' then
return pandoc.RawInline('docbook', '<keycap>')
elseif elem.format == 'html' and elem.text == '</kbd>' then
return pandoc.RawInline('docbook', '</keycap>')
end
end

View File

@ -10,9 +10,7 @@ nativeBuildInputs = [ breakpointHook ];
When a build failure happens there will be an instruction printed that shows how to attach with `cntr` to the build sandbox.
::: {.note}
::: {.title}
Caution with remote builds
:::
This wont work with remote builds as the build environment is on a different machine and cant be accessed by `cntr`. Remote builds can be turned off by setting `--option builders ''` for `nix-build` or `--builders ''` for `nix build`.
:::

View File

@ -67,7 +67,13 @@ When using multiple modules, you may need to access configuration values
defined in other modules. This is what the `config` function argument is
for: it contains the complete, merged system configuration. That is,
`config` is the result of combining the configurations returned by every
module [^1] . For example, here is a module that adds some packages to
module. (If you're wondering how it's possible that the (indirect) *result*
of a function is passed as an *input* to that same function: that's
because Nix is a "lazy" language --- it only computes values when
they are needed. This works as long as no individual configuration
value depends on itself.)
For example, here is a module that adds some packages to
[](#opt-environment.systemPackages) only if
[](#opt-services.xserver.enable) is set to `true` somewhere else:
@ -125,9 +131,3 @@ in
{ imports = [ (netConfig "nixos.localdomain") ]; }
```
[^1]: If you're wondering how it's possible that the (indirect) *result*
of a function is passed as an *input* to that same function: that's
because Nix is a "lazy" language --- it only computes values when
they are needed. This works as long as no individual configuration
value depends on itself.

View File

@ -8,7 +8,7 @@ It means that if you have SSH access to a machine, no additional setup is needed
## Interactive mounting {#sec-sshfs-interactive}
In NixOS, SSHFS is packaged as <package>sshfs</package>.
In NixOS, SSHFS is packaged as `sshfs`.
Once installed, mounting a directory interactively is simple as running:
```ShellSession
$ sshfs my-user@example.com:/my-dir /mnt/my-dir

View File

@ -69,7 +69,7 @@ Wine, you should also set the following:
hardware.opengl.driSupport32Bit = true;
```
## Auto-login {#sec-x11-auto-login .unnumbered}
## Auto-login {#sec-x11-auto-login}
The x11 login screen can be skipped entirely, automatically logging you
into your window manager and desktop environment when you boot your
@ -96,7 +96,7 @@ services.xserver.displayManager.autoLogin.enable = true;
services.xserver.displayManager.autoLogin.user = "alice";
```
## Intel Graphics drivers {#sec-x11--graphics-cards-intel .unnumbered}
## Intel Graphics drivers {#sec-x11--graphics-cards-intel}
There are two choices for Intel Graphics drivers in X.org: `modesetting`
(included in the xorg-server itself) and `intel` (provided by the
@ -136,7 +136,7 @@ services.xserver.deviceSection = ''
Note that this will likely downgrade the performance compared to
`modesetting` or `intel` with DRI 3 (default).
## Proprietary NVIDIA drivers {#sec-x11-graphics-cards-nvidia .unnumbered}
## Proprietary NVIDIA drivers {#sec-x11-graphics-cards-nvidia}
NVIDIA provides a proprietary driver for its graphics cards that has
better 3D performance than the X.org drivers. It is not enabled by
@ -158,7 +158,7 @@ services.xserver.videoDrivers = [ "nvidiaLegacy304" ];
You may need to reboot after enabling this driver to prevent a clash
with other kernel modules.
## Proprietary AMD drivers {#sec-x11--graphics-cards-amd .unnumbered}
## Proprietary AMD drivers {#sec-x11--graphics-cards-amd}
AMD provides a proprietary driver for its graphics cards that is not
enabled by default because it's not Free Software, is often broken in
@ -173,7 +173,7 @@ services.xserver.videoDrivers = [ "amdgpu-pro" ];
You will need to reboot after enabling this driver to prevent a clash
with other kernel modules.
## Touchpads {#sec-x11-touchpads .unnumbered}
## Touchpads {#sec-x11-touchpads}
Support for Synaptics touchpads (found in many laptops such as the Dell
Latitude series) can be enabled as follows:
@ -192,7 +192,7 @@ services.xserver.libinput.touchpad.tapping = false;
Note: the use of `services.xserver.synaptics` is deprecated since NixOS
17.09.
## GTK/Qt themes {#sec-x11-gtk-and-qt-themes .unnumbered}
## GTK/Qt themes {#sec-x11-gtk-and-qt-themes}
GTK themes can be installed either to user profile or system-wide (via
`environment.systemPackages`). To make Qt 5 applications look similar to
@ -204,7 +204,7 @@ qt.platformTheme = "gtk2";
qt.style = "gtk2";
```
## Custom XKB layouts {#custom-xkb-layouts .unnumbered}
## Custom XKB layouts {#custom-xkb-layouts}
It is possible to install custom [ XKB
](https://en.wikipedia.org/wiki/X_keyboard_extension) keyboard layouts

View File

@ -24,7 +24,7 @@ Some Xfce programs are not installed automatically. To install them
manually (system wide), put them into your
[](#opt-environment.systemPackages) from `pkgs.xfce`.
## Thunar {#sec-xfce-thunar-plugins .unnumbered}
## Thunar {#sec-xfce-thunar-plugins}
Thunar (the Xfce file manager) is automatically enabled when Xfce is
enabled. To enable Thunar without enabling Xfce, use the configuration
@ -35,7 +35,7 @@ If you'd like to add extra plugins to Thunar, add them to
[](#opt-programs.thunar.plugins). You shouldn't just add them to
[](#opt-environment.systemPackages).
## Troubleshooting {#sec-xfce-troubleshooting .unnumbered}
## Troubleshooting {#sec-xfce-troubleshooting}
Even after enabling udisks2, volume management might not work. Thunar
and/or the desktop takes time to show up. Thunar will spit out this kind

View File

@ -6,7 +6,6 @@ You can quickly check your edits with the following:
```ShellSession
$ cd /path/to/nixpkgs
$ ./nixos/doc/manual/md-to-db.sh
$ nix-build nixos/release.nix -A manual.x86_64-linux
```

View File

@ -68,12 +68,34 @@ let
optionIdPrefix = "test-opt-";
};
sources = lib.sourceFilesBySuffices ./. [".xml"];
sources = runCommand "manual-sources" {
inputs = lib.sourceFilesBySuffices ./. [ ".xml" ".md" ];
nativeBuildInputs = [ pkgs.nixos-render-docs ];
} ''
mkdir $out
cd $out
cp -r --no-preserve=all $inputs/* .
declare -a convert_args
while read -r mf; do
if [[ "$mf" = *.chapter.md ]]; then
convert_args+=("--chapter")
else
convert_args+=("--section")
fi
convert_args+=("from_md/''${mf%.md}.xml" "$mf")
done < <(find . -type f -name '*.md')
nixos-render-docs manual docbook-fragment \
--manpage-urls ${manpageUrls} \
"''${convert_args[@]}"
'';
modulesDoc = runCommand "modules.xml" {
nativeBuildInputs = [ pkgs.nixos-render-docs ];
} ''
nixos-render-docs manual docbook \
nixos-render-docs manual docbook-section \
--manpage-urls ${manpageUrls} \
"$out" \
--section \
@ -255,8 +277,7 @@ in rec {
# Generate the NixOS manpages.
manpages = runCommand "nixos-manpages"
{ inherit sources;
nativeBuildInputs = [
{ nativeBuildInputs = [
buildPackages.installShellFiles
] ++ lib.optionals allowDocBook [
buildPackages.libxml2.bin

View File

@ -13,9 +13,8 @@ checking for entire option trees, it is only recommended for use in
submodules.
::: {#ex-freeform-module .example}
::: {.title}
**Example: Freeform submodule**
:::
The following shows a submodule assigning a freeform type that allows
arbitrary attributes with `str` values below `settings`, but also
declares an option for the `settings.port` attribute to have it

View File

@ -87,6 +87,7 @@ lib.mkOption {
description = lib.mdDoc "Whether to enable magic.";
}
```
:::
### `mkPackageOption`, `mkPackageOptionMD` {#sec-option-declarations-util-mkPackageOption}
@ -108,7 +109,7 @@ You can omit the default path if the name of the option is also attribute path i
During the transition to CommonMark documentation `mkPackageOption` creates an option with a DocBook description attribute, once the transition is completed it will create a CommonMark description instead. `mkPackageOptionMD` always creates an option with a CommonMark description attribute and will be removed some time after the transition is completed.
::: {#ex-options-declarations-util-mkPackageOption .title}
[]{#ex-options-declarations-util-mkPackageOption}
Examples:
::: {#ex-options-declarations-util-mkPackageOption-hello .example}
@ -122,6 +123,7 @@ lib.mkOption {
description = lib.mdDoc "The hello package to use.";
}
```
:::
::: {#ex-options-declarations-util-mkPackageOption-ghc .example}
```nix
@ -138,6 +140,7 @@ lib.mkOption {
description = lib.mdDoc "The GHC package to use.";
}
```
:::
## Extensible Option Types {#sec-option-declarations-eot}
@ -186,9 +189,7 @@ changing the main service module file and the type system automatically
enforces that there can only be a single display manager enabled.
::: {#ex-option-declaration-eot-service .example}
::: {.title}
**Example: Extensible type placeholder in the service module**
:::
```nix
services.xserver.displayManager.enable = mkOption {
description = "Display manager to use";
@ -198,9 +199,7 @@ services.xserver.displayManager.enable = mkOption {
:::
::: {#ex-option-declaration-eot-backend-gdm .example}
::: {.title}
**Example: Extending `services.xserver.displayManager.enable` in the `gdm` module**
:::
```nix
services.xserver.displayManager.enable = mkOption {
type = with types; nullOr (enum [ "gdm" ]);
@ -209,9 +208,7 @@ services.xserver.displayManager.enable = mkOption {
:::
::: {#ex-option-declaration-eot-backend-sddm .example}
::: {.title}
**Example: Extending `services.xserver.displayManager.enable` in the `sddm` module**
:::
```nix
services.xserver.displayManager.enable = mkOption {
type = with types; nullOr (enum [ "sddm" ]);

View File

@ -12,7 +12,7 @@ config = {
However, sometimes you need to wrap an option definition or set of
option definitions in a *property* to achieve certain effects:
## Delaying Conditionals {#sec-option-definitions-delaying-conditionals .unnumbered}
## Delaying Conditionals {#sec-option-definitions-delaying-conditionals}
If a set of option definitions is conditional on the value of another
option, you may need to use `mkIf`. Consider, for instance:
@ -56,7 +56,7 @@ config = {
};
```
## Setting Priorities {#sec-option-definitions-setting-priorities .unnumbered}
## Setting Priorities {#sec-option-definitions-setting-priorities}
A module can override the definitions of an option in other modules by
setting an *override priority*. All option definitions that do not have the lowest
@ -72,7 +72,7 @@ This definition causes all other definitions with priorities above 10 to
be discarded. The function `mkForce` is equal to `mkOverride 50`, and
`mkDefault` is equal to `mkOverride 1000`.
## Ordering Definitions {#sec-option-definitions-ordering .unnumbered}
## Ordering Definitions {#sec-option-definitions-ordering}
It is also possible to influence the order in which the definitions for an option are
merged by setting an *order priority* with `mkOrder`. The default order priority is 1000.
@ -89,7 +89,7 @@ definitions in the final list value of `hardware.firmware`.
Note that this is different from [override priorities](#sec-option-definitions-setting-priorities):
setting an order does not affect whether the definition is included or not.
## Merging Configurations {#sec-option-definitions-merging .unnumbered}
## Merging Configurations {#sec-option-definitions-merging}
In conjunction with `mkIf`, it is sometimes useful for a module to
return multiple sets of option definitions, to be merged together as if

View File

@ -36,9 +36,8 @@ merging is handled.
together. This type is recommended when the option type is unknown.
::: {#ex-types-anything .example}
::: {.title}
**Example: `types.anything` Example**
:::
Two definitions of this type like
```nix
@ -357,9 +356,7 @@ you will still need to provide a default value (e.g. an empty attribute set)
if you want to allow users to leave it undefined.
::: {#ex-submodule-direct .example}
::: {.title}
**Example: Directly defined submodule**
:::
```nix
options.mod = mkOption {
description = "submodule example";
@ -378,9 +375,7 @@ options.mod = mkOption {
:::
::: {#ex-submodule-reference .example}
::: {.title}
**Example: Submodule defined as a reference**
:::
```nix
let
modOptions = {
@ -408,9 +403,7 @@ multiple definitions of the submodule option set
([Example: Definition of a list of submodules](#ex-submodule-listof-definition)).
::: {#ex-submodule-listof-declaration .example}
::: {.title}
**Example: Declaration of a list of submodules**
:::
```nix
options.mod = mkOption {
description = "submodule example";
@ -429,9 +422,7 @@ options.mod = mkOption {
:::
::: {#ex-submodule-listof-definition .example}
::: {.title}
**Example: Definition of a list of submodules**
:::
```nix
config.mod = [
{ foo = 1; bar = "one"; }
@ -446,9 +437,7 @@ multiple named definitions of the submodule option set
([Example: Definition of attribute sets of submodules](#ex-submodule-attrsof-definition)).
::: {#ex-submodule-attrsof-declaration .example}
::: {.title}
**Example: Declaration of attribute sets of submodules**
:::
```nix
options.mod = mkOption {
description = "submodule example";
@ -467,9 +456,7 @@ options.mod = mkOption {
:::
::: {#ex-submodule-attrsof-definition .example}
::: {.title}
**Example: Definition of attribute sets of submodules**
:::
```nix
config.mod.one = { foo = 1; bar = "one"; };
config.mod.two = { foo = 2; bar = "two"; };
@ -489,9 +476,8 @@ Types are mainly characterized by their `check` and `merge` functions.
([Example: Overriding a type check](#ex-extending-type-check-2)).
::: {#ex-extending-type-check-1 .example}
::: {.title}
**Example: Adding a type check**
:::
```nix
byte = mkOption {
description = "An integer between 0 and 255.";
@ -501,9 +487,8 @@ Types are mainly characterized by their `check` and `merge` functions.
:::
::: {#ex-extending-type-check-2 .example}
::: {.title}
**Example: Overriding a type check**
:::
```nix
nixThings = mkOption {
description = "words that start with 'nix'";

View File

@ -119,9 +119,8 @@ have a predefined type and string generator already declared under
default Elixir keyword list
::: {#pkgs-formats-result}
[]{#pkgs-formats-result}
These functions all return an attribute set with these values:
:::
`type`
@ -144,9 +143,8 @@ These functions all return an attribute set with these values:
:::
::: {#ex-settings-nix-representable .example}
::: {.title}
**Example: Module with conventional `settings` option**
:::
The following shows a module for an example program that uses a JSON
configuration file. It demonstrates how above values can be used, along
with some other related best practices. See the comments for
@ -220,9 +218,7 @@ the port, which will enforce it to be a valid integer and make it show
up in the manual.
::: {#ex-settings-typed-attrs .example}
::: {.title}
**Example: Declaring a type-checked `settings` attribute**
:::
```nix
settings = lib.mkOption {
type = lib.types.submodule {

View File

@ -37,9 +37,7 @@ options, but does not declare any. The structure of full NixOS modules
is shown in [Example: Structure of NixOS Modules](#ex-module-syntax).
::: {#ex-module-syntax .example}
::: {.title}
**Example: Structure of NixOS Modules**
:::
```nix
{ config, pkgs, ... }:
@ -102,9 +100,7 @@ Exec directives](#exec-escaping-example) for an example. When using these
functions system environment substitution should *not* be disabled explicitly.
::: {#locate-example .example}
::: {.title}
**Example: NixOS Module for the "locate" Service**
:::
```nix
{ config, lib, pkgs, ... }:
@ -165,9 +161,7 @@ in {
:::
::: {#exec-escaping-example .example}
::: {.title}
**Example: Escaping in Exec directives**
:::
```nix
{ config, lib, pkgs, utils, ... }:

View File

@ -417,8 +417,7 @@ with foo_running:
`seconds_interval`
:
specifies how often the condition should be polled:
: specifies how often the condition should be polled:
```py
@polling_condition(seconds_interval=10)
@ -428,8 +427,7 @@ def foo_running():
`description`
:
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:
: 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:
```py
@polling_condition

View File

@ -1,5 +0,0 @@
This directory is temporarily needed while we transition the manual to CommonMark. It stores the output of the ../md-to-db.sh script that converts CommonMark files back to DocBook.
We are choosing to convert the Markdown to DocBook at authoring time instead of manual building time, because we do not want the pandoc toolchain to become part of the NixOS closure.
Do not edit the DocBook files inside this directory or its subdirectories. Instead, edit the corresponding .md file in the normal manual directories, and run ../md-to-db.sh to update the file here.

View File

@ -1,144 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-boot-problems">
<title>Boot Problems</title>
<para>
If NixOS fails to boot, there are a number of kernel command line
parameters that may help you to identify or fix the issue. You can
add these parameters in the GRUB boot menu by pressing “e” to modify
the selected boot entry and editing the line starting with
<literal>linux</literal>. The following are some useful kernel
command line parameters that are recognised by the NixOS boot
scripts or by systemd:
</para>
<variablelist>
<varlistentry>
<term>
<literal>boot.shell_on_fail</literal>
</term>
<listitem>
<para>
Allows the user to start a root shell if something goes wrong
in stage 1 of the boot process (the initial ramdisk). This is
disabled by default because there is no authentication for the
root shell.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>boot.debug1</literal>
</term>
<listitem>
<para>
Start an interactive shell in stage 1 before anything useful
has been done. That is, no modules have been loaded and no
file systems have been mounted, except for
<literal>/proc</literal> and <literal>/sys</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>boot.debug1devices</literal>
</term>
<listitem>
<para>
Like <literal>boot.debug1</literal>, but runs stage1 until
kernel modules are loaded and device nodes are created. This
may help with e.g. making the keyboard work.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>boot.debug1mounts</literal>
</term>
<listitem>
<para>
Like <literal>boot.debug1</literal> or
<literal>boot.debug1devices</literal>, but runs stage1 until
all filesystems that are mounted during initrd are mounted
(see
<link linkend="opt-fileSystems._name_.neededForBoot">neededForBoot</link>).
As a motivating example, this could be useful if youve
forgotten to set
<link linkend="opt-fileSystems._name_.neededForBoot">neededForBoot</link>
on a file system.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>boot.trace</literal>
</term>
<listitem>
<para>
Print every shell command executed by the stage 1 and 2 boot
scripts.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>single</literal>
</term>
<listitem>
<para>
Boot into rescue mode (a.k.a. single user mode). This will
cause systemd to start nothing but the unit
<literal>rescue.target</literal>, which runs
<literal>sulogin</literal> to prompt for the root password and
start a root login shell. Exiting the shell causes the system
to continue with the normal boot process.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>systemd.log_level=debug</literal>
<literal>systemd.log_target=console</literal>
</term>
<listitem>
<para>
Make systemd very verbose and send log messages to the console
instead of the journal. For more parameters recognised by
systemd, see systemd(1).
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
In addition, these arguments are recognised by the live image only:
</para>
<variablelist>
<varlistentry>
<term>
<literal>live.nixos.passwd=password</literal>
</term>
<listitem>
<para>
Set the password for the <literal>nixos</literal> live user.
This can be used for SSH access if there are issues using the
terminal.
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
Notice that for <literal>boot.shell_on_fail</literal>,
<literal>boot.debug1</literal>,
<literal>boot.debug1devices</literal>, and
<literal>boot.debug1mounts</literal>, if you did
<emphasis role="strong">not</emphasis> select <quote>start the new
shell as pid 1</quote>, and you <literal>exit</literal> from the new
shell, boot will proceed normally from the point where it failed, as
if youd chosen <quote>ignore the error and continue</quote>.
</para>
<para>
If no login prompts or X11 login screens appear (e.g. due to hanging
dependencies), you can press Alt+ArrowUp. If youre lucky, this will
start rescue mode (described above). (Also note that since most
units have a 90-second timeout before systemd gives up on them, the
<literal>agetty</literal> login prompts should appear eventually
unless something is very wrong.)
</para>
</section>

View File

@ -1,72 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-nix-gc">
<title>Cleaning the Nix Store</title>
<para>
Nix has a purely functional model, meaning that packages are never
upgraded in place. Instead new versions of packages end up in a
different location in the Nix store (<literal>/nix/store</literal>).
You should periodically run Nixs <emphasis>garbage
collector</emphasis> to remove old, unreferenced packages. This is
easy:
</para>
<programlisting>
$ nix-collect-garbage
</programlisting>
<para>
Alternatively, you can use a systemd unit that does the same in the
background:
</para>
<programlisting>
# systemctl start nix-gc.service
</programlisting>
<para>
You can tell NixOS in <literal>configuration.nix</literal> to run
this unit automatically at certain points in time, for instance,
every night at 03:15:
</para>
<programlisting language="nix">
nix.gc.automatic = true;
nix.gc.dates = &quot;03:15&quot;;
</programlisting>
<para>
The commands above do not remove garbage collector roots, such as
old system configurations. Thus they do not remove the ability to
roll back to previous configurations. The following command deletes
old roots, removing the ability to roll back to them:
</para>
<programlisting>
$ nix-collect-garbage -d
</programlisting>
<para>
You can also do this for specific profiles, e.g.
</para>
<programlisting>
$ nix-env -p /nix/var/nix/profiles/per-user/eelco/profile --delete-generations old
</programlisting>
<para>
Note that NixOS system configurations are stored in the profile
<literal>/nix/var/nix/profiles/system</literal>.
</para>
<para>
Another way to reclaim disk space (often as much as 40% of the size
of the Nix store) is to run Nixs store optimiser, which seeks out
identical files in the store and replaces them with hard links to a
single copy.
</para>
<programlisting>
$ nix-store --optimise
</programlisting>
<para>
Since this command needs to read the entire Nix store, it can take
quite a while to finish.
</para>
<section xml:id="sect-nixos-gc-boot-entries">
<title>NixOS Boot Entries</title>
<para>
If your <literal>/boot</literal> partition runs out of space,
after clearing old profiles you must rebuild your system with
<literal>nixos-rebuild boot</literal> or
<literal>nixos-rebuild switch</literal> to update the
<literal>/boot</literal> partition and clear space.
</para>
</section>
</chapter>

View File

@ -1,54 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-container-networking">
<title>Container Networking</title>
<para>
When you create a container using
<literal>nixos-container create</literal>, it gets it own private
IPv4 address in the range <literal>10.233.0.0/16</literal>. You can
get the containers IPv4 address as follows:
</para>
<programlisting>
# nixos-container show-ip foo
10.233.4.2
$ ping -c1 10.233.4.2
64 bytes from 10.233.4.2: icmp_seq=1 ttl=64 time=0.106 ms
</programlisting>
<para>
Networking is implemented using a pair of virtual Ethernet devices.
The network interface in the container is called
<literal>eth0</literal>, while the matching interface in the host is
called <literal>ve-container-name</literal> (e.g.,
<literal>ve-foo</literal>). The container has its own network
namespace and the <literal>CAP_NET_ADMIN</literal> capability, so it
can perform arbitrary network configuration such as setting up
firewall rules, without affecting or having access to the hosts
network.
</para>
<para>
By default, containers cannot talk to the outside network. If you
want that, you should set up Network Address Translation (NAT) rules
on the host to rewrite container traffic to use your external IP
address. This can be accomplished using the following configuration
on the host:
</para>
<programlisting language="nix">
networking.nat.enable = true;
networking.nat.internalInterfaces = [&quot;ve-+&quot;];
networking.nat.externalInterface = &quot;eth0&quot;;
</programlisting>
<para>
where <literal>eth0</literal> should be replaced with the desired
external interface. Note that <literal>ve-+</literal> is a wildcard
that matches all container interfaces.
</para>
<para>
If you are using Network Manager, you need to explicitly prevent it
from managing container interfaces:
</para>
<programlisting language="nix">
networking.networkmanager.unmanaged = [ &quot;interface-name:ve-*&quot; ];
</programlisting>
<para>
You may need to restart your system for the changes to take effect.
</para>
</section>

View File

@ -1,31 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="ch-containers">
<title>Container Management</title>
<para>
NixOS allows you to easily run other NixOS instances as
<emphasis>containers</emphasis>. Containers are a light-weight
approach to virtualisation that runs software in the container at
the same speed as in the host system. NixOS containers share the Nix
store of the host, making container creation very efficient.
</para>
<warning>
<para>
Currently, NixOS containers are not perfectly isolated from the
host system. This means that a user with root access to the
container can do things that affect the host. So you should not
give container root access to untrusted users.
</para>
</warning>
<para>
NixOS containers can be created in two ways: imperatively, using the
command <literal>nixos-container</literal>, and declaratively, by
specifying them in your <literal>configuration.nix</literal>. The
declarative approach implies that containers get upgraded along with
your host system when you run <literal>nixos-rebuild</literal>,
which is often not what you want. By contrast, in the imperative
approach, containers are configured and updated independently from
the host system.
</para>
<xi:include href="imperative-containers.section.xml" />
<xi:include href="declarative-containers.section.xml" />
<xi:include href="container-networking.section.xml" />
</chapter>

View File

@ -1,67 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-cgroups">
<title>Control Groups</title>
<para>
To keep track of the processes in a running system, systemd uses
<emphasis>control groups</emphasis> (cgroups). A control group is a
set of processes used to allocate resources such as CPU, memory or
I/O bandwidth. There can be multiple control group hierarchies,
allowing each kind of resource to be managed independently.
</para>
<para>
The command <literal>systemd-cgls</literal> lists all control groups
in the <literal>systemd</literal> hierarchy, which is what systemd
uses to keep track of the processes belonging to each service or
user session:
</para>
<programlisting>
$ systemd-cgls
├─user
│ └─eelco
│ └─c1
│ ├─ 2567 -:0
│ ├─ 2682 kdeinit4: kdeinit4 Running...
│ ├─ ...
│ └─10851 sh -c less -R
└─system
├─httpd.service
│ ├─2444 httpd -f /nix/store/3pyacby5cpr55a03qwbnndizpciwq161-httpd.conf -DNO_DETACH
│ └─...
├─dhcpcd.service
│ └─2376 dhcpcd --config /nix/store/f8dif8dsi2yaa70n03xir8r653776ka6-dhcpcd.conf
└─ ...
</programlisting>
<para>
Similarly, <literal>systemd-cgls cpu</literal> shows the cgroups in
the CPU hierarchy, which allows per-cgroup CPU scheduling
priorities. By default, every systemd service gets its own CPU
cgroup, while all user sessions are in the top-level CPU cgroup.
This ensures, for instance, that a thousand run-away processes in
the <literal>httpd.service</literal> cgroup cannot starve the CPU
for one process in the <literal>postgresql.service</literal> cgroup.
(By contrast, it they were in the same cgroup, then the PostgreSQL
process would get 1/1001 of the cgroups CPU time.) You can limit a
services CPU share in <literal>configuration.nix</literal>:
</para>
<programlisting language="nix">
systemd.services.httpd.serviceConfig.CPUShares = 512;
</programlisting>
<para>
By default, every cgroup has 1024 CPU shares, so this will halve the
CPU allocation of the <literal>httpd.service</literal> cgroup.
</para>
<para>
There also is a <literal>memory</literal> hierarchy that controls
memory allocation limits; by default, all processes are in the
top-level cgroup, so any service or session can exhaust all
available memory. Per-cgroup memory limits can be specified in
<literal>configuration.nix</literal>; for instance, to limit
<literal>httpd.service</literal> to 512 MiB of RAM (excluding swap):
</para>
<programlisting language="nix">
systemd.services.httpd.serviceConfig.MemoryLimit = &quot;512M&quot;;
</programlisting>
<para>
The command <literal>systemd-cgtop</literal> shows a continuously
updated list of all cgroups with their CPU and memory usage.
</para>
</chapter>

View File

@ -1,60 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-declarative-containers">
<title>Declarative Container Specification</title>
<para>
You can also specify containers and their configuration in the
hosts <literal>configuration.nix</literal>. For example, the
following specifies that there shall be a container named
<literal>database</literal> running PostgreSQL:
</para>
<programlisting language="nix">
containers.database =
{ config =
{ config, pkgs, ... }:
{ services.postgresql.enable = true;
services.postgresql.package = pkgs.postgresql_14;
};
};
</programlisting>
<para>
If you run <literal>nixos-rebuild switch</literal>, the container
will be built. If the container was already running, it will be
updated in place, without rebooting. The container can be configured
to start automatically by setting
<literal>containers.database.autoStart = true</literal> in its
configuration.
</para>
<para>
By default, declarative containers share the network namespace of
the host, meaning that they can listen on (privileged) ports.
However, they cannot change the network configuration. You can give
a container its own network as follows:
</para>
<programlisting language="nix">
containers.database = {
privateNetwork = true;
hostAddress = &quot;192.168.100.10&quot;;
localAddress = &quot;192.168.100.11&quot;;
};
</programlisting>
<para>
This gives the container a private virtual Ethernet interface with
IP address <literal>192.168.100.11</literal>, which is hooked up to
a virtual Ethernet interface on the host with IP address
<literal>192.168.100.10</literal>. (See the next section for details
on container networking.)
</para>
<para>
To disable the container, just remove it from
<literal>configuration.nix</literal> and run
<literal>nixos-rebuild switch</literal>. Note that this will not
delete the root directory of the container in
<literal>/var/lib/nixos-containers</literal>. Containers can be
destroyed using the imperative method:
<literal>nixos-container destroy foo</literal>.
</para>
<para>
Declarative containers can be started and stopped using the
corresponding systemd service, e.g.
<literal>systemctl start container@database</literal>.
</para>
</section>

View File

@ -1,132 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-imperative-containers">
<title>Imperative Container Management</title>
<para>
Well cover imperative container management using
<literal>nixos-container</literal> first. Be aware that container
management is currently only possible as <literal>root</literal>.
</para>
<para>
You create a container with identifier <literal>foo</literal> as
follows:
</para>
<programlisting>
# nixos-container create foo
</programlisting>
<para>
This creates the containers root directory in
<literal>/var/lib/nixos-containers/foo</literal> and a small
configuration file in
<literal>/etc/nixos-containers/foo.conf</literal>. It also builds
the containers initial system configuration and stores it in
<literal>/nix/var/nix/profiles/per-container/foo/system</literal>.
You can modify the initial configuration of the container on the
command line. For instance, to create a container that has
<literal>sshd</literal> running, with the given public key for
<literal>root</literal>:
</para>
<programlisting>
# nixos-container create foo --config '
services.openssh.enable = true;
users.users.root.openssh.authorizedKeys.keys = [&quot;ssh-dss AAAAB3N…&quot;];
'
</programlisting>
<para>
By default the next free address in the
<literal>10.233.0.0/16</literal> subnet will be chosen as container
IP. This behavior can be altered by setting
<literal>--host-address</literal> and
<literal>--local-address</literal>:
</para>
<programlisting>
# nixos-container create test --config-file test-container.nix \
--local-address 10.235.1.2 --host-address 10.235.1.1
</programlisting>
<para>
Creating a container does not start it. To start the container, run:
</para>
<programlisting>
# nixos-container start foo
</programlisting>
<para>
This command will return as soon as the container has booted and has
reached <literal>multi-user.target</literal>. On the host, the
container runs within a systemd unit called
<literal>container@container-name.service</literal>. Thus, if
something went wrong, you can get status info using
<literal>systemctl</literal>:
</para>
<programlisting>
# systemctl status container@foo
</programlisting>
<para>
If the container has started successfully, you can log in as root
using the <literal>root-login</literal> operation:
</para>
<programlisting>
# nixos-container root-login foo
[root@foo:~]#
</programlisting>
<para>
Note that only root on the host can do this (since there is no
authentication). You can also get a regular login prompt using the
<literal>login</literal> operation, which is available to all users
on the host:
</para>
<programlisting>
# nixos-container login foo
foo login: alice
Password: ***
</programlisting>
<para>
With <literal>nixos-container run</literal>, you can execute
arbitrary commands in the container:
</para>
<programlisting>
# nixos-container run foo -- uname -a
Linux foo 3.4.82 #1-NixOS SMP Thu Mar 20 14:44:05 UTC 2014 x86_64 GNU/Linux
</programlisting>
<para>
There are several ways to change the configuration of the container.
First, on the host, you can edit
<literal>/var/lib/container/name/etc/nixos/configuration.nix</literal>,
and run
</para>
<programlisting>
# nixos-container update foo
</programlisting>
<para>
This will build and activate the new configuration. You can also
specify a new configuration on the command line:
</para>
<programlisting>
# nixos-container update foo --config '
services.httpd.enable = true;
services.httpd.adminAddr = &quot;foo@example.org&quot;;
networking.firewall.allowedTCPPorts = [ 80 ];
'
# curl http://$(nixos-container show-ip foo)/
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 3.2 Final//EN&quot;&gt;
</programlisting>
<para>
However, note that this will overwrite the containers
<literal>/etc/nixos/configuration.nix</literal>.
</para>
<para>
Alternatively, you can change the configuration from within the
container itself by running <literal>nixos-rebuild switch</literal>
inside the container. Note that the container by default does not
have a copy of the NixOS channel, so you should run
<literal>nix-channel --update</literal> first.
</para>
<para>
Containers can be stopped and started using
<literal>nixos-container stop</literal> and
<literal>nixos-container start</literal>, respectively, or by using
<literal>systemctl</literal> on the containers service unit. To
destroy a container, including its file system, do
</para>
<programlisting>
# nixos-container destroy foo
</programlisting>
</section>

View File

@ -1,45 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-logging">
<title>Logging</title>
<para>
System-wide logging is provided by systemds
<emphasis>journal</emphasis>, which subsumes traditional logging
daemons such as syslogd and klogd. Log entries are kept in binary
files in <literal>/var/log/journal/</literal>. The command
<literal>journalctl</literal> allows you to see the contents of the
journal. For example,
</para>
<programlisting>
$ journalctl -b
</programlisting>
<para>
shows all journal entries since the last reboot. (The output of
<literal>journalctl</literal> is piped into <literal>less</literal>
by default.) You can use various options and match operators to
restrict output to messages of interest. For instance, to get all
messages from PostgreSQL:
</para>
<programlisting>
$ journalctl -u postgresql.service
-- Logs begin at Mon, 2013-01-07 13:28:01 CET, end at Tue, 2013-01-08 01:09:57 CET. --
...
Jan 07 15:44:14 hagbard postgres[2681]: [2-1] LOG: database system is shut down
-- Reboot --
Jan 07 15:45:10 hagbard postgres[2532]: [1-1] LOG: database system was shut down at 2013-01-07 15:44:14 CET
Jan 07 15:45:13 hagbard postgres[2500]: [1-1] LOG: database system is ready to accept connections
</programlisting>
<para>
Or to get all messages since the last reboot that have at least a
<quote>critical</quote> severity level:
</para>
<programlisting>
$ journalctl -b -p crit
Dec 17 21:08:06 mandark sudo[3673]: pam_unix(sudo:auth): auth could not identify password for [alice]
Dec 29 01:30:22 mandark kernel[6131]: [1053513.909444] CPU6: Core temperature above threshold, cpu clock throttled (total events = 1)
</programlisting>
<para>
The system journal is readable by root and by users in the
<literal>wheel</literal> and <literal>systemd-journal</literal>
groups. All users have a private journal that can be read using
<literal>journalctl</literal>.
</para>
</chapter>

View File

@ -1,14 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-maintenance-mode">
<title>Maintenance Mode</title>
<para>
You can enter rescue mode by running:
</para>
<programlisting>
# systemctl rescue
</programlisting>
<para>
This will eventually give you a single-user root shell. Systemd will
stop (almost) all system services. To get out of maintenance mode,
just exit from the rescue shell.
</para>
</section>

View File

@ -1,25 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-nix-network-issues">
<title>Network Problems</title>
<para>
Nix uses a so-called <emphasis>binary cache</emphasis> to optimise
building a package from source into downloading it as a pre-built
binary. That is, whenever a command like
<literal>nixos-rebuild</literal> needs a path in the Nix store, Nix
will try to download that path from the Internet rather than build
it from source. The default binary cache is
<literal>https://cache.nixos.org/</literal>. If this cache is
unreachable, Nix operations may take a long time due to HTTP
connection timeouts. You can disable the use of the binary cache by
adding <literal>--option use-binary-caches false</literal>, e.g.
</para>
<programlisting>
# nixos-rebuild switch --option use-binary-caches false
</programlisting>
<para>
If you have an alternative binary cache at your disposal, you can
use it instead:
</para>
<programlisting>
# nixos-rebuild switch --option binary-caches http://my-cache.example.org/
</programlisting>
</section>

View File

@ -1,38 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-rebooting">
<title>Rebooting and Shutting Down</title>
<para>
The system can be shut down (and automatically powered off) by
doing:
</para>
<programlisting>
# shutdown
</programlisting>
<para>
This is equivalent to running <literal>systemctl poweroff</literal>.
</para>
<para>
To reboot the system, run
</para>
<programlisting>
# reboot
</programlisting>
<para>
which is equivalent to <literal>systemctl reboot</literal>.
Alternatively, you can quickly reboot the system using
<literal>kexec</literal>, which bypasses the BIOS by directly
loading the new kernel into memory:
</para>
<programlisting>
# systemctl kexec
</programlisting>
<para>
The machine can be suspended to RAM (if supported) using
<literal>systemctl suspend</literal>, and suspended to disk using
<literal>systemctl hibernate</literal>.
</para>
<para>
These commands can be run by any user who is logged in locally, i.e.
on a virtual console or in X11; otherwise, the user is asked for
authentication.
</para>
</chapter>

View File

@ -1,42 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-rollback">
<title>Rolling Back Configuration Changes</title>
<para>
After running <literal>nixos-rebuild</literal> to switch to a new
configuration, you may find that the new configuration doesnt work
very well. In that case, there are several ways to return to a
previous configuration.
</para>
<para>
First, the GRUB boot manager allows you to boot into any previous
configuration that hasnt been garbage-collected. These
configurations can be found under the GRUB submenu <quote>NixOS -
All configurations</quote>. This is especially useful if the new
configuration fails to boot. After the system has booted, you can
make the selected configuration the default for subsequent boots:
</para>
<programlisting>
# /run/current-system/bin/switch-to-configuration boot
</programlisting>
<para>
Second, you can switch to the previous configuration in a running
system:
</para>
<programlisting>
# nixos-rebuild switch --rollback
</programlisting>
<para>
This is equivalent to running:
</para>
<programlisting>
# /nix/var/nix/profiles/system-N-link/bin/switch-to-configuration switch
</programlisting>
<para>
where <literal>N</literal> is the number of the NixOS system
configuration. To get a list of the available configurations, do:
</para>
<programlisting>
$ ls -l /nix/var/nix/profiles/system-*-link
...
lrwxrwxrwx 1 root root 78 Aug 12 13:54 /nix/var/nix/profiles/system-268-link -&gt; /nix/store/202b...-nixos-13.07pre4932_5a676e4-4be1055
</programlisting>
</section>

View File

@ -1,141 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-systemctl">
<title>Service Management</title>
<para>
In NixOS, all system services are started and monitored using the
systemd program. systemd is the <quote>init</quote> process of the
system (i.e. PID 1), the parent of all other processes. It manages a
set of so-called <quote>units</quote>, which can be things like
system services (programs), but also mount points, swap files,
devices, targets (groups of units) and more. Units can have complex
dependencies; for instance, one unit can require that another unit
must be successfully started before the first unit can be started.
When the system boots, it starts a unit named
<literal>default.target</literal>; the dependencies of this unit
cause all system services to be started, file systems to be mounted,
swap files to be activated, and so on.
</para>
<section xml:id="sect-nixos-systemd-general">
<title>Interacting with a running systemd</title>
<para>
The command <literal>systemctl</literal> is the main way to
interact with <literal>systemd</literal>. The following paragraphs
demonstrate ways to interact with any OS running systemd as init
system. NixOS is of no exception. The
<link linkend="sect-nixos-systemd-nixos">next section </link>
explains NixOS specific things worth knowing.
</para>
<para>
Without any arguments, <literal>systemctl</literal> the status of
active units:
</para>
<programlisting>
$ systemctl
-.mount loaded active mounted /
swapfile.swap loaded active active /swapfile
sshd.service loaded active running SSH Daemon
graphical.target loaded active active Graphical Interface
...
</programlisting>
<para>
You can ask for detailed status information about a unit, for
instance, the PostgreSQL database service:
</para>
<programlisting>
$ systemctl status postgresql.service
postgresql.service - PostgreSQL Server
Loaded: loaded (/nix/store/pn3q73mvh75gsrl8w7fdlfk3fq5qm5mw-unit/postgresql.service)
Active: active (running) since Mon, 2013-01-07 15:55:57 CET; 9h ago
Main PID: 2390 (postgres)
CGroup: name=systemd:/system/postgresql.service
├─2390 postgres
├─2418 postgres: writer process
├─2419 postgres: wal writer process
├─2420 postgres: autovacuum launcher process
├─2421 postgres: stats collector process
└─2498 postgres: zabbix zabbix [local] idle
Jan 07 15:55:55 hagbard postgres[2394]: [1-1] LOG: database system was shut down at 2013-01-07 15:55:05 CET
Jan 07 15:55:57 hagbard postgres[2390]: [1-1] LOG: database system is ready to accept connections
Jan 07 15:55:57 hagbard postgres[2420]: [1-1] LOG: autovacuum launcher started
Jan 07 15:55:57 hagbard systemd[1]: Started PostgreSQL Server.
</programlisting>
<para>
Note that this shows the status of the unit (active and running),
all the processes belonging to the service, as well as the most
recent log messages from the service.
</para>
<para>
Units can be stopped, started or restarted:
</para>
<programlisting>
# systemctl stop postgresql.service
# systemctl start postgresql.service
# systemctl restart postgresql.service
</programlisting>
<para>
These operations are synchronous: they wait until the service has
finished starting or stopping (or has failed). Starting a unit
will cause the dependencies of that unit to be started as well (if
necessary).
</para>
</section>
<section xml:id="sect-nixos-systemd-nixos">
<title>systemd in NixOS</title>
<para>
Packages in Nixpkgs sometimes provide systemd units with them,
usually in e.g <literal>#pkg-out#/lib/systemd/</literal>. Putting
such a package in <literal>environment.systemPackages</literal>
doesnt make the service available to users or the system.
</para>
<para>
In order to enable a systemd <emphasis>system</emphasis> service
with provided upstream package, use (e.g):
</para>
<programlisting language="nix">
systemd.packages = [ pkgs.packagekit ];
</programlisting>
<para>
Usually NixOS modules written by the community do the above, plus
take care of other details. If a module was written for a service
you are interested in, youd probably need only to use
<literal>services.#name#.enable = true;</literal>. These services
are defined in Nixpkgs
<link xlink:href="https://github.com/NixOS/nixpkgs/tree/master/nixos/modules">
<literal>nixos/modules/</literal> directory </link>. In case the
service is simple enough, the above method should work, and start
the service on boot.
</para>
<para>
<emphasis>User</emphasis> systemd services on the other hand,
should be treated differently. Given a package that has a systemd
unit file at <literal>#pkg-out#/lib/systemd/user/</literal>, using
<xref linkend="opt-systemd.packages" /> will make you able to
start the service via <literal>systemctl --user start</literal>,
but it wont start automatically on login. However, You can
imperatively enable it by adding the packages attribute to
<xref linkend="opt-systemd.packages" /> and then do this (e.g):
</para>
<programlisting>
$ mkdir -p ~/.config/systemd/user/default.target.wants
$ ln -s /run/current-system/sw/lib/systemd/user/syncthing.service ~/.config/systemd/user/default.target.wants/
$ systemctl --user daemon-reload
$ systemctl --user enable syncthing.service
</programlisting>
<para>
If you are interested in a timer file, use
<literal>timers.target.wants</literal> instead of
<literal>default.target.wants</literal> in the 1st and 2nd
command.
</para>
<para>
Using <literal>systemctl --user enable syncthing.service</literal>
instead of the above, will work, but itll use the absolute path
of <literal>syncthing.service</literal> for the symlink, and this
path is in <literal>/nix/store/.../lib/systemd/user/</literal>.
Hence <link linkend="sec-nix-gc">garbage collection</link> will
remove that file and you will wind up with a broken symlink in
your systemd configuration, which in turn will not make the
service / timer start on login.
</para>
</section>
</chapter>

View File

@ -1,34 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-nix-store-corruption">
<title>Nix Store Corruption</title>
<para>
After a system crash, its possible for files in the Nix store to
become corrupted. (For instance, the Ext4 file system has the
tendency to replace un-synced files with zero bytes.) NixOS tries
hard to prevent this from happening: it performs a
<literal>sync</literal> before switching to a new configuration, and
Nixs database is fully transactional. If corruption still occurs,
you may be able to fix it automatically.
</para>
<para>
If the corruption is in a path in the closure of the NixOS system
configuration, you can fix it by doing
</para>
<programlisting>
# nixos-rebuild switch --repair
</programlisting>
<para>
This will cause Nix to check every path in the closure, and if its
cryptographic hash differs from the hash recorded in Nixs database,
the path is rebuilt or redownloaded.
</para>
<para>
You can also scan the entire Nix store for corrupt paths:
</para>
<programlisting>
# nix-store --verify --check-contents --repair
</programlisting>
<para>
Any corrupt paths will be redownloaded if theyre available in a
binary cache; otherwise, they cannot be repaired.
</para>
</section>

View File

@ -1,12 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="ch-troubleshooting">
<title>Troubleshooting</title>
<para>
This chapter describes solutions to common problems you might
encounter when you manage your NixOS system.
</para>
<xi:include href="boot-problems.section.xml" />
<xi:include href="maintenance-mode.section.xml" />
<xi:include href="rollback.section.xml" />
<xi:include href="store-corruption.section.xml" />
<xi:include href="network-problems.section.xml" />
</chapter>

View File

@ -1,46 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-user-sessions">
<title>User Sessions</title>
<para>
Systemd keeps track of all users who are logged into the system
(e.g. on a virtual console or remotely via SSH). The command
<literal>loginctl</literal> allows querying and manipulating user
sessions. For instance, to list all user sessions:
</para>
<programlisting>
$ loginctl
SESSION UID USER SEAT
c1 500 eelco seat0
c3 0 root seat0
c4 500 alice
</programlisting>
<para>
This shows that two users are logged in locally, while another is
logged in remotely. (<quote>Seats</quote> are essentially the
combinations of displays and input devices attached to the system;
usually, there is only one seat.) To get information about a
session:
</para>
<programlisting>
$ loginctl session-status c3
c3 - root (0)
Since: Tue, 2013-01-08 01:17:56 CET; 4min 42s ago
Leader: 2536 (login)
Seat: seat0; vc3
TTY: /dev/tty3
Service: login; type tty; class user
State: online
CGroup: name=systemd:/user/root/c3
├─ 2536 /nix/store/10mn4xip9n7y9bxqwnsx7xwx2v2g34xn-shadow-4.1.5.1/bin/login --
├─10339 -bash
└─10355 w3m nixos.org
</programlisting>
<para>
This shows that the user is logged in on virtual console 3. It also
lists the processes belonging to this session. Since systemd keeps
track of this, you can terminate a session in a way that ensures
that all the sessions processes are gone:
</para>
<programlisting>
# loginctl terminate-session c3
</programlisting>
</chapter>

View File

@ -1,101 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-module-abstractions">
<title>Abstractions</title>
<para>
If you find yourself repeating yourself over and over, its time to
abstract. Take, for instance, this Apache HTTP Server configuration:
</para>
<programlisting language="nix">
{
services.httpd.virtualHosts =
{ &quot;blog.example.org&quot; = {
documentRoot = &quot;/webroot/blog.example.org&quot;;
adminAddr = &quot;alice@example.org&quot;;
forceSSL = true;
enableACME = true;
enablePHP = true;
};
&quot;wiki.example.org&quot; = {
documentRoot = &quot;/webroot/wiki.example.org&quot;;
adminAddr = &quot;alice@example.org&quot;;
forceSSL = true;
enableACME = true;
enablePHP = true;
};
};
}
</programlisting>
<para>
It defines two virtual hosts with nearly identical configuration;
the only difference is the document root directories. To prevent
this duplication, we can use a <literal>let</literal>:
</para>
<programlisting language="nix">
let
commonConfig =
{ adminAddr = &quot;alice@example.org&quot;;
forceSSL = true;
enableACME = true;
};
in
{
services.httpd.virtualHosts =
{ &quot;blog.example.org&quot; = (commonConfig // { documentRoot = &quot;/webroot/blog.example.org&quot;; });
&quot;wiki.example.org&quot; = (commonConfig // { documentRoot = &quot;/webroot/wiki.example.com&quot;; });
};
}
</programlisting>
<para>
The <literal>let commonConfig = ...</literal> defines a variable
named <literal>commonConfig</literal>. The <literal>//</literal>
operator merges two attribute sets, so the configuration of the
second virtual host is the set <literal>commonConfig</literal>
extended with the document root option.
</para>
<para>
You can write a <literal>let</literal> wherever an expression is
allowed. Thus, you also could have written:
</para>
<programlisting language="nix">
{
services.httpd.virtualHosts =
let commonConfig = ...; in
{ &quot;blog.example.org&quot; = (commonConfig // { ... })
&quot;wiki.example.org&quot; = (commonConfig // { ... })
};
}
</programlisting>
<para>
but not <literal>{ let commonConfig = ...; in ...; }</literal> since
attributes (as opposed to attribute values) are not expressions.
</para>
<para>
<emphasis role="strong">Functions</emphasis> provide another method
of abstraction. For instance, suppose that we want to generate lots
of different virtual hosts, all with identical configuration except
for the document root. This can be done as follows:
</para>
<programlisting language="nix">
{
services.httpd.virtualHosts =
let
makeVirtualHost = webroot:
{ documentRoot = webroot;
adminAddr = &quot;alice@example.org&quot;;
forceSSL = true;
enableACME = true;
};
in
{ &quot;example.org&quot; = (makeVirtualHost &quot;/webroot/example.org&quot;);
&quot;example.com&quot; = (makeVirtualHost &quot;/webroot/example.com&quot;);
&quot;example.gov&quot; = (makeVirtualHost &quot;/webroot/example.gov&quot;);
&quot;example.nl&quot; = (makeVirtualHost &quot;/webroot/example.nl&quot;);
};
}
</programlisting>
<para>
Here, <literal>makeVirtualHost</literal> is a function that takes a
single argument <literal>webroot</literal> and returns the
configuration for a virtual host. That function is then called for
several names to produce the list of virtual host configurations.
</para>
</section>

View File

@ -1,16 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="ad-hoc-network-config">
<title>Ad-Hoc Configuration</title>
<para>
You can use <xref linkend="opt-networking.localCommands" /> to
specify shell commands to be run at the end of
<literal>network-setup.service</literal>. This is useful for doing
network configuration not covered by the existing NixOS modules. For
instance, to statically configure an IPv6 address:
</para>
<programlisting language="nix">
networking.localCommands =
''
ip -6 addr add 2001:610:685:1::1/64 dev eth0
'';
</programlisting>
</section>

View File

@ -1,59 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-ad-hoc-packages">
<title>Ad-Hoc Package Management</title>
<para>
With the command <literal>nix-env</literal>, you can install and
uninstall packages from the command line. For instance, to install
Mozilla Thunderbird:
</para>
<programlisting>
$ nix-env -iA nixos.thunderbird
</programlisting>
<para>
If you invoke this as root, the package is installed in the Nix
profile <literal>/nix/var/nix/profiles/default</literal> and visible
to all users of the system; otherwise, the package ends up in
<literal>/nix/var/nix/profiles/per-user/username/profile</literal>
and is not visible to other users. The <literal>-A</literal> flag
specifies the package by its attribute name; without it, the package
is installed by matching against its package name (e.g.
<literal>thunderbird</literal>). The latter is slower because it
requires matching against all available Nix packages, and is
ambiguous if there are multiple matching packages.
</para>
<para>
Packages come from the NixOS channel. You typically upgrade a
package by updating to the latest version of the NixOS channel:
</para>
<programlisting>
$ nix-channel --update nixos
</programlisting>
<para>
and then running <literal>nix-env -i</literal> again. Other packages
in the profile are <emphasis>not</emphasis> affected; this is the
crucial difference with the declarative style of package management,
where running <literal>nixos-rebuild switch</literal> causes all
packages to be updated to their current versions in the NixOS
channel. You can however upgrade all packages for which there is a
newer version by doing:
</para>
<programlisting>
$ nix-env -u '*'
</programlisting>
<para>
A package can be uninstalled using the <literal>-e</literal> flag:
</para>
<programlisting>
$ nix-env -e thunderbird
</programlisting>
<para>
Finally, you can roll back an undesirable <literal>nix-env</literal>
action:
</para>
<programlisting>
$ nix-env --rollback
</programlisting>
<para>
<literal>nix-env</literal> has many more flags. For details, see the
nix-env(1) manpage or the Nix manual.
</para>
</section>

View File

@ -1,118 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-custom-packages">
<title>Adding Custom Packages</title>
<para>
Its possible that a package you need is not available in NixOS. In
that case, you can do two things. Either you can package it with
Nix, or you can try to use prebuilt packages from upstream. Due to
the peculiarities of NixOS, it is important to note that building
software from source is often easier than using pre-built
executables.
</para>
<section xml:id="sec-custom-packages-nix">
<title>Building with Nix</title>
<para>
This can be done either in-tree or out-of-tree. For an in-tree
build, you can clone the Nixpkgs repository, add the package to
your clone, and (optionally) submit a patch or pull request to
have it accepted into the main Nixpkgs repository. This is
described in detail in the
<link xlink:href="https://nixos.org/nixpkgs/manual">Nixpkgs
manual</link>. In short, you clone Nixpkgs:
</para>
<programlisting>
$ git clone https://github.com/NixOS/nixpkgs
$ cd nixpkgs
</programlisting>
<para>
Then you write and test the package as described in the Nixpkgs
manual. Finally, you add it to
<xref linkend="opt-environment.systemPackages" />, e.g.
</para>
<programlisting language="nix">
environment.systemPackages = [ pkgs.my-package ];
</programlisting>
<para>
and you run <literal>nixos-rebuild</literal>, specifying your own
Nixpkgs tree:
</para>
<programlisting>
# nixos-rebuild switch -I nixpkgs=/path/to/my/nixpkgs
</programlisting>
<para>
The second possibility is to add the package outside of the
Nixpkgs tree. For instance, here is how you specify a build of the
<link xlink:href="https://www.gnu.org/software/hello/">GNU
Hello</link> package directly in
<literal>configuration.nix</literal>:
</para>
<programlisting language="nix">
environment.systemPackages =
let
my-hello = with pkgs; stdenv.mkDerivation rec {
name = &quot;hello-2.8&quot;;
src = fetchurl {
url = &quot;mirror://gnu/hello/${name}.tar.gz&quot;;
sha256 = &quot;0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6&quot;;
};
};
in
[ my-hello ];
</programlisting>
<para>
Of course, you can also move the definition of
<literal>my-hello</literal> into a separate Nix expression, e.g.
</para>
<programlisting language="nix">
environment.systemPackages = [ (import ./my-hello.nix) ];
</programlisting>
<para>
where <literal>my-hello.nix</literal> contains:
</para>
<programlisting language="nix">
with import &lt;nixpkgs&gt; {}; # bring all of Nixpkgs into scope
stdenv.mkDerivation rec {
name = &quot;hello-2.8&quot;;
src = fetchurl {
url = &quot;mirror://gnu/hello/${name}.tar.gz&quot;;
sha256 = &quot;0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6&quot;;
};
}
</programlisting>
<para>
This allows testing the package easily:
</para>
<programlisting>
$ nix-build my-hello.nix
$ ./result/bin/hello
Hello, world!
</programlisting>
</section>
<section xml:id="sec-custom-packages-prebuilt">
<title>Using pre-built executables</title>
<para>
Most pre-built executables will not work on NixOS. There are two
notable exceptions: flatpaks and AppImages. For flatpaks see the
<link linkend="module-services-flatpak">dedicated section</link>.
AppImages will not run <quote>as-is</quote> on NixOS. First you
need to install <literal>appimage-run</literal>: add to
<literal>/etc/nixos/configuration.nix</literal>
</para>
<programlisting language="nix">
environment.systemPackages = [ pkgs.appimage-run ];
</programlisting>
<para>
Then instead of running the AppImage <quote>as-is</quote>, run
<literal>appimage-run foo.appimage</literal>.
</para>
<para>
To make other pre-built executables work on NixOS, you need to
package them with Nix and special helpers like
<literal>autoPatchelfHook</literal> or
<literal>buildFHSUserEnv</literal>. See the
<link xlink:href="https://nixos.org/nixpkgs/manual">Nixpkgs
manual</link> for details. This is complex and often doing a
source build is easier.
</para>
</section>
</section>

View File

@ -1,231 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-configuration-file">
<title>NixOS Configuration File</title>
<para>
The NixOS configuration file generally looks like this:
</para>
<programlisting language="nix">
{ config, pkgs, ... }:
{ option definitions
}
</programlisting>
<para>
The first line (<literal>{ config, pkgs, ... }:</literal>) denotes
that this is actually a function that takes at least the two
arguments <literal>config</literal> and <literal>pkgs</literal>.
(These are explained later, in chapter
<xref linkend="sec-writing-modules" />) The function returns a
<emphasis>set</emphasis> of option definitions
(<literal>{ ... }</literal>). These definitions have the form
<literal>name = value</literal>, where <literal>name</literal> is
the name of an option and <literal>value</literal> is its value. For
example,
</para>
<programlisting language="nix">
{ config, pkgs, ... }:
{ services.httpd.enable = true;
services.httpd.adminAddr = &quot;alice@example.org&quot;;
services.httpd.virtualHosts.localhost.documentRoot = &quot;/webroot&quot;;
}
</programlisting>
<para>
defines a configuration with three option definitions that together
enable the Apache HTTP Server with <literal>/webroot</literal> as
the document root.
</para>
<para>
Sets can be nested, and in fact dots in option names are shorthand
for defining a set containing another set. For instance,
<xref linkend="opt-services.httpd.enable" /> defines a set named
<literal>services</literal> that contains a set named
<literal>httpd</literal>, which in turn contains an option
definition named <literal>enable</literal> with value
<literal>true</literal>. This means that the example above can also
be written as:
</para>
<programlisting language="nix">
{ config, pkgs, ... }:
{ services = {
httpd = {
enable = true;
adminAddr = &quot;alice@example.org&quot;;
virtualHosts = {
localhost = {
documentRoot = &quot;/webroot&quot;;
};
};
};
};
}
</programlisting>
<para>
which may be more convenient if you have lots of option definitions
that share the same prefix (such as
<literal>services.httpd</literal>).
</para>
<para>
NixOS checks your option definitions for correctness. For instance,
if you try to define an option that doesnt exist (that is, doesnt
have a corresponding <emphasis>option declaration</emphasis>),
<literal>nixos-rebuild</literal> will give an error like:
</para>
<programlisting>
The option `services.httpd.enable' defined in `/etc/nixos/configuration.nix' does not exist.
</programlisting>
<para>
Likewise, values in option definitions must have a correct type. For
instance, <literal>services.httpd.enable</literal> must be a Boolean
(<literal>true</literal> or <literal>false</literal>). Trying to
give it a value of another type, such as a string, will cause an
error:
</para>
<programlisting>
The option value `services.httpd.enable' in `/etc/nixos/configuration.nix' is not a boolean.
</programlisting>
<para>
Options have various types of values. The most important are:
</para>
<variablelist>
<varlistentry>
<term>
Strings
</term>
<listitem>
<para>
Strings are enclosed in double quotes, e.g.
</para>
<programlisting language="nix">
networking.hostName = &quot;dexter&quot;;
</programlisting>
<para>
Special characters can be escaped by prefixing them with a
backslash (e.g. <literal>\&quot;</literal>).
</para>
<para>
Multi-line strings can be enclosed in <emphasis>double single
quotes</emphasis>, e.g.
</para>
<programlisting language="nix">
networking.extraHosts =
''
127.0.0.2 other-localhost
10.0.0.1 server
'';
</programlisting>
<para>
The main difference is that it strips from each line a number
of spaces equal to the minimal indentation of the string as a
whole (disregarding the indentation of empty lines), and that
characters like <literal>&quot;</literal> and
<literal>\</literal> are not special (making it more
convenient for including things like shell code). See more
info about this in the Nix manual
<link xlink:href="https://nixos.org/nix/manual/#ssec-values">here</link>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
Booleans
</term>
<listitem>
<para>
These can be <literal>true</literal> or
<literal>false</literal>, e.g.
</para>
<programlisting language="nix">
networking.firewall.enable = true;
networking.firewall.allowPing = false;
</programlisting>
</listitem>
</varlistentry>
<varlistentry>
<term>
Integers
</term>
<listitem>
<para>
For example,
</para>
<programlisting language="nix">
boot.kernel.sysctl.&quot;net.ipv4.tcp_keepalive_time&quot; = 60;
</programlisting>
<para>
(Note that here the attribute name
<literal>net.ipv4.tcp_keepalive_time</literal> is enclosed in
quotes to prevent it from being interpreted as a set named
<literal>net</literal> containing a set named
<literal>ipv4</literal>, and so on. This is because its not a
NixOS option but the literal name of a Linux kernel setting.)
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
Sets
</term>
<listitem>
<para>
Sets were introduced above. They are name/value pairs enclosed
in braces, as in the option definition
</para>
<programlisting language="nix">
fileSystems.&quot;/boot&quot; =
{ device = &quot;/dev/sda1&quot;;
fsType = &quot;ext4&quot;;
options = [ &quot;rw&quot; &quot;data=ordered&quot; &quot;relatime&quot; ];
};
</programlisting>
</listitem>
</varlistentry>
<varlistentry>
<term>
Lists
</term>
<listitem>
<para>
The important thing to note about lists is that list elements
are separated by whitespace, like this:
</para>
<programlisting language="nix">
boot.kernelModules = [ &quot;fuse&quot; &quot;kvm-intel&quot; &quot;coretemp&quot; ];
</programlisting>
<para>
List elements can be any other type, e.g. sets:
</para>
<programlisting language="nix">
swapDevices = [ { device = &quot;/dev/disk/by-label/swap&quot;; } ];
</programlisting>
</listitem>
</varlistentry>
<varlistentry>
<term>
Packages
</term>
<listitem>
<para>
Usually, the packages you need are already part of the Nix
Packages collection, which is a set that can be accessed
through the function argument <literal>pkgs</literal>. Typical
uses:
</para>
<programlisting language="nix">
environment.systemPackages =
[ pkgs.thunderbird
pkgs.emacs
];
services.postgresql.package = pkgs.postgresql_14;
</programlisting>
<para>
The latter option definition changes the default PostgreSQL
package used by NixOSs PostgreSQL service to 14.x. For more
information on packages, including how to add new ones, see
<xref linkend="sec-custom-packages" />.
</para>
</listitem>
</varlistentry>
</variablelist>
</section>

View File

@ -1,20 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="sec-configuration-syntax">
<title>Configuration Syntax</title>
<para>
The NixOS configuration file
<literal>/etc/nixos/configuration.nix</literal> is actually a
<emphasis>Nix expression</emphasis>, which is the Nix package
managers purely functional language for describing how to build
packages and configurations. This means you have all the expressive
power of that language at your disposal, including the ability to
abstract over common patterns, which is very useful when managing
complex systems. The syntax and semantics of the Nix language are
fully described in the
<link xlink:href="https://nixos.org/nix/manual/#chap-writing-nix-expressions">Nix
manual</link>, but here we give a short overview of the most
important constructs useful in NixOS configuration files.
</para>
<xi:include href="config-file.section.xml" />
<xi:include href="abstractions.section.xml" />
<xi:include href="modularity.section.xml" />
</chapter>

View File

@ -1,90 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-customising-packages">
<title>Customising Packages</title>
<para>
Some packages in Nixpkgs have options to enable or disable optional
functionality or change other aspects of the package. For instance,
the Firefox wrapper package (which provides Firefox with a set of
plugins such as the Adobe Flash player) has an option to enable the
Google Talk plugin. It can be set in
<literal>configuration.nix</literal> as follows:
<literal>nixpkgs.config.firefox.enableGoogleTalkPlugin = true;</literal>
</para>
<warning>
<para>
Unfortunately, Nixpkgs currently lacks a way to query available
configuration options.
</para>
</warning>
<para>
Apart from high-level options, its possible to tweak a package in
almost arbitrary ways, such as changing or disabling dependencies of
a package. For instance, the Emacs package in Nixpkgs by default has
a dependency on GTK 2. If you want to build it against GTK 3, you
can specify that as follows:
</para>
<programlisting language="nix">
environment.systemPackages = [ (pkgs.emacs.override { gtk = pkgs.gtk3; }) ];
</programlisting>
<para>
The function <literal>override</literal> performs the call to the
Nix function that produces Emacs, with the original arguments
amended by the set of arguments specified by you. So here the
function argument <literal>gtk</literal> gets the value
<literal>pkgs.gtk3</literal>, causing Emacs to depend on GTK 3. (The
parentheses are necessary because in Nix, function application binds
more weakly than list construction, so without them,
<xref linkend="opt-environment.systemPackages" /> would be a list
with two elements.)
</para>
<para>
Even greater customisation is possible using the function
<literal>overrideAttrs</literal>. While the
<literal>override</literal> mechanism above overrides the arguments
of a package function, <literal>overrideAttrs</literal> allows
changing the <emphasis>attributes</emphasis> passed to
<literal>mkDerivation</literal>. This permits changing any aspect of
the package, such as the source code. For instance, if you want to
override the source code of Emacs, you can say:
</para>
<programlisting language="nix">
environment.systemPackages = [
(pkgs.emacs.overrideAttrs (oldAttrs: {
name = &quot;emacs-25.0-pre&quot;;
src = /path/to/my/emacs/tree;
}))
];
</programlisting>
<para>
Here, <literal>overrideAttrs</literal> takes the Nix derivation
specified by <literal>pkgs.emacs</literal> and produces a new
derivation in which the originals <literal>name</literal> and
<literal>src</literal> attribute have been replaced by the given
values by re-calling <literal>stdenv.mkDerivation</literal>. The
original attributes are accessible via the function argument, which
is conventionally named <literal>oldAttrs</literal>.
</para>
<para>
The overrides shown above are not global. They do not affect the
original package; other packages in Nixpkgs continue to depend on
the original rather than the customised package. This means that if
another package in your system depends on the original package, you
end up with two instances of the package. If you want to have
everything depend on your customised instance, you can apply a
<emphasis>global</emphasis> override as follows:
</para>
<programlisting language="nix">
nixpkgs.config.packageOverrides = pkgs:
{ emacs = pkgs.emacs.override { gtk = pkgs.gtk3; };
};
</programlisting>
<para>
The effect of this definition is essentially equivalent to modifying
the <literal>emacs</literal> attribute in the Nixpkgs source tree.
Any package in Nixpkgs that depends on <literal>emacs</literal> will
be passed your customised instance. (However, the value
<literal>pkgs.emacs</literal> in
<literal>nixpkgs.config.packageOverrides</literal> refers to the
original rather than overridden instance, to prevent an infinite
recursion.)
</para>
</section>

View File

@ -1,53 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="sec-declarative-package-mgmt">
<title>Declarative Package Management</title>
<para>
With declarative package management, you specify which packages you
want on your system by setting the option
<xref linkend="opt-environment.systemPackages" />. For instance,
adding the following line to <literal>configuration.nix</literal>
enables the Mozilla Thunderbird email application:
</para>
<programlisting language="nix">
environment.systemPackages = [ pkgs.thunderbird ];
</programlisting>
<para>
The effect of this specification is that the Thunderbird package
from Nixpkgs will be built or downloaded as part of the system when
you run <literal>nixos-rebuild switch</literal>.
</para>
<note>
<para>
Some packages require additional global configuration such as
D-Bus or systemd service registration so adding them to
<xref linkend="opt-environment.systemPackages" /> might not be
sufficient. You are advised to check the
<link linkend="ch-options">list of options</link> whether a NixOS
module for the package does not exist.
</para>
</note>
<para>
You can get a list of the available packages as follows:
</para>
<programlisting>
$ nix-env -qaP '*' --description
nixos.firefox firefox-23.0 Mozilla Firefox - the browser, reloaded
...
</programlisting>
<para>
The first column in the output is the <emphasis>attribute
name</emphasis>, such as <literal>nixos.thunderbird</literal>.
</para>
<para>
Note: the <literal>nixos</literal> prefix tells us that we want to
get the package from the <literal>nixos</literal> channel and works
only in CLI tools. In declarative configuration use
<literal>pkgs</literal> prefix (variable).
</para>
<para>
To <quote>uninstall</quote> a package, simply remove it from
<xref linkend="opt-environment.systemPackages" /> and run
<literal>nixos-rebuild switch</literal>.
</para>
<xi:include href="customizing-packages.section.xml" />
<xi:include href="adding-custom-packages.section.xml" />
</section>

View File

@ -1,55 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="ch-file-systems">
<title>File Systems</title>
<para>
You can define file systems using the <literal>fileSystems</literal>
configuration option. For instance, the following definition causes
NixOS to mount the Ext4 file system on device
<literal>/dev/disk/by-label/data</literal> onto the mount point
<literal>/data</literal>:
</para>
<programlisting language="nix">
fileSystems.&quot;/data&quot; =
{ device = &quot;/dev/disk/by-label/data&quot;;
fsType = &quot;ext4&quot;;
};
</programlisting>
<para>
This will create an entry in <literal>/etc/fstab</literal>, which
will generate a corresponding
<link xlink:href="https://www.freedesktop.org/software/systemd/man/systemd.mount.html">systemd.mount</link>
unit via
<link xlink:href="https://www.freedesktop.org/software/systemd/man/systemd-fstab-generator.html">systemd-fstab-generator</link>.
The filesystem will be mounted automatically unless
<literal>&quot;noauto&quot;</literal> is present in
<link linkend="opt-fileSystems._name_.options">options</link>.
<literal>&quot;noauto&quot;</literal> filesystems can be mounted
explicitly using <literal>systemctl</literal> e.g.
<literal>systemctl start data.mount</literal>. Mount points are
created automatically if they dont already exist. For
<literal>device</literal>, its best to use the topology-independent
device aliases in <literal>/dev/disk/by-label</literal> and
<literal>/dev/disk/by-uuid</literal>, as these dont change if the
topology changes (e.g. if a disk is moved to another IDE
controller).
</para>
<para>
You can usually omit the file system type
(<literal>fsType</literal>), since <literal>mount</literal> can
usually detect the type and load the necessary kernel module
automatically. However, if the file system is needed at early boot
(in the initial ramdisk) and is not <literal>ext2</literal>,
<literal>ext3</literal> or <literal>ext4</literal>, then its best
to specify <literal>fsType</literal> to ensure that the kernel
module is available.
</para>
<note>
<para>
System startup will fail if any of the filesystems fails to mount,
dropping you to the emergency shell. You can make a mount
asynchronous and non-critical by adding
<literal>options = [ &quot;nofail&quot; ];</literal>.
</para>
</note>
<xi:include href="luks-file-systems.section.xml" />
<xi:include href="sshfs-file-systems.section.xml" />
</chapter>

View File

@ -1,39 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-firewall">
<title>Firewall</title>
<para>
NixOS has a simple stateful firewall that blocks incoming
connections and other unexpected packets. The firewall applies to
both IPv4 and IPv6 traffic. It is enabled by default. It can be
disabled as follows:
</para>
<programlisting language="nix">
networking.firewall.enable = false;
</programlisting>
<para>
If the firewall is enabled, you can open specific TCP ports to the
outside world:
</para>
<programlisting language="nix">
networking.firewall.allowedTCPPorts = [ 80 443 ];
</programlisting>
<para>
Note that TCP port 22 (ssh) is opened automatically if the SSH
daemon is enabled
(<literal>services.openssh.enable = true</literal>). UDP ports can
be opened through
<xref linkend="opt-networking.firewall.allowedUDPPorts" />.
</para>
<para>
To open ranges of TCP ports:
</para>
<programlisting language="nix">
networking.firewall.allowedTCPPortRanges = [
{ from = 4000; to = 4007; }
{ from = 8000; to = 8010; }
];
</programlisting>
<para>
Similarly, UDP port ranges can be opened through
<xref linkend="opt-networking.firewall.allowedUDPPortRanges" />.
</para>
</section>

View File

@ -1,281 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-gpu-accel">
<title>GPU acceleration</title>
<para>
NixOS provides various APIs that benefit from GPU hardware
acceleration, such as VA-API and VDPAU for video playback; OpenGL
and Vulkan for 3D graphics; and OpenCL for general-purpose
computing. This chapter describes how to set up GPU hardware
acceleration (as far as this is not done automatically) and how to
verify that hardware acceleration is indeed used.
</para>
<para>
Most of the aforementioned APIs are agnostic with regards to which
display server is used. Consequently, these instructions should
apply both to the X Window System and Wayland compositors.
</para>
<section xml:id="sec-gpu-accel-opencl">
<title>OpenCL</title>
<para>
<link xlink:href="https://en.wikipedia.org/wiki/OpenCL">OpenCL</link>
is a general compute API. It is used by various applications such
as Blender and Darktable to accelerate certain operations.
</para>
<para>
OpenCL applications load drivers through the <emphasis>Installable
Client Driver</emphasis> (ICD) mechanism. In this mechanism, an
ICD file specifies the path to the OpenCL driver for a particular
GPU family. In NixOS, there are two ways to make ICD files visible
to the ICD loader. The first is through the
<literal>OCL_ICD_VENDORS</literal> environment variable. This
variable can contain a directory which is scanned by the ICL
loader for ICD files. For example:
</para>
<programlisting>
$ export \
OCL_ICD_VENDORS=`nix-build '&lt;nixpkgs&gt;' --no-out-link -A rocm-opencl-icd`/etc/OpenCL/vendors/
</programlisting>
<para>
The second mechanism is to add the OpenCL driver package to
<xref linkend="opt-hardware.opengl.extraPackages" />. This links
the ICD file under <literal>/run/opengl-driver</literal>, where it
will be visible to the ICD loader.
</para>
<para>
The proper installation of OpenCL drivers can be verified through
the <literal>clinfo</literal> command of the clinfo package. This
command will report the number of hardware devices that is found
and give detailed information for each device:
</para>
<programlisting>
$ clinfo | head -n3
Number of platforms 1
Platform Name AMD Accelerated Parallel Processing
Platform Vendor Advanced Micro Devices, Inc.
</programlisting>
<section xml:id="sec-gpu-accel-opencl-amd">
<title>AMD</title>
<para>
Modern AMD
<link xlink:href="https://en.wikipedia.org/wiki/Graphics_Core_Next">Graphics
Core Next</link> (GCN) GPUs are supported through the
rocm-opencl-icd package. Adding this package to
<xref linkend="opt-hardware.opengl.extraPackages" /> enables
OpenCL support:
</para>
<programlisting language="nix">
hardware.opengl.extraPackages = [
rocm-opencl-icd
];
</programlisting>
</section>
<section xml:id="sec-gpu-accel-opencl-intel">
<title>Intel</title>
<para>
<link xlink:href="https://en.wikipedia.org/wiki/List_of_Intel_graphics_processing_units#Gen8">Intel
Gen8 and later GPUs</link> are supported by the Intel NEO OpenCL
runtime that is provided by the intel-compute-runtime package.
For Gen7 GPUs, the deprecated Beignet runtime can be used, which
is provided by the beignet package. The proprietary Intel OpenCL
runtime, in the intel-ocl package, is an alternative for Gen7
GPUs.
</para>
<para>
The intel-compute-runtime, beignet, or intel-ocl package can be
added to <xref linkend="opt-hardware.opengl.extraPackages" /> to
enable OpenCL support. For example, for Gen8 and later GPUs, the
following configuration can be used:
</para>
<programlisting language="nix">
hardware.opengl.extraPackages = [
intel-compute-runtime
];
</programlisting>
</section>
</section>
<section xml:id="sec-gpu-accel-vulkan">
<title>Vulkan</title>
<para>
<link xlink:href="https://en.wikipedia.org/wiki/Vulkan_(API)">Vulkan</link>
is a graphics and compute API for GPUs. It is used directly by
games or indirectly though compatibility layers like
<link xlink:href="https://github.com/doitsujin/dxvk/wiki">DXVK</link>.
</para>
<para>
By default, if <xref linkend="opt-hardware.opengl.driSupport" />
is enabled, mesa is installed and provides Vulkan for supported
hardware.
</para>
<para>
Similar to OpenCL, Vulkan drivers are loaded through the
<emphasis>Installable Client Driver</emphasis> (ICD) mechanism.
ICD files for Vulkan are JSON files that specify the path to the
driver library and the supported Vulkan version. All successfully
loaded drivers are exposed to the application as different GPUs.
In NixOS, there are two ways to make ICD files visible to Vulkan
applications: an environment variable and a module option.
</para>
<para>
The first option is through the
<literal>VK_ICD_FILENAMES</literal> environment variable. This
variable can contain multiple JSON files, separated by
<literal>:</literal>. For example:
</para>
<programlisting>
$ export \
VK_ICD_FILENAMES=`nix-build '&lt;nixpkgs&gt;' --no-out-link -A amdvlk`/share/vulkan/icd.d/amd_icd64.json
</programlisting>
<para>
The second mechanism is to add the Vulkan driver package to
<xref linkend="opt-hardware.opengl.extraPackages" />. This links
the ICD file under <literal>/run/opengl-driver</literal>, where it
will be visible to the ICD loader.
</para>
<para>
The proper installation of Vulkan drivers can be verified through
the <literal>vulkaninfo</literal> command of the vulkan-tools
package. This command will report the hardware devices and drivers
found, in this example output amdvlk and radv:
</para>
<programlisting>
$ vulkaninfo | grep GPU
GPU id : 0 (Unknown AMD GPU)
GPU id : 1 (AMD RADV NAVI10 (LLVM 9.0.1))
...
GPU0:
deviceType = PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
deviceName = Unknown AMD GPU
GPU1:
deviceType = PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
</programlisting>
<para>
A simple graphical application that uses Vulkan is
<literal>vkcube</literal> from the vulkan-tools package.
</para>
<section xml:id="sec-gpu-accel-vulkan-amd">
<title>AMD</title>
<para>
Modern AMD
<link xlink:href="https://en.wikipedia.org/wiki/Graphics_Core_Next">Graphics
Core Next</link> (GCN) GPUs are supported through either radv,
which is part of mesa, or the amdvlk package. Adding the amdvlk
package to <xref linkend="opt-hardware.opengl.extraPackages" />
makes amdvlk the default driver and hides radv and lavapipe from
the device list. A specific driver can be forced as follows:
</para>
<programlisting language="nix">
hardware.opengl.extraPackages = [
pkgs.amdvlk
];
# To enable Vulkan support for 32-bit applications, also add:
hardware.opengl.extraPackages32 = [
pkgs.driversi686Linux.amdvlk
];
# Force radv
environment.variables.AMD_VULKAN_ICD = &quot;RADV&quot;;
# Or
environment.variables.VK_ICD_FILENAMES =
&quot;/run/opengl-driver/share/vulkan/icd.d/radeon_icd.x86_64.json&quot;;
</programlisting>
</section>
</section>
<section xml:id="sec-gpu-accel-va-api">
<title>VA-API</title>
<para>
<link xlink:href="https://www.intel.com/content/www/us/en/developer/articles/technical/linuxmedia-vaapi.html">VA-API
(Video Acceleration API)</link> is an open-source library and API
specification, which provides access to graphics hardware
acceleration capabilities for video processing.
</para>
<para>
VA-API drivers are loaded by <literal>libva</literal>. The version
in nixpkgs is built to search the opengl driver path, so drivers
can be installed in
<xref linkend="opt-hardware.opengl.extraPackages" />.
</para>
<para>
VA-API can be tested using:
</para>
<programlisting>
$ nix-shell -p libva-utils --run vainfo
</programlisting>
<section xml:id="sec-gpu-accel-va-api-intel">
<title>Intel</title>
<para>
Modern Intel GPUs use the iHD driver, which can be installed
with:
</para>
<programlisting language="nix">
hardware.opengl.extraPackages = [
intel-media-driver
];
</programlisting>
<para>
Older Intel GPUs use the i965 driver, which can be installed
with:
</para>
<programlisting language="nix">
hardware.opengl.extraPackages = [
vaapiIntel
];
</programlisting>
</section>
</section>
<section xml:id="sec-gpu-accel-common-issues">
<title>Common issues</title>
<section xml:id="sec-gpu-accel-common-issues-permissions">
<title>User permissions</title>
<para>
Except where noted explicitly, it should not be necessary to
adjust user permissions to use these acceleration APIs. In the
default configuration, GPU devices have world-read/write
permissions (<literal>/dev/dri/renderD*</literal>) or are tagged
as <literal>uaccess</literal>
(<literal>/dev/dri/card*</literal>). The access control lists of
devices with the <literal>uaccess</literal> tag will be updated
automatically when a user logs in through
<literal>systemd-logind</literal>. For example, if the user
<emphasis>alice</emphasis> is logged in, the access control list
should look as follows:
</para>
<programlisting>
$ getfacl /dev/dri/card0
# file: dev/dri/card0
# owner: root
# group: video
user::rw-
user:alice:rw-
group::rw-
mask::rw-
other::---
</programlisting>
<para>
If you disabled (this functionality of)
<literal>systemd-logind</literal>, you may need to add the user
to the <literal>video</literal> group and log in again.
</para>
</section>
<section xml:id="sec-gpu-accel-common-issues-mixing-nixpkgs">
<title>Mixing different versions of nixpkgs</title>
<para>
The <emphasis>Installable Client Driver</emphasis> (ICD)
mechanism used by OpenCL and Vulkan loads runtimes into its
address space using <literal>dlopen</literal>. Mixing an ICD
loader mechanism and runtimes from different version of nixpkgs
may not work. For example, if the ICD loader uses an older
version of glibc than the runtime, the runtime may not be
loadable due to missing symbols. Unfortunately, the loader will
generally be quiet about such issues.
</para>
<para>
If you suspect that you are running into library version
mismatches between an ICL loader and a runtime, you could run an
application with the <literal>LD_DEBUG</literal> variable set to
get more diagnostic information. For example, OpenCL can be
tested with <literal>LD_DEBUG=files clinfo</literal>, which
should report missing symbols.
</para>
</section>
</section>
</chapter>

View File

@ -1,43 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-ipv4">
<title>IPv4 Configuration</title>
<para>
By default, NixOS uses DHCP (specifically,
<literal>dhcpcd</literal>) to automatically configure network
interfaces. However, you can configure an interface manually as
follows:
</para>
<programlisting language="nix">
networking.interfaces.eth0.ipv4.addresses = [ {
address = &quot;192.168.1.2&quot;;
prefixLength = 24;
} ];
</programlisting>
<para>
Typically youll also want to set a default gateway and set of name
servers:
</para>
<programlisting language="nix">
networking.defaultGateway = &quot;192.168.1.1&quot;;
networking.nameservers = [ &quot;8.8.8.8&quot; ];
</programlisting>
<note>
<para>
Statically configured interfaces are set up by the systemd service
<literal>interface-name-cfg.service</literal>. The default gateway
and name server configuration is performed by
<literal>network-setup.service</literal>.
</para>
</note>
<para>
The host name is set using
<xref linkend="opt-networking.hostName" />:
</para>
<programlisting language="nix">
networking.hostName = &quot;cartman&quot;;
</programlisting>
<para>
The default host name is <literal>nixos</literal>. Set it to the
empty string (<literal>&quot;&quot;</literal>) to allow the DHCP
server to provide the host name.
</para>
</section>

View File

@ -1,47 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-ipv6">
<title>IPv6 Configuration</title>
<para>
IPv6 is enabled by default. Stateless address autoconfiguration is
used to automatically assign IPv6 addresses to all interfaces, and
Privacy Extensions (RFC 4946) are enabled by default. You can adjust
the default for this by setting
<xref linkend="opt-networking.tempAddresses" />. This option may be
overridden on a per-interface basis by
<xref linkend="opt-networking.interfaces._name_.tempAddress" />. You
can disable IPv6 support globally by setting:
</para>
<programlisting language="nix">
networking.enableIPv6 = false;
</programlisting>
<para>
You can disable IPv6 on a single interface using a normal sysctl (in
this example, we use interface <literal>eth0</literal>):
</para>
<programlisting language="nix">
boot.kernel.sysctl.&quot;net.ipv6.conf.eth0.disable_ipv6&quot; = true;
</programlisting>
<para>
As with IPv4 networking interfaces are automatically configured via
DHCPv6. You can configure an interface manually:
</para>
<programlisting language="nix">
networking.interfaces.eth0.ipv6.addresses = [ {
address = &quot;fe00:aa:bb:cc::2&quot;;
prefixLength = 64;
} ];
</programlisting>
<para>
For configuring a gateway, optionally with explicitly specified
interface:
</para>
<programlisting language="nix">
networking.defaultGateway6 = {
address = &quot;fe00::1&quot;;
interface = &quot;enp0s3&quot;;
};
</programlisting>
<para>
See <xref linkend="sec-ipv4" /> for similar examples and additional
information.
</para>
</section>

View File

@ -1,115 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-kubernetes">
<title>Kubernetes</title>
<para>
The NixOS Kubernetes module is a collective term for a handful of
individual submodules implementing the Kubernetes cluster
components.
</para>
<para>
There are generally two ways of enabling Kubernetes on NixOS. One
way is to enable and configure cluster components appropriately by
hand:
</para>
<programlisting language="nix">
services.kubernetes = {
apiserver.enable = true;
controllerManager.enable = true;
scheduler.enable = true;
addonManager.enable = true;
proxy.enable = true;
flannel.enable = true;
};
</programlisting>
<para>
Another way is to assign cluster roles (<quote>master</quote> and/or
<quote>node</quote>) to the host. This enables apiserver,
controllerManager, scheduler, addonManager, kube-proxy and etcd:
</para>
<programlisting language="nix">
services.kubernetes.roles = [ &quot;master&quot; ];
</programlisting>
<para>
While this will enable the kubelet and kube-proxy only:
</para>
<programlisting language="nix">
services.kubernetes.roles = [ &quot;node&quot; ];
</programlisting>
<para>
Assigning both the master and node roles is usable if you want a
single node Kubernetes cluster for dev or testing purposes:
</para>
<programlisting language="nix">
services.kubernetes.roles = [ &quot;master&quot; &quot;node&quot; ];
</programlisting>
<para>
Note: Assigning either role will also default both
<xref linkend="opt-services.kubernetes.flannel.enable" /> and
<xref linkend="opt-services.kubernetes.easyCerts" /> to true. This
sets up flannel as CNI and activates automatic PKI bootstrapping.
</para>
<note>
<para>
As of NixOS 19.03, it is mandatory to configure:
<xref linkend="opt-services.kubernetes.masterAddress" />. The
masterAddress must be resolveable and routeable by all cluster
nodes. In single node clusters, this can be set to
<literal>localhost</literal>.
</para>
</note>
<para>
Role-based access control (RBAC) authorization mode is enabled by
default. This means that anonymous requests to the apiserver secure
port will expectedly cause a permission denied error. All cluster
components must therefore be configured with x509 certificates for
two-way tls communication. The x509 certificate subject section
determines the roles and permissions granted by the apiserver to
perform clusterwide or namespaced operations. See also:
<link xlink:href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/">
Using RBAC Authorization</link>.
</para>
<para>
The NixOS kubernetes module provides an option for automatic
certificate bootstrapping and configuration,
<xref linkend="opt-services.kubernetes.easyCerts" />. The PKI
bootstrapping process involves setting up a certificate authority
(CA) daemon (cfssl) on the kubernetes master node. cfssl generates a
CA-cert for the cluster, and uses the CA-cert for signing
subordinate certs issued to each of the cluster components.
Subsequently, the certmgr daemon monitors active certificates and
renews them when needed. For single node Kubernetes clusters,
setting <xref linkend="opt-services.kubernetes.easyCerts" /> = true
is sufficient and no further action is required. For joining extra
node machines to an existing cluster on the other hand, establishing
initial trust is mandatory.
</para>
<para>
To add new nodes to the cluster: On any (non-master) cluster node
where <xref linkend="opt-services.kubernetes.easyCerts" /> is
enabled, the helper script
<literal>nixos-kubernetes-node-join</literal> is available on PATH.
Given a token on stdin, it will copy the token to the kubernetes
secrets directory and restart the certmgr service. As requested
certificates are issued, the script will restart kubernetes cluster
components as needed for them to pick up new keypairs.
</para>
<note>
<para>
Multi-master (HA) clusters are not supported by the easyCerts
module.
</para>
</note>
<para>
In order to interact with an RBAC-enabled cluster as an
administrator, one needs to have cluster-admin privileges. By
default, when easyCerts is enabled, a cluster-admin kubeconfig file
is generated and linked into
<literal>/etc/kubernetes/cluster-admin.kubeconfig</literal> as
determined by
<xref linkend="opt-services.kubernetes.pki.etcClusterAdminKubeconfig" />.
<literal>export KUBECONFIG=/etc/kubernetes/cluster-admin.kubeconfig</literal>
will make kubectl use this kubeconfig to access and authenticate the
cluster. The cluster-admin kubeconfig references an auto-generated
keypair owned by root. Thus, only root on the kubernetes master may
obtain cluster-admin rights by means of this file.
</para>
</chapter>

View File

@ -1,221 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-kernel-config">
<title>Linux Kernel</title>
<para>
You can override the Linux kernel and associated packages using the
option <literal>boot.kernelPackages</literal>. For instance, this
selects the Linux 3.10 kernel:
</para>
<programlisting language="nix">
boot.kernelPackages = pkgs.linuxKernel.packages.linux_3_10;
</programlisting>
<para>
Note that this not only replaces the kernel, but also packages that
are specific to the kernel version, such as the NVIDIA video
drivers. This ensures that driver packages are consistent with the
kernel.
</para>
<para>
While <literal>pkgs.linuxKernel.packages</literal> contains all
available kernel packages, you may want to use one of the
unversioned <literal>pkgs.linuxPackages_*</literal> aliases such as
<literal>pkgs.linuxPackages_latest</literal>, that are kept up to
date with new versions.
</para>
<para>
Please note that the current convention in NixOS is to only keep
actively maintained kernel versions on both unstable and the
currently supported stable release(s) of NixOS. This means that a
non-longterm kernel will be removed after its abandoned by the
kernel developers, even on stable NixOS versions. If you pin your
kernel onto a non-longterm version, expect your evaluation to fail
as soon as the version is out of maintenance.
</para>
<para>
Longterm versions of kernels will be removed before the next stable
NixOS that will exceed the maintenance period of the kernel version.
</para>
<para>
The default Linux kernel configuration should be fine for most
users. You can see the configuration of your current kernel with the
following command:
</para>
<programlisting>
zcat /proc/config.gz
</programlisting>
<para>
If you want to change the kernel configuration, you can use the
<literal>packageOverrides</literal> feature (see
<xref linkend="sec-customising-packages" />). For instance, to
enable support for the kernel debugger KGDB:
</para>
<programlisting language="nix">
nixpkgs.config.packageOverrides = pkgs: pkgs.lib.recursiveUpdate pkgs {
linuxKernel.kernels.linux_5_10 = pkgs.linuxKernel.kernels.linux_5_10.override {
extraConfig = ''
KGDB y
'';
};
};
</programlisting>
<para>
<literal>extraConfig</literal> takes a list of Linux kernel
configuration options, one per line. The name of the option should
not include the prefix <literal>CONFIG_</literal>. The option value
is typically <literal>y</literal>, <literal>n</literal> or
<literal>m</literal> (to build something as a kernel module).
</para>
<para>
Kernel modules for hardware devices are generally loaded
automatically by <literal>udev</literal>. You can force a module to
be loaded via <xref linkend="opt-boot.kernelModules" />, e.g.
</para>
<programlisting language="nix">
boot.kernelModules = [ &quot;fuse&quot; &quot;kvm-intel&quot; &quot;coretemp&quot; ];
</programlisting>
<para>
If the module is required early during the boot (e.g. to mount the
root file system), you can use
<xref linkend="opt-boot.initrd.kernelModules" />:
</para>
<programlisting language="nix">
boot.initrd.kernelModules = [ &quot;cifs&quot; ];
</programlisting>
<para>
This causes the specified modules and their dependencies to be added
to the initial ramdisk.
</para>
<para>
Kernel runtime parameters can be set through
<xref linkend="opt-boot.kernel.sysctl" />, e.g.
</para>
<programlisting language="nix">
boot.kernel.sysctl.&quot;net.ipv4.tcp_keepalive_time&quot; = 120;
</programlisting>
<para>
sets the kernels TCP keepalive time to 120 seconds. To see the
available parameters, run <literal>sysctl -a</literal>.
</para>
<section xml:id="sec-linux-config-customizing">
<title>Building a custom kernel</title>
<para>
You can customize the default kernel configuration by overriding
the arguments for your kernel package:
</para>
<programlisting language="nix">
pkgs.linux_latest.override {
ignoreConfigErrors = true;
autoModules = false;
kernelPreferBuiltin = true;
extraStructuredConfig = with lib.kernel; {
DEBUG_KERNEL = yes;
FRAME_POINTER = yes;
KGDB = yes;
KGDB_SERIAL_CONSOLE = yes;
DEBUG_INFO = yes;
};
}
</programlisting>
<para>
See <literal>pkgs/os-specific/linux/kernel/generic.nix</literal>
for details on how these arguments affect the generated
configuration. You can also build a custom version of Linux by
calling <literal>pkgs.buildLinux</literal> directly, which
requires the <literal>src</literal> and <literal>version</literal>
arguments to be specified.
</para>
<para>
To use your custom kernel package in your NixOS configuration, set
</para>
<programlisting language="nix">
boot.kernelPackages = pkgs.linuxPackagesFor yourCustomKernel;
</programlisting>
<para>
Note that this method will use the common configuration defined in
<literal>pkgs/os-specific/linux/kernel/common-config.nix</literal>,
which is suitable for a NixOS system.
</para>
<para>
If you already have a generated configuration file, you can build
a kernel that uses it with
<literal>pkgs.linuxManualConfig</literal>:
</para>
<programlisting language="nix">
let
baseKernel = pkgs.linux_latest;
in pkgs.linuxManualConfig {
inherit (baseKernel) src modDirVersion;
version = &quot;${baseKernel.version}-custom&quot;;
configfile = ./my_kernel_config;
allowImportFromDerivation = true;
}
</programlisting>
<note>
<para>
The build will fail if <literal>modDirVersion</literal> does not
match the sources <literal>kernel.release</literal> file, so
<literal>modDirVersion</literal> should remain tied to
<literal>src</literal>.
</para>
</note>
<para>
To edit the <literal>.config</literal> file for Linux X.Y, proceed
as follows:
</para>
<programlisting>
$ nix-shell '&lt;nixpkgs&gt;' -A linuxKernel.kernels.linux_X_Y.configEnv
$ unpackPhase
$ cd linux-*
$ make nconfig
</programlisting>
</section>
<section xml:id="sec-linux-config-developing-modules">
<title>Developing kernel modules</title>
<para>
When developing kernel modules its often convenient to run
edit-compile-run loop as quickly as possible. See below snippet as
an example of developing <literal>mellanox</literal> drivers.
</para>
<programlisting>
$ nix-build '&lt;nixpkgs&gt;' -A linuxPackages.kernel.dev
$ nix-shell '&lt;nixpkgs&gt;' -A linuxPackages.kernel
$ unpackPhase
$ cd linux-*
$ make -C $dev/lib/modules/*/build M=$(pwd)/drivers/net/ethernet/mellanox modules
# insmod ./drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.ko
</programlisting>
</section>
<section xml:id="sec-linux-zfs">
<title>ZFS</title>
<para>
Its a common issue that the latest stable version of ZFS doesnt
support the latest available Linux kernel. It is recommended to
use the latest available LTS thats compatible with ZFS. Usually
this is the default kernel provided by nixpkgs (i.e.
<literal>pkgs.linuxPackages</literal>).
</para>
<para>
Alternatively, its possible to pin the system to the latest
available kernel version <emphasis>that is supported by
ZFS</emphasis> like this:
</para>
<programlisting language="nix">
{
boot.kernelPackages = pkgs.zfs.latestCompatibleLinuxPackages;
}
</programlisting>
<para>
Please note that the version this attribute points to isnt
monotonic because the latest kernel version only refers to kernel
versions supported by the Linux developers. In other words, the
latest kernel version that ZFS is compatible with may decrease
over time.
</para>
<para>
An example: the latest version ZFS is compatible with is 5.19
which is a non-longterm version. When 5.19 is out of maintenance,
the latest supported kernel version is 5.15 because its longterm
and the versions 5.16, 5.17 and 5.18 are already out of
maintenance because theyre non-longterm.
</para>
</section>
</chapter>

View File

@ -1,84 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-luks-file-systems">
<title>LUKS-Encrypted File Systems</title>
<para>
NixOS supports file systems that are encrypted using
<emphasis>LUKS</emphasis> (Linux Unified Key Setup). For example,
here is how you create an encrypted Ext4 file system on the device
<literal>/dev/disk/by-uuid/3f6b0024-3a44-4fde-a43a-767b872abe5d</literal>:
</para>
<programlisting>
# cryptsetup luksFormat /dev/disk/by-uuid/3f6b0024-3a44-4fde-a43a-767b872abe5d
WARNING!
========
This will overwrite data on /dev/disk/by-uuid/3f6b0024-3a44-4fde-a43a-767b872abe5d irrevocably.
Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase: ***
Verify passphrase: ***
# cryptsetup luksOpen /dev/disk/by-uuid/3f6b0024-3a44-4fde-a43a-767b872abe5d crypted
Enter passphrase for /dev/disk/by-uuid/3f6b0024-3a44-4fde-a43a-767b872abe5d: ***
# mkfs.ext4 /dev/mapper/crypted
</programlisting>
<para>
The LUKS volume should be automatically picked up by
<literal>nixos-generate-config</literal>, but you might want to
verify that your <literal>hardware-configuration.nix</literal> looks
correct. To manually ensure that the system is automatically mounted
at boot time as <literal>/</literal>, add the following to
<literal>configuration.nix</literal>:
</para>
<programlisting language="nix">
boot.initrd.luks.devices.crypted.device = &quot;/dev/disk/by-uuid/3f6b0024-3a44-4fde-a43a-767b872abe5d&quot;;
fileSystems.&quot;/&quot;.device = &quot;/dev/mapper/crypted&quot;;
</programlisting>
<para>
Should grub be used as bootloader, and <literal>/boot</literal> is
located on an encrypted partition, it is necessary to add the
following grub option:
</para>
<programlisting language="nix">
boot.loader.grub.enableCryptodisk = true;
</programlisting>
<section xml:id="sec-luks-file-systems-fido2">
<title>FIDO2</title>
<para>
NixOS also supports unlocking your LUKS-Encrypted file system
using a FIDO2 compatible token. In the following example, we will
create a new FIDO2 credential and add it as a new key to our
existing device <literal>/dev/sda2</literal>:
</para>
<programlisting>
# export FIDO2_LABEL=&quot;/dev/sda2 @ $HOSTNAME&quot;
# fido2luks credential &quot;$FIDO2_LABEL&quot;
f1d00200108b9d6e849a8b388da457688e3dd653b4e53770012d8f28e5d3b269865038c346802f36f3da7278b13ad6a3bb6a1452e24ebeeaa24ba40eef559b1b287d2a2f80b7
# fido2luks -i add-key /dev/sda2 f1d00200108b9d6e849a8b388da457688e3dd653b4e53770012d8f28e5d3b269865038c346802f36f3da7278b13ad6a3bb6a1452e24ebeeaa24ba40eef559b1b287d2a2f80b7
Password:
Password (again):
Old password:
Old password (again):
Added to key to device /dev/sda2, slot: 2
</programlisting>
<para>
To ensure that this file system is decrypted using the FIDO2
compatible key, add the following to
<literal>configuration.nix</literal>:
</para>
<programlisting language="nix">
boot.initrd.luks.fido2Support = true;
boot.initrd.luks.devices.&quot;/dev/sda2&quot;.fido2.credential = &quot;f1d00200108b9d6e849a8b388da457688e3dd653b4e53770012d8f28e5d3b269865038c346802f36f3da7278b13ad6a3bb6a1452e24ebeeaa24ba40eef559b1b287d2a2f80b7&quot;;
</programlisting>
<para>
You can also use the FIDO2 passwordless setup, but for security
reasons, you might want to enable it only when your device is PIN
protected, such as
<link xlink:href="https://trezor.io/">Trezor</link>.
</para>
<programlisting language="nix">
boot.initrd.luks.devices.&quot;/dev/sda2&quot;.fido2.passwordLess = true;
</programlisting>
</section>
</section>

View File

@ -1,152 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-modularity">
<title>Modularity</title>
<para>
The NixOS configuration mechanism is modular. If your
<literal>configuration.nix</literal> becomes too big, you can split
it into multiple files. Likewise, if you have multiple NixOS
configurations (e.g. for different computers) with some commonality,
you can move the common configuration into a shared file.
</para>
<para>
Modules have exactly the same syntax as
<literal>configuration.nix</literal>. In fact,
<literal>configuration.nix</literal> is itself a module. You can use
other modules by including them from
<literal>configuration.nix</literal>, e.g.:
</para>
<programlisting language="nix">
{ config, pkgs, ... }:
{ imports = [ ./vpn.nix ./kde.nix ];
services.httpd.enable = true;
environment.systemPackages = [ pkgs.emacs ];
...
}
</programlisting>
<para>
Here, we include two modules from the same directory,
<literal>vpn.nix</literal> and <literal>kde.nix</literal>. The
latter might look like this:
</para>
<programlisting language="nix">
{ config, pkgs, ... }:
{ services.xserver.enable = true;
services.xserver.displayManager.sddm.enable = true;
services.xserver.desktopManager.plasma5.enable = true;
environment.systemPackages = [ pkgs.vim ];
}
</programlisting>
<para>
Note that both <literal>configuration.nix</literal> and
<literal>kde.nix</literal> define the option
<xref linkend="opt-environment.systemPackages" />. When multiple
modules define an option, NixOS will try to
<emphasis>merge</emphasis> the definitions. In the case of
<xref linkend="opt-environment.systemPackages" />, thats easy: the
lists of packages can simply be concatenated. The value in
<literal>configuration.nix</literal> is merged last, so for
list-type options, it will appear at the end of the merged list. If
you want it to appear first, you can use
<literal>mkBefore</literal>:
</para>
<programlisting language="nix">
boot.kernelModules = mkBefore [ &quot;kvm-intel&quot; ];
</programlisting>
<para>
This causes the <literal>kvm-intel</literal> kernel module to be
loaded before any other kernel modules.
</para>
<para>
For other types of options, a merge may not be possible. For
instance, if two modules define
<xref linkend="opt-services.httpd.adminAddr" />,
<literal>nixos-rebuild</literal> will give an error:
</para>
<programlisting>
The unique option `services.httpd.adminAddr' is defined multiple times, in `/etc/nixos/httpd.nix' and `/etc/nixos/configuration.nix'.
</programlisting>
<para>
When that happens, its possible to force one definition take
precedence over the others:
</para>
<programlisting language="nix">
services.httpd.adminAddr = pkgs.lib.mkForce &quot;bob@example.org&quot;;
</programlisting>
<para>
When using multiple modules, you may need to access configuration
values defined in other modules. This is what the
<literal>config</literal> function argument is for: it contains the
complete, merged system configuration. That is,
<literal>config</literal> is the result of combining the
configurations returned by every module <footnote>
<para>
If youre wondering how its possible that the (indirect)
<emphasis>result</emphasis> of a function is passed as an
<emphasis>input</emphasis> to that same function: thats because
Nix is a <quote>lazy</quote> language — it only computes values
when they are needed. This works as long as no individual
configuration value depends on itself.
</para>
</footnote> . For example, here is a module that adds some packages
to <xref linkend="opt-environment.systemPackages" /> only if
<xref linkend="opt-services.xserver.enable" /> is set to
<literal>true</literal> somewhere else:
</para>
<programlisting language="nix">
{ config, pkgs, ... }:
{ environment.systemPackages =
if config.services.xserver.enable then
[ pkgs.firefox
pkgs.thunderbird
]
else
[ ];
}
</programlisting>
<para>
With multiple modules, it may not be obvious what the final value of
a configuration option is. The command
<literal>nixos-option</literal> allows you to find out:
</para>
<programlisting>
$ nixos-option services.xserver.enable
true
$ nixos-option boot.kernelModules
[ &quot;tun&quot; &quot;ipv6&quot; &quot;loop&quot; ... ]
</programlisting>
<para>
Interactive exploration of the configuration is possible using
<literal>nix repl</literal>, a read-eval-print loop for Nix
expressions. A typical use:
</para>
<programlisting>
$ nix repl '&lt;nixpkgs/nixos&gt;'
nix-repl&gt; config.networking.hostName
&quot;mandark&quot;
nix-repl&gt; map (x: x.hostName) config.services.httpd.virtualHosts
[ &quot;example.org&quot; &quot;example.gov&quot; ]
</programlisting>
<para>
While abstracting your configuration, you may find it useful to
generate modules using code, instead of writing files. The example
below would have the same effect as importing a file which sets
those options.
</para>
<programlisting language="nix">
{ config, pkgs, ... }:
let netConfig = hostName: {
networking.hostName = hostName;
networking.useDHCP = false;
};
in
{ imports = [ (netConfig &quot;nixos.localdomain&quot;) ]; }
</programlisting>
</section>

View File

@ -1,49 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-networkmanager">
<title>NetworkManager</title>
<para>
To facilitate network configuration, some desktop environments use
NetworkManager. You can enable NetworkManager by setting:
</para>
<programlisting language="nix">
networking.networkmanager.enable = true;
</programlisting>
<para>
some desktop managers (e.g., GNOME) enable NetworkManager
automatically for you.
</para>
<para>
All users that should have permission to change network settings
must belong to the <literal>networkmanager</literal> group:
</para>
<programlisting language="nix">
users.users.alice.extraGroups = [ &quot;networkmanager&quot; ];
</programlisting>
<para>
NetworkManager is controlled using either <literal>nmcli</literal>
or <literal>nmtui</literal> (curses-based terminal user interface).
See their manual pages for details on their usage. Some desktop
environments (GNOME, KDE) have their own configuration tools for
NetworkManager. On XFCE, there is no configuration tool for
NetworkManager by default: by enabling
<xref linkend="opt-programs.nm-applet.enable" />, the graphical
applet will be installed and will launch automatically when the
graphical session is started.
</para>
<note>
<para>
<literal>networking.networkmanager</literal> and
<literal>networking.wireless</literal> (WPA Supplicant) can be
used together if desired. To do this you need to instruct
NetworkManager to ignore those interfaces like:
</para>
<programlisting language="nix">
networking.networkmanager.unmanaged = [
&quot;*&quot; &quot;except:type:wwan&quot; &quot;except:type:gsm&quot;
];
</programlisting>
<para>
Refer to the option description for the exact syntax and
references to external documentation.
</para>
</note>
</section>

View File

@ -1,15 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="sec-networking">
<title>Networking</title>
<para>
This section describes how to configure networking components on
your NixOS machine.
</para>
<xi:include href="network-manager.section.xml" />
<xi:include href="ssh.section.xml" />
<xi:include href="ipv4-config.section.xml" />
<xi:include href="ipv6-config.section.xml" />
<xi:include href="firewall.section.xml" />
<xi:include href="wireless.section.xml" />
<xi:include href="ad-hoc-network-config.section.xml" />
<xi:include href="renaming-interfaces.section.xml" />
</chapter>

View File

@ -1,28 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="sec-package-management">
<title>Package Management</title>
<para>
This section describes how to add additional packages to your
system. NixOS has two distinct styles of package management:
</para>
<itemizedlist>
<listitem>
<para>
<emphasis>Declarative</emphasis>, where you declare what
packages you want in your <literal>configuration.nix</literal>.
Every time you run <literal>nixos-rebuild</literal>, NixOS will
ensure that you get a consistent set of binaries corresponding
to your specification.
</para>
</listitem>
<listitem>
<para>
<emphasis>Ad hoc</emphasis>, where you install, upgrade and
uninstall packages via the <literal>nix-env</literal> command.
This style allows mixing packages from different Nixpkgs
versions. Its the only choice for non-root users.
</para>
</listitem>
</itemizedlist>
<xi:include href="declarative-packages.section.xml" />
<xi:include href="ad-hoc-packages.section.xml" />
</chapter>

View File

@ -1,38 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="ch-profiles">
<title>Profiles</title>
<para>
In some cases, it may be desirable to take advantage of
commonly-used, predefined configurations provided by nixpkgs, but
different from those that come as default. This is a role fulfilled
by NixOSs Profiles, which come as files living in
<literal>&lt;nixpkgs/nixos/modules/profiles&gt;</literal>. That is
to say, expected usage is to add them to the imports list of your
<literal>/etc/configuration.nix</literal> as such:
</para>
<programlisting language="nix">
imports = [
&lt;nixpkgs/nixos/modules/profiles/profile-name.nix&gt;
];
</programlisting>
<para>
Even if some of these profiles seem only useful in the context of
install media, many are actually intended to be used in real
installs.
</para>
<para>
What follows is a brief explanation on the purpose and use-case for
each profile. Detailing each option configured by each one is out of
scope.
</para>
<xi:include href="profiles/all-hardware.section.xml" />
<xi:include href="profiles/base.section.xml" />
<xi:include href="profiles/clone-config.section.xml" />
<xi:include href="profiles/demo.section.xml" />
<xi:include href="profiles/docker-container.section.xml" />
<xi:include href="profiles/graphical.section.xml" />
<xi:include href="profiles/hardened.section.xml" />
<xi:include href="profiles/headless.section.xml" />
<xi:include href="profiles/installation-device.section.xml" />
<xi:include href="profiles/minimal.section.xml" />
<xi:include href="profiles/qemu-guest.section.xml" />
</chapter>

View File

@ -1,15 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-profile-all-hardware">
<title>All Hardware</title>
<para>
Enables all hardware supported by NixOS: i.e., all firmware is
included, and all devices from which one may boot are enabled in the
initrd. Its primary use is in the NixOS installation CDs.
</para>
<para>
The enabled kernel modules include support for SATA and PATA, SCSI
(partially), USB, Firewire (untested), Virtio (QEMU, KVM, etc.),
VMware, and Hyper-V. Additionally,
<xref linkend="opt-hardware.enableAllFirmware" /> is enabled, and
the firmware for the ZyDAS ZD1211 chipset is specifically installed.
</para>
</section>

View File

@ -1,10 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-profile-base">
<title>Base</title>
<para>
Defines the software packages included in the <quote>minimal</quote>
installation CD. It installs several utilities useful in a simple
recovery or install media, such as a text-mode web browser, and
tools for manipulating block devices, networking, hardware
diagnostics, and filesystems (with their respective kernel modules).
</para>
</section>

View File

@ -1,16 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-profile-clone-config">
<title>Clone Config</title>
<para>
This profile is used in installer images. It provides an editable
configuration.nix that imports all the modules that were also used
when creating the image in the first place. As a result it allows
users to edit and rebuild the live-system.
</para>
<para>
On images where the installation media also becomes an installation
target, copying over <literal>configuration.nix</literal> should be
disabled by setting <literal>installer.cloneConfig</literal> to
<literal>false</literal>. For example, this is done in
<literal>sd-image-aarch64-installer.nix</literal>.
</para>
</section>

View File

@ -1,10 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-profile-demo">
<title>Demo</title>
<para>
This profile just enables a <literal>demo</literal> user, with
password <literal>demo</literal>, uid <literal>1000</literal>,
<literal>wheel</literal> group and
<link linkend="opt-services.xserver.displayManager.autoLogin">autologin
in the SDDM display manager</link>.
</para>
</section>

View File

@ -1,12 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-profile-docker-container">
<title>Docker Container</title>
<para>
This is the profile from which the Docker images are generated. It
prepares a working system by importing the
<link linkend="sec-profile-minimal">Minimal</link> and
<link linkend="sec-profile-clone-config">Clone Config</link>
profiles, and setting appropriate configuration options that are
useful inside a container context, like
<xref linkend="opt-boot.isContainer" />.
</para>
</section>

View File

@ -1,14 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-profile-graphical">
<title>Graphical</title>
<para>
Defines a NixOS configuration with the Plasma 5 desktop. Its used
by the graphical installation CD.
</para>
<para>
It sets <xref linkend="opt-services.xserver.enable" />,
<xref linkend="opt-services.xserver.displayManager.sddm.enable" />,
<xref linkend="opt-services.xserver.desktopManager.plasma5.enable" />,
and <xref linkend="opt-services.xserver.libinput.enable" /> to true.
It also includes glxinfo and firefox in the system packages list.
</para>
</section>

View File

@ -1,25 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-profile-hardened">
<title>Hardened</title>
<para>
A profile with most (vanilla) hardening options enabled by default,
potentially at the cost of stability, features and performance.
</para>
<para>
This includes a hardened kernel, and limiting the system information
available to processes through the <literal>/sys</literal> and
<literal>/proc</literal> filesystems. It also disables the User
Namespaces feature of the kernel, which stops Nix from being able to
build anything (this particular setting can be overridden via
<xref linkend="opt-security.allowUserNamespaces" />). See the
<link xlink:href="https://github.com/nixos/nixpkgs/tree/master/nixos/modules/profiles/hardened.nix">profile
source</link> for further detail on which settings are altered.
</para>
<warning>
<para>
This profile enables options that are known to affect system
stability. If you experience any stability issues when using the
profile, try disabling it. If you report an issue and use this
profile, always mention that you do.
</para>
</warning>
</section>

View File

@ -1,15 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-profile-headless">
<title>Headless</title>
<para>
Common configuration for headless machines (e.g., Amazon EC2
instances).
</para>
<para>
Disables <link linkend="opt-sound.enable">sound</link>,
<link linkend="opt-boot.vesa">vesa</link>, serial consoles,
<link linkend="opt-systemd.enableEmergencyMode">emergency
mode</link>, <link linkend="opt-boot.loader.grub.splashImage">grub
splash images</link> and configures the kernel to reboot
automatically on panic.
</para>
</section>

View File

@ -1,32 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-profile-installation-device">
<title>Installation Device</title>
<para>
Provides a basic configuration for installation devices like CDs.
This enables redistributable firmware, includes the
<link linkend="sec-profile-clone-config">Clone Config profile</link>
and a copy of the Nixpkgs channel, so
<literal>nixos-install</literal> works out of the box.
</para>
<para>
Documentation for
<link linkend="opt-documentation.enable">Nixpkgs</link> and
<link linkend="opt-documentation.nixos.enable">NixOS</link> are
forcefully enabled (to override the
<link linkend="sec-profile-minimal">Minimal profile</link>
preference); the NixOS manual is shown automatically on TTY 8,
udisks is disabled. Autologin is enabled as <literal>nixos</literal>
user, while passwordless login as both <literal>root</literal> and
<literal>nixos</literal> is possible. Passwordless
<literal>sudo</literal> is enabled too.
<link linkend="opt-networking.wireless.enable">wpa_supplicant</link>
is enabled, but configured to not autostart.
</para>
<para>
It is explained how to login, start the ssh server, and if
available, how to start the display manager.
</para>
<para>
Several settings are tweaked so that the installer has a better
chance of succeeding under low-memory environments.
</para>
</section>

View File

@ -1,13 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-profile-minimal">
<title>Minimal</title>
<para>
This profile defines a small NixOS configuration. It does not
contain any graphical stuff. Its a very short file that enables
<link linkend="opt-environment.noXlibs">noXlibs</link>, sets
<xref linkend="opt-i18n.supportedLocales" /> to only support the
user-selected locale,
<link linkend="opt-documentation.enable">disables packages
documentation</link>, and <link linkend="opt-sound.enable">disables
sound</link>.
</para>
</section>

View File

@ -1,11 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-profile-qemu-guest">
<title>QEMU Guest</title>
<para>
This profile contains common configuration for virtual machines
running under QEMU (using virtio).
</para>
<para>
It makes virtio modules available on the initrd and sets the system
time from the hardware clock to work around a bug in qemu-kvm.
</para>
</section>

View File

@ -1,62 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-rename-ifs">
<title>Renaming network interfaces</title>
<para>
NixOS uses the udev
<link xlink:href="https://systemd.io/PREDICTABLE_INTERFACE_NAMES/">predictable
naming scheme</link> to assign names to network interfaces. This
means that by default cards are not given the traditional names like
<literal>eth0</literal> or <literal>eth1</literal>, whose order can
change unpredictably across reboots. Instead, relying on physical
locations and firmware information, the scheme produces names like
<literal>ens1</literal>, <literal>enp2s0</literal>, etc.
</para>
<para>
These names are predictable but less memorable and not necessarily
stable: for example installing new hardware or changing firmware
settings can result in a
<link xlink:href="https://github.com/systemd/systemd/issues/3715#issue-165347602">name
change</link>. If this is undesirable, for example if you have a
single ethernet card, you can revert to the traditional scheme by
setting
<xref linkend="opt-networking.usePredictableInterfaceNames" /> to
<literal>false</literal>.
</para>
<section xml:id="sec-custom-ifnames">
<title>Assigning custom names</title>
<para>
In case there are multiple interfaces of the same type, its
better to assign custom names based on the device hardware
address. For example, we assign the name <literal>wan</literal> to
the interface with MAC address
<literal>52:54:00:12:01:01</literal> using a netword link unit:
</para>
<programlisting language="nix">
systemd.network.links.&quot;10-wan&quot; = {
matchConfig.PermanentMACAddress = &quot;52:54:00:12:01:01&quot;;
linkConfig.Name = &quot;wan&quot;;
};
</programlisting>
<para>
Note that links are directly read by udev, <emphasis>not
networkd</emphasis>, and will work even if networkd is disabled.
</para>
<para>
Alternatively, we can use a plain old udev rule:
</para>
<programlisting language="nix">
services.udev.initrdRules = ''
SUBSYSTEM==&quot;net&quot;, ACTION==&quot;add&quot;, DRIVERS==&quot;?*&quot;, \
ATTR{address}==&quot;52:54:00:12:01:01&quot;, KERNEL==&quot;eth*&quot;, NAME=&quot;wan&quot;
'';
</programlisting>
<warning>
<para>
The rule must be installed in the initrd using
<literal>services.udev.initrdRules</literal>, not the usual
<literal>services.udev.extraRules</literal> option. This is to
avoid race conditions with other programs controlling the
interface.
</para>
</warning>
</section>
</section>

View File

@ -1,23 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-ssh">
<title>Secure Shell Access</title>
<para>
Secure shell (SSH) access to your machine can be enabled by setting:
</para>
<programlisting language="nix">
services.openssh.enable = true;
</programlisting>
<para>
By default, root logins using a password are disallowed. They can be
disabled entirely by setting
<xref linkend="opt-services.openssh.settings.PermitRootLogin" /> to
<literal>&quot;no&quot;</literal>.
</para>
<para>
You can declaratively specify authorised RSA/DSA public keys for a
user as follows:
</para>
<programlisting language="nix">
users.users.alice.openssh.authorizedKeys.keys =
[ &quot;ssh-dss AAAAB3NzaC1kc3MAAACBAPIkGWVEt4...&quot; ];
</programlisting>
</section>

View File

@ -1,139 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-sshfs-file-systems">
<title>SSHFS File Systems</title>
<para>
<link xlink:href="https://github.com/libfuse/sshfs">SSHFS</link> is
a
<link xlink:href="https://en.wikipedia.org/wiki/Filesystem_in_Userspace">FUSE</link>
filesystem that allows easy access to directories on a remote
machine using the SSH File Transfer Protocol (SFTP). It means that
if you have SSH access to a machine, no additional setup is needed
to mount a directory.
</para>
<section xml:id="sec-sshfs-interactive">
<title>Interactive mounting</title>
<para>
In NixOS, SSHFS is packaged as <package>sshfs</package>. Once
installed, mounting a directory interactively is simple as
running:
</para>
<programlisting>
$ sshfs my-user@example.com:/my-dir /mnt/my-dir
</programlisting>
<para>
Like any other FUSE file system, the directory is unmounted using:
</para>
<programlisting>
$ fusermount -u /mnt/my-dir
</programlisting>
</section>
<section xml:id="sec-sshfs-non-interactive">
<title>Non-interactive mounting</title>
<para>
Mounting non-interactively requires some precautions because
<literal>sshfs</literal> will run at boot and under a different
user (root). For obvious reason, you cant input a password, so
public key authentication using an unencrypted key is needed. To
create a new key without a passphrase you can do:
</para>
<programlisting>
$ ssh-keygen -t ed25519 -P '' -f example-key
Generating public/private ed25519 key pair.
Your identification has been saved in test-key
Your public key has been saved in test-key.pub
The key fingerprint is:
SHA256:yjxl3UbTn31fLWeyLYTAKYJPRmzknjQZoyG8gSNEoIE my-user@workstation
</programlisting>
<para>
To keep the key safe, change the ownership to
<literal>root:root</literal> and make sure the permissions are
<literal>600</literal>: OpenSSH normally refuses to use the key if
its not well-protected.
</para>
<para>
The file system can be configured in NixOS via the usual
<link linkend="opt-fileSystems">fileSystems</link> option. Heres
a typical setup:
</para>
<programlisting language="nix">
{
system.fsPackages = [ pkgs.sshfs ];
fileSystems.&quot;/mnt/my-dir&quot; = {
device = &quot;my-user@example.com:/my-dir/&quot;;
fsType = &quot;sshfs&quot;;
options =
[ # Filesystem options
&quot;allow_other&quot; # for non-root access
&quot;_netdev&quot; # this is a network fs
&quot;x-systemd.automount&quot; # mount on demand
# SSH options
&quot;reconnect&quot; # handle connection drops
&quot;ServerAliveInterval=15&quot; # keep connections alive
&quot;IdentityFile=/var/secrets/example-key&quot;
];
};
}
</programlisting>
<para>
More options from <literal>ssh_config(5)</literal> can be given as
well, for example you can change the default SSH port or specify a
jump proxy:
</para>
<programlisting language="nix">
{
options =
[ &quot;ProxyJump=bastion@example.com&quot;
&quot;Port=22&quot;
];
}
</programlisting>
<para>
Its also possible to change the <literal>ssh</literal> command
used by SSHFS to connect to the server. For example:
</para>
<programlisting language="nix">
{
options =
[ (builtins.replaceStrings [&quot; &quot;] [&quot;\\040&quot;]
&quot;ssh_command=${pkgs.openssh}/bin/ssh -v -L 8080:localhost:80&quot;)
];
}
</programlisting>
<note>
<para>
The escaping of spaces is needed because every option is written
to the <literal>/etc/fstab</literal> file, which is a
space-separated table.
</para>
</note>
<section xml:id="sec-sshfs-troubleshooting">
<title>Troubleshooting</title>
<para>
If youre having a hard time figuring out why mounting is
failing, you can add the option
<literal>&quot;debug&quot;</literal>. This enables a verbose log
in SSHFS that you can access via:
</para>
<programlisting>
$ journalctl -u $(systemd-escape -p /mnt/my-dir/).mount
Jun 22 11:41:18 workstation mount[87790]: SSHFS version 3.7.1
Jun 22 11:41:18 workstation mount[87793]: executing &lt;ssh&gt; &lt;-x&gt; &lt;-a&gt; &lt;-oClearAllForwardings=yes&gt; &lt;-oServerAliveInterval=15&gt; &lt;-oIdentityFile=/var/secrets/wrong-key&gt; &lt;-2&gt; &lt;my-user@example.com&gt; &lt;-s&gt; &lt;sftp&gt;
Jun 22 11:41:19 workstation mount[87793]: my-user@example.com: Permission denied (publickey).
Jun 22 11:41:19 workstation mount[87790]: read: Connection reset by peer
Jun 22 11:41:19 workstation systemd[1]: mnt-my\x2ddir.mount: Mount process exited, code=exited, status=1/FAILURE
Jun 22 11:41:19 workstation systemd[1]: mnt-my\x2ddir.mount: Failed with result 'exit-code'.
Jun 22 11:41:19 workstation systemd[1]: Failed to mount /mnt/my-dir.
Jun 22 11:41:19 workstation systemd[1]: mnt-my\x2ddir.mount: Consumed 54ms CPU time, received 2.3K IP traffic, sent 2.7K IP traffic.
</programlisting>
<note>
<para>
If the mount point contains special characters it needs to be
escaped using <literal>systemd-escape</literal>. This is due
to the way systemd converts paths into unit names.
</para>
</note>
</section>
</section>
</section>

View File

@ -1,121 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="module-services-subversion">
<title>Subversion</title>
<para>
<link xlink:href="https://subversion.apache.org/">Subversion</link>
is a centralized version-control system. It can use a
<link xlink:href="http://svnbook.red-bean.com/en/1.7/svn-book.html#svn.serverconfig.choosing">variety
of protocols</link> for communication between client and server.
</para>
<section xml:id="module-services-subversion-apache-httpd">
<title>Subversion inside Apache HTTP</title>
<para>
This section focuses on configuring a web-based server on top of
the Apache HTTP server, which uses
<link xlink:href="http://www.webdav.org/">WebDAV</link>/<link xlink:href="http://www.webdav.org/deltav/WWW10/deltav-intro.htm">DeltaV</link>
for communication.
</para>
<para>
For more information on the general setup, please refer to the
<link xlink:href="http://svnbook.red-bean.com/en/1.7/svn-book.html#svn.serverconfig.httpd">the
appropriate section of the Subversion book</link>.
</para>
<para>
To configure, include in
<literal>/etc/nixos/configuration.nix</literal> code to activate
Apache HTTP, setting
<xref linkend="opt-services.httpd.adminAddr" /> appropriately:
</para>
<programlisting language="nix">
services.httpd.enable = true;
services.httpd.adminAddr = ...;
networking.firewall.allowedTCPPorts = [ 80 443 ];
</programlisting>
<para>
For a simple Subversion server with basic authentication,
configure the Subversion module for Apache as follows, setting
<literal>hostName</literal> and <literal>documentRoot</literal>
appropriately, and <literal>SVNParentPath</literal> to the parent
directory of the repositories,
<literal>AuthzSVNAccessFile</literal> to the location of the
<literal>.authz</literal> file describing access permission, and
<literal>AuthUserFile</literal> to the password file.
</para>
<programlisting language="nix">
services.httpd.extraModules = [
# note that order is *super* important here
{ name = &quot;dav_svn&quot;; path = &quot;${pkgs.apacheHttpdPackages.subversion}/modules/mod_dav_svn.so&quot;; }
{ name = &quot;authz_svn&quot;; path = &quot;${pkgs.apacheHttpdPackages.subversion}/modules/mod_authz_svn.so&quot;; }
];
services.httpd.virtualHosts = {
&quot;svn&quot; = {
hostName = HOSTNAME;
documentRoot = DOCUMENTROOT;
locations.&quot;/svn&quot;.extraConfig = ''
DAV svn
SVNParentPath REPO_PARENT
AuthzSVNAccessFile ACCESS_FILE
AuthName &quot;SVN Repositories&quot;
AuthType Basic
AuthUserFile PASSWORD_FILE
Require valid-user
'';
}
</programlisting>
<para>
The key <literal>&quot;svn&quot;</literal> is just a symbolic name
identifying the virtual host. The
<literal>&quot;/svn&quot;</literal> in
<literal>locations.&quot;/svn&quot;.extraConfig</literal> is the
path underneath which the repositories will be served.
</para>
<para>
<link xlink:href="https://wiki.archlinux.org/index.php/Subversion">This
page</link> explains how to set up the Subversion configuration
itself. This boils down to the following:
</para>
<para>
Underneath <literal>REPO_PARENT</literal> repositories can be set
up as follows:
</para>
<programlisting>
$ svn create REPO_NAME
</programlisting>
<para>
Repository files need to be accessible by
<literal>wwwrun</literal>:
</para>
<programlisting>
$ chown -R wwwrun:wwwrun REPO_PARENT
</programlisting>
<para>
The password file <literal>PASSWORD_FILE</literal> can be created
as follows:
</para>
<programlisting>
$ htpasswd -cs PASSWORD_FILE USER_NAME
</programlisting>
<para>
Additional users can be set up similarly, omitting the
<literal>c</literal> flag:
</para>
<programlisting>
$ htpasswd -s PASSWORD_FILE USER_NAME
</programlisting>
<para>
The file describing access permissions
<literal>ACCESS_FILE</literal> will look something like the
following:
</para>
<programlisting language="nix">
[/]
* = r
[REPO_NAME:/]
USER_NAME = rw
</programlisting>
<para>
The Subversion repositories will be accessible as
<literal>http://HOSTNAME/svn/REPO_NAME</literal>.
</para>
</section>
</chapter>

View File

@ -1,105 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-user-management">
<title>User Management</title>
<para>
NixOS supports both declarative and imperative styles of user
management. In the declarative style, users are specified in
<literal>configuration.nix</literal>. For instance, the following
states that a user account named <literal>alice</literal> shall
exist:
</para>
<programlisting language="nix">
users.users.alice = {
isNormalUser = true;
home = &quot;/home/alice&quot;;
description = &quot;Alice Foobar&quot;;
extraGroups = [ &quot;wheel&quot; &quot;networkmanager&quot; ];
openssh.authorizedKeys.keys = [ &quot;ssh-dss AAAAB3Nza... alice@foobar&quot; ];
};
</programlisting>
<para>
Note that <literal>alice</literal> is a member of the
<literal>wheel</literal> and <literal>networkmanager</literal>
groups, which allows her to use <literal>sudo</literal> to execute
commands as <literal>root</literal> and to configure the network,
respectively. Also note the SSH public key that allows remote logins
with the corresponding private key. Users created in this way do not
have a password by default, so they cannot log in via mechanisms
that require a password. However, you can use the
<literal>passwd</literal> program to set a password, which is
retained across invocations of <literal>nixos-rebuild</literal>.
</para>
<para>
If you set <xref linkend="opt-users.mutableUsers" /> to false, then
the contents of <literal>/etc/passwd</literal> and
<literal>/etc/group</literal> will be congruent to your NixOS
configuration. For instance, if you remove a user from
<xref linkend="opt-users.users" /> and run nixos-rebuild, the user
account will cease to exist. Also, imperative commands for managing
users and groups, such as useradd, are no longer available.
Passwords may still be assigned by setting the users
<link linkend="opt-users.users._name_.hashedPassword">hashedPassword</link>
option. A hashed password can be generated using
<literal>mkpasswd</literal>.
</para>
<para>
A user ID (uid) is assigned automatically. You can also specify a
uid manually by adding
</para>
<programlisting language="nix">
uid = 1000;
</programlisting>
<para>
to the user specification.
</para>
<para>
Groups can be specified similarly. The following states that a group
named <literal>students</literal> shall exist:
</para>
<programlisting language="nix">
users.groups.students.gid = 1000;
</programlisting>
<para>
As with users, the group ID (gid) is optional and will be assigned
automatically if its missing.
</para>
<para>
In the imperative style, users and groups are managed by commands
such as <literal>useradd</literal>, <literal>groupmod</literal> and
so on. For instance, to create a user account named
<literal>alice</literal>:
</para>
<programlisting>
# useradd -m alice
</programlisting>
<para>
To make all nix tools available to this new user use `su - USER`
which opens a login shell (==shell that loads the profile) for given
user. This will create the ~/.nix-defexpr symlink. So run:
</para>
<programlisting>
# su - alice -c &quot;true&quot;
</programlisting>
<para>
The flag <literal>-m</literal> causes the creation of a home
directory for the new user, which is generally what you want. The
user does not have an initial password and therefore cannot log in.
A password can be set using the <literal>passwd</literal> utility:
</para>
<programlisting>
# passwd alice
Enter new UNIX password: ***
Retype new UNIX password: ***
</programlisting>
<para>
A user can be deleted using <literal>userdel</literal>:
</para>
<programlisting>
# userdel -r alice
</programlisting>
<para>
The flag <literal>-r</literal> deletes the users home directory.
Accounts can be modified using <literal>usermod</literal>. Unix
groups can be managed using <literal>groupadd</literal>,
<literal>groupmod</literal> and <literal>groupdel</literal>.
</para>
</chapter>

View File

@ -1,32 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-wayland">
<title>Wayland</title>
<para>
While X11 (see <xref linkend="sec-x11" />) is still the primary
display technology on NixOS, Wayland support is steadily improving.
Where X11 separates the X Server and the window manager, on Wayland
those are combined: a Wayland Compositor is like an X11 window
manager, but also embeds the Wayland <quote>Server</quote>
functionality. This means it is sufficient to install a Wayland
Compositor such as sway without separately enabling a Wayland
server:
</para>
<programlisting language="nix">
programs.sway.enable = true;
</programlisting>
<para>
This installs the sway compositor along with some essential
utilities. Now you can start sway from the TTY console.
</para>
<para>
If you are using a wlroots-based compositor, like sway, and want to
be able to share your screen, you might want to activate this
option:
</para>
<programlisting language="nix">
xdg.portal.wlr.enable = true;
</programlisting>
<para>
and configure Pipewire using
<xref linkend="opt-services.pipewire.enable" /> and related options.
</para>
</chapter>

View File

@ -1,73 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-wireless">
<title>Wireless Networks</title>
<para>
For a desktop installation using NetworkManager (e.g., GNOME), you
just have to make sure the user is in the
<literal>networkmanager</literal> group and you can skip the rest of
this section on wireless networks.
</para>
<para>
NixOS will start wpa_supplicant for you if you enable this setting:
</para>
<programlisting language="nix">
networking.wireless.enable = true;
</programlisting>
<para>
NixOS lets you specify networks for wpa_supplicant declaratively:
</para>
<programlisting language="nix">
networking.wireless.networks = {
echelon = { # SSID with no spaces or special characters
psk = &quot;abcdefgh&quot;;
};
&quot;echelon's AP&quot; = { # SSID with spaces and/or special characters
psk = &quot;ijklmnop&quot;;
};
echelon = { # Hidden SSID
hidden = true;
psk = &quot;qrstuvwx&quot;;
};
free.wifi = {}; # Public wireless network
};
</programlisting>
<para>
Be aware that keys will be written to the nix store in plaintext!
When no networks are set, it will default to using a configuration
file at <literal>/etc/wpa_supplicant.conf</literal>. You should edit
this file yourself to define wireless networks, WPA keys and so on
(see wpa_supplicant.conf(5)).
</para>
<para>
If you are using WPA2 you can generate pskRaw key using
<literal>wpa_passphrase</literal>:
</para>
<programlisting>
$ wpa_passphrase ESSID PSK
network={
ssid=&quot;echelon&quot;
#psk=&quot;abcdefgh&quot;
psk=dca6d6ed41f4ab5a984c9f55f6f66d4efdc720ebf66959810f4329bb391c5435
}
</programlisting>
<programlisting language="nix">
networking.wireless.networks = {
echelon = {
pskRaw = &quot;dca6d6ed41f4ab5a984c9f55f6f66d4efdc720ebf66959810f4329bb391c5435&quot;;
};
};
</programlisting>
<para>
or you can use it to directly generate the
<literal>wpa_supplicant.conf</literal>:
</para>
<programlisting>
# wpa_passphrase ESSID PSK &gt; /etc/wpa_supplicant.conf
</programlisting>
<para>
After you have edited the <literal>wpa_supplicant.conf</literal>,
you need to restart the wpa_supplicant service.
</para>
<programlisting>
# systemctl restart wpa_supplicant.service
</programlisting>
</section>

View File

@ -1,380 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-x11">
<title>X Window System</title>
<para>
The X Window System (X11) provides the basis of NixOS graphical
user interface. It can be enabled as follows:
</para>
<programlisting language="nix">
services.xserver.enable = true;
</programlisting>
<para>
The X server will automatically detect and use the appropriate video
driver from a set of X.org drivers (such as <literal>vesa</literal>
and <literal>intel</literal>). You can also specify a driver
manually, e.g.
</para>
<programlisting language="nix">
services.xserver.videoDrivers = [ &quot;r128&quot; ];
</programlisting>
<para>
to enable X.orgs <literal>xf86-video-r128</literal> driver.
</para>
<para>
You also need to enable at least one desktop or window manager.
Otherwise, you can only log into a plain undecorated
<literal>xterm</literal> window. Thus you should pick one or more of
the following lines:
</para>
<programlisting language="nix">
services.xserver.desktopManager.plasma5.enable = true;
services.xserver.desktopManager.xfce.enable = true;
services.xserver.desktopManager.gnome.enable = true;
services.xserver.desktopManager.mate.enable = true;
services.xserver.windowManager.xmonad.enable = true;
services.xserver.windowManager.twm.enable = true;
services.xserver.windowManager.icewm.enable = true;
services.xserver.windowManager.i3.enable = true;
services.xserver.windowManager.herbstluftwm.enable = true;
</programlisting>
<para>
NixOSs default <emphasis>display manager</emphasis> (the program
that provides a graphical login prompt and manages the X server) is
LightDM. You can select an alternative one by picking one of the
following lines:
</para>
<programlisting language="nix">
services.xserver.displayManager.sddm.enable = true;
services.xserver.displayManager.gdm.enable = true;
</programlisting>
<para>
You can set the keyboard layout (and optionally the layout variant):
</para>
<programlisting language="nix">
services.xserver.layout = &quot;de&quot;;
services.xserver.xkbVariant = &quot;neo&quot;;
</programlisting>
<para>
The X server is started automatically at boot time. If you dont
want this to happen, you can set:
</para>
<programlisting language="nix">
services.xserver.autorun = false;
</programlisting>
<para>
The X server can then be started manually:
</para>
<programlisting>
# systemctl start display-manager.service
</programlisting>
<para>
On 64-bit systems, if you want OpenGL for 32-bit programs such as in
Wine, you should also set the following:
</para>
<programlisting language="nix">
hardware.opengl.driSupport32Bit = true;
</programlisting>
<section xml:id="sec-x11-auto-login">
<title>Auto-login</title>
<para>
The x11 login screen can be skipped entirely, automatically
logging you into your window manager and desktop environment when
you boot your computer.
</para>
<para>
This is especially helpful if you have disk encryption enabled.
Since you already have to provide a password to decrypt your disk,
entering a second password to login can be redundant.
</para>
<para>
To enable auto-login, you need to define your default window
manager and desktop environment. If you wanted no desktop
environment and i3 as your your window manager, youd define:
</para>
<programlisting language="nix">
services.xserver.displayManager.defaultSession = &quot;none+i3&quot;;
</programlisting>
<para>
Every display manager in NixOS supports auto-login, here is an
example using lightdm for a user <literal>alice</literal>:
</para>
<programlisting language="nix">
services.xserver.displayManager.lightdm.enable = true;
services.xserver.displayManager.autoLogin.enable = true;
services.xserver.displayManager.autoLogin.user = &quot;alice&quot;;
</programlisting>
</section>
<section xml:id="sec-x11--graphics-cards-intel">
<title>Intel Graphics drivers</title>
<para>
There are two choices for Intel Graphics drivers in X.org:
<literal>modesetting</literal> (included in the xorg-server
itself) and <literal>intel</literal> (provided by the package
xf86-video-intel).
</para>
<para>
The default and recommended is <literal>modesetting</literal>. It
is a generic driver which uses the kernel
<link xlink:href="https://en.wikipedia.org/wiki/Mode_setting">mode
setting</link> (KMS) mechanism. It supports Glamor (2D graphics
acceleration via OpenGL) and is actively maintained but may
perform worse in some cases (like in old chipsets).
</para>
<para>
The second driver, <literal>intel</literal>, is specific to Intel
GPUs, but not recommended by most distributions: it lacks several
modern features (for example, it doesnt support Glamor) and the
package hasnt been officially updated since 2015.
</para>
<para>
The results vary depending on the hardware, so you may have to try
both drivers. Use the option
<xref linkend="opt-services.xserver.videoDrivers" /> to set one.
The recommended configuration for modern systems is:
</para>
<programlisting language="nix">
services.xserver.videoDrivers = [ &quot;modesetting&quot; ];
</programlisting>
<para>
If you experience screen tearing no matter what, this
configuration was reported to resolve the issue:
</para>
<programlisting language="nix">
services.xserver.videoDrivers = [ &quot;intel&quot; ];
services.xserver.deviceSection = ''
Option &quot;DRI&quot; &quot;2&quot;
Option &quot;TearFree&quot; &quot;true&quot;
'';
</programlisting>
<para>
Note that this will likely downgrade the performance compared to
<literal>modesetting</literal> or <literal>intel</literal> with
DRI 3 (default).
</para>
</section>
<section xml:id="sec-x11-graphics-cards-nvidia">
<title>Proprietary NVIDIA drivers</title>
<para>
NVIDIA provides a proprietary driver for its graphics cards that
has better 3D performance than the X.org drivers. It is not
enabled by default because its not free software. You can enable
it as follows:
</para>
<programlisting language="nix">
services.xserver.videoDrivers = [ &quot;nvidia&quot; ];
</programlisting>
<para>
Or if you have an older card, you may have to use one of the
legacy drivers:
</para>
<programlisting language="nix">
services.xserver.videoDrivers = [ &quot;nvidiaLegacy390&quot; ];
services.xserver.videoDrivers = [ &quot;nvidiaLegacy340&quot; ];
services.xserver.videoDrivers = [ &quot;nvidiaLegacy304&quot; ];
</programlisting>
<para>
You may need to reboot after enabling this driver to prevent a
clash with other kernel modules.
</para>
</section>
<section xml:id="sec-x11--graphics-cards-amd">
<title>Proprietary AMD drivers</title>
<para>
AMD provides a proprietary driver for its graphics cards that is
not enabled by default because its not Free Software, is often
broken in nixpkgs and as of this writing doesnt offer more
features or performance. If you still want to use it anyway, you
need to explicitly set:
</para>
<programlisting language="nix">
services.xserver.videoDrivers = [ &quot;amdgpu-pro&quot; ];
</programlisting>
<para>
You will need to reboot after enabling this driver to prevent a
clash with other kernel modules.
</para>
</section>
<section xml:id="sec-x11-touchpads">
<title>Touchpads</title>
<para>
Support for Synaptics touchpads (found in many laptops such as the
Dell Latitude series) can be enabled as follows:
</para>
<programlisting language="nix">
services.xserver.libinput.enable = true;
</programlisting>
<para>
The driver has many options (see <xref linkend="ch-options" />).
For instance, the following disables tap-to-click behavior:
</para>
<programlisting language="nix">
services.xserver.libinput.touchpad.tapping = false;
</programlisting>
<para>
Note: the use of <literal>services.xserver.synaptics</literal> is
deprecated since NixOS 17.09.
</para>
</section>
<section xml:id="sec-x11-gtk-and-qt-themes">
<title>GTK/Qt themes</title>
<para>
GTK themes can be installed either to user profile or system-wide
(via <literal>environment.systemPackages</literal>). To make Qt 5
applications look similar to GTK ones, you can use the following
configuration:
</para>
<programlisting language="nix">
qt.enable = true;
qt.platformTheme = &quot;gtk2&quot;;
qt.style = &quot;gtk2&quot;;
</programlisting>
</section>
<section xml:id="custom-xkb-layouts">
<title>Custom XKB layouts</title>
<para>
It is possible to install custom
<link xlink:href="https://en.wikipedia.org/wiki/X_keyboard_extension">
XKB </link> keyboard layouts using the option
<literal>services.xserver.extraLayouts</literal>.
</para>
<para>
As a first example, we are going to create a layout based on the
basic US layout, with an additional layer to type some greek
symbols by pressing the right-alt key.
</para>
<para>
Create a file called <literal>us-greek</literal> with the
following content (under a directory called
<literal>symbols</literal>; its an XKB peculiarity that will help
with testing):
</para>
<programlisting language="nix">
xkb_symbols &quot;us-greek&quot;
{
include &quot;us(basic)&quot; // includes the base US keys
include &quot;level3(ralt_switch)&quot; // configures right alt as a third level switch
key &lt;LatA&gt; { [ a, A, Greek_alpha ] };
key &lt;LatB&gt; { [ b, B, Greek_beta ] };
key &lt;LatG&gt; { [ g, G, Greek_gamma ] };
key &lt;LatD&gt; { [ d, D, Greek_delta ] };
key &lt;LatZ&gt; { [ z, Z, Greek_zeta ] };
};
</programlisting>
<para>
A minimal layout specification must include the following:
</para>
<programlisting language="nix">
services.xserver.extraLayouts.us-greek = {
description = &quot;US layout with alt-gr greek&quot;;
languages = [ &quot;eng&quot; ];
symbolsFile = /yourpath/symbols/us-greek;
};
</programlisting>
<note>
<para>
The name (after <literal>extraLayouts.</literal>) should match
the one given to the <literal>xkb_symbols</literal> block.
</para>
</note>
<para>
Applying this customization requires rebuilding several packages,
and a broken XKB file can lead to the X session crashing at login.
Therefore, youre strongly advised to <emphasis role="strong">test
your layout before applying it</emphasis>:
</para>
<programlisting>
$ nix-shell -p xorg.xkbcomp
$ setxkbmap -I/yourpath us-greek -print | xkbcomp -I/yourpath - $DISPLAY
</programlisting>
<para>
You can inspect the predefined XKB files for examples:
</para>
<programlisting>
$ echo &quot;$(nix-build --no-out-link '&lt;nixpkgs&gt;' -A xorg.xkeyboardconfig)/etc/X11/xkb/&quot;
</programlisting>
<para>
Once the configuration is applied, and you did a logout/login
cycle, the layout should be ready to use. You can try it by e.g.
running <literal>setxkbmap us-greek</literal> and then type
<literal>&lt;alt&gt;+a</literal> (it may not get applied in your
terminal straight away). To change the default, the usual
<literal>services.xserver.layout</literal> option can still be
used.
</para>
<para>
A layout can have several other components besides
<literal>xkb_symbols</literal>, for example we will define new
keycodes for some multimedia key and bind these to some symbol.
</para>
<para>
Use the <emphasis>xev</emphasis> utility from
<literal>pkgs.xorg.xev</literal> to find the codes of the keys of
interest, then create a <literal>media-key</literal> file to hold
the keycodes definitions
</para>
<programlisting language="nix">
xkb_keycodes &quot;media&quot;
{
&lt;volUp&gt; = 123;
&lt;volDown&gt; = 456;
}
</programlisting>
<para>
Now use the newly define keycodes in <literal>media-sym</literal>:
</para>
<programlisting language="nix">
xkb_symbols &quot;media&quot;
{
key.type = &quot;ONE_LEVEL&quot;;
key &lt;volUp&gt; { [ XF86AudioLowerVolume ] };
key &lt;volDown&gt; { [ XF86AudioRaiseVolume ] };
}
</programlisting>
<para>
As before, to install the layout do
</para>
<programlisting language="nix">
services.xserver.extraLayouts.media = {
description = &quot;Multimedia keys remapping&quot;;
languages = [ &quot;eng&quot; ];
symbolsFile = /path/to/media-key;
keycodesFile = /path/to/media-sym;
};
</programlisting>
<note>
<para>
The function
<literal>pkgs.writeText &lt;filename&gt; &lt;content&gt;</literal>
can be useful if you prefer to keep the layout definitions
inside the NixOS configuration.
</para>
</note>
<para>
Unfortunately, the Xorg server does not (currently) support
setting a keymap directly but relies instead on XKB rules to
select the matching components (keycodes, types, …) of a layout.
This means that components other than symbols wont be loaded by
default. As a workaround, you can set the keymap using
<literal>setxkbmap</literal> at the start of the session with:
</para>
<programlisting language="nix">
services.xserver.displayManager.sessionCommands = &quot;setxkbmap -keycodes media&quot;;
</programlisting>
<para>
If you are manually starting the X server, you should set the
argument <literal>-xkbdir /etc/X11/xkb</literal>, otherwise X
wont find your layout files. For example with
<literal>xinit</literal> run
</para>
<programlisting>
$ xinit -- -xkbdir /etc/X11/xkb
</programlisting>
<para>
To learn how to write layouts take a look at the XKB
<link xlink:href="https://www.x.org/releases/current/doc/xorg-docs/input/XKB-Enhancing.html#Defining_New_Layouts">documentation
</link>. More example layouts can also be found
<link xlink:href="https://wiki.archlinux.org/index.php/X_KeyBoard_extension#Basic_examples">here
</link>.
</para>
</section>
</chapter>

View File

@ -1,70 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-xfce">
<title>Xfce Desktop Environment</title>
<para>
To enable the Xfce Desktop Environment, set
</para>
<programlisting language="nix">
services.xserver.desktopManager.xfce.enable = true;
services.xserver.displayManager.defaultSession = &quot;xfce&quot;;
</programlisting>
<para>
Optionally, <emphasis>picom</emphasis> can be enabled for nice
graphical effects, some example settings:
</para>
<programlisting language="nix">
services.picom = {
enable = true;
fade = true;
inactiveOpacity = 0.9;
shadow = true;
fadeDelta = 4;
};
</programlisting>
<para>
Some Xfce programs are not installed automatically. To install them
manually (system wide), put them into your
<xref linkend="opt-environment.systemPackages" /> from
<literal>pkgs.xfce</literal>.
</para>
<section xml:id="sec-xfce-thunar-plugins">
<title>Thunar</title>
<para>
Thunar (the Xfce file manager) is automatically enabled when Xfce
is enabled. To enable Thunar without enabling Xfce, use the
configuration option <xref linkend="opt-programs.thunar.enable" />
instead of simply adding <literal>pkgs.xfce.thunar</literal> to
<xref linkend="opt-environment.systemPackages" />.
</para>
<para>
If youd like to add extra plugins to Thunar, add them to
<xref linkend="opt-programs.thunar.plugins" />. You shouldnt just
add them to <xref linkend="opt-environment.systemPackages" />.
</para>
</section>
<section xml:id="sec-xfce-troubleshooting">
<title>Troubleshooting</title>
<para>
Even after enabling udisks2, volume management might not work.
Thunar and/or the desktop takes time to show up. Thunar will spit
out this kind of message on start (look at
<literal>journalctl --user -b</literal>).
</para>
<programlisting>
Thunar:2410): GVFS-RemoteVolumeMonitor-WARNING **: remote volume monitor with dbus name org.gtk.Private.UDisks2VolumeMonitor is not supported
</programlisting>
<para>
This is caused by some needed GNOME services not running. This is
all fixed by enabling <quote>Launch GNOME services on
startup</quote> in the Advanced tab of the Session and Startup
settings panel. Alternatively, you can run this command to do the
same thing.
</para>
<programlisting>
$ xfconf-query -c xfce4-session -p /compat/LaunchGNOME -s true
</programlisting>
<para>
It is necessary to log out and log in again for this to take
effect.
</para>
</section>
</chapter>

View File

@ -1,52 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="chap-contributing">
<title>Contributing to this manual</title>
<para>
The
<link xlink:href="https://en.wikipedia.org/wiki/DocBook">DocBook</link>
and CommonMark sources of the NixOS manual are in the
<link xlink:href="https://github.com/NixOS/nixpkgs/tree/master/nixos/doc/manual">nixos/doc/manual</link>
subdirectory of the
<link xlink:href="https://github.com/NixOS/nixpkgs">Nixpkgs</link>
repository.
</para>
<para>
You can quickly check your edits with the following:
</para>
<programlisting>
$ cd /path/to/nixpkgs
$ ./nixos/doc/manual/md-to-db.sh
$ nix-build nixos/release.nix -A manual.x86_64-linux
</programlisting>
<para>
If the build succeeds, the manual will be in
<literal>./result/share/doc/nixos/index.html</literal>.
</para>
<para>
<emphasis role="strong">Contributing to the man pages</emphasis>
</para>
<para>
The man pages are written in
<link xlink:href="https://en.wikipedia.org/wiki/DocBook">DocBook</link>
which is XML.
</para>
<para>
To see what your edits look like:
</para>
<programlisting>
$ cd /path/to/nixpkgs
$ nix-build nixos/release.nix -A manpages.x86_64-linux
</programlisting>
<para>
You can then read the man page you edited by running
</para>
<programlisting>
$ man --manpath=result/share/man nixos-rebuild # Replace nixos-rebuild with the command whose manual you edited
</programlisting>
<para>
If youre on a different architecture thats supported by NixOS
(check nixos/release.nix) then replace
<literal>x86_64-linux</literal> with the architecture.
<literal>nix-build</literal> will complain otherwise, but should
also tell you which architecture you have + the supported ones.
</para>
</chapter>

View File

@ -1,150 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-activation-script">
<title>Activation script</title>
<para>
The activation script is a bash script called to activate the new
configuration which resides in a NixOS system in
<literal>$out/activate</literal>. Since its contents depend on your
system configuration, the contents may differ. This chapter explains
how the script works in general and some common NixOS snippets.
Please be aware that the script is executed on every boot and system
switch, so tasks that can be performed in other places should be
performed there (for example letting a directory of a service be
created by systemd using mechanisms like
<literal>StateDirectory</literal>,
<literal>CacheDirectory</literal>, … or if thats not possible using
<literal>preStart</literal> of the service).
</para>
<para>
Activation scripts are defined as snippets using
<xref linkend="opt-system.activationScripts" />. They can either be
a simple multiline string or an attribute set that can depend on
other snippets. The builder for the activation script will take
these dependencies into account and order the snippets accordingly.
As a simple example:
</para>
<programlisting language="nix">
system.activationScripts.my-activation-script = {
deps = [ &quot;etc&quot; ];
# supportsDryActivation = true;
text = ''
echo &quot;Hallo i bims&quot;
'';
};
</programlisting>
<para>
This example creates an activation script snippet that is run after
the <literal>etc</literal> snippet. The special variable
<literal>supportsDryActivation</literal> can be set so the snippet
is also run when <literal>nixos-rebuild dry-activate</literal> is
run. To differentiate between real and dry activation, the
<literal>$NIXOS_ACTION</literal> environment variable can be read
which is set to <literal>dry-activate</literal> when a dry
activation is done.
</para>
<para>
An activation script can write to special files instructing
<literal>switch-to-configuration</literal> to restart/reload units.
The script will take these requests into account and will
incorporate the unit configuration as described above. This means
that the activation script will <quote>fake</quote> a modified unit
file and <literal>switch-to-configuration</literal> will act
accordingly. By doing so, configuration like
<link linkend="opt-systemd.services">systemd.services.&lt;name&gt;.restartIfChanged</link>
is respected. Since the activation script is run
<emphasis role="strong">after</emphasis> services are already
stopped,
<link linkend="opt-systemd.services">systemd.services.&lt;name&gt;.stopIfChanged</link>
cannot be taken into account anymore and the unit is always
restarted instead of being stopped and started afterwards.
</para>
<para>
The files that can be written to are
<literal>/run/nixos/activation-restart-list</literal> and
<literal>/run/nixos/activation-reload-list</literal> with their
respective counterparts for dry activation being
<literal>/run/nixos/dry-activation-restart-list</literal> and
<literal>/run/nixos/dry-activation-reload-list</literal>. Those
files can contain newline-separated lists of unit names where
duplicates are being ignored. These files are not create
automatically and activation scripts must take the possibility into
account that they have to create them first.
</para>
<section xml:id="sec-activation-script-nixos-snippets">
<title>NixOS snippets</title>
<para>
There are some snippets NixOS enables by default because disabling
them would most likely break your system. This section lists a few
of them and what they do:
</para>
<itemizedlist spacing="compact">
<listitem>
<para>
<literal>binsh</literal> creates <literal>/bin/sh</literal>
which points to the runtime shell
</para>
</listitem>
<listitem>
<para>
<literal>etc</literal> sets up the contents of
<literal>/etc</literal>, this includes systemd units and
excludes <literal>/etc/passwd</literal>,
<literal>/etc/group</literal>, and
<literal>/etc/shadow</literal> (which are managed by the
<literal>users</literal> snippet)
</para>
</listitem>
<listitem>
<para>
<literal>hostname</literal> sets the systems hostname in the
kernel (not in <literal>/etc</literal>)
</para>
</listitem>
<listitem>
<para>
<literal>modprobe</literal> sets the path to the
<literal>modprobe</literal> binary for module auto-loading
</para>
</listitem>
<listitem>
<para>
<literal>nix</literal> prepares the nix store and adds a
default initial channel
</para>
</listitem>
<listitem>
<para>
<literal>specialfs</literal> is responsible for mounting
filesystems like <literal>/proc</literal> and
<literal>sys</literal>
</para>
</listitem>
<listitem>
<para>
<literal>users</literal> creates and removes users and groups
by managing <literal>/etc/passwd</literal>,
<literal>/etc/group</literal> and
<literal>/etc/shadow</literal>. This also creates home
directories
</para>
</listitem>
<listitem>
<para>
<literal>usrbinenv</literal> creates
<literal>/usr/bin/env</literal>
</para>
</listitem>
<listitem>
<para>
<literal>var</literal> creates some directories in
<literal>/var</literal> that are not service-specific
</para>
</listitem>
<listitem>
<para>
<literal>wrappers</literal> creates setuid wrappers like
<literal>ping</literal> and <literal>sudo</literal>
</para>
</listitem>
</itemizedlist>
</section>
</section>

View File

@ -1,58 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-assertions">
<title>Warnings and Assertions</title>
<para>
When configuration problems are detectable in a module, it is a good
idea to write an assertion or warning. Doing so provides clear
feedback to the user and prevents errors after the build.
</para>
<para>
Although Nix has the <literal>abort</literal> and
<literal>builtins.trace</literal>
<link xlink:href="https://nixos.org/nix/manual/#ssec-builtins">functions</link>
to perform such tasks, they are not ideally suited for NixOS
modules. Instead of these functions, you can declare your warnings
and assertions using the NixOS module system.
</para>
<section xml:id="sec-assertions-warnings">
<title>Warnings</title>
<para>
This is an example of using <literal>warnings</literal>.
</para>
<programlisting language="nix">
{ config, lib, ... }:
{
config = lib.mkIf config.services.foo.enable {
warnings =
if config.services.foo.bar
then [ ''You have enabled the bar feature of the foo service.
This is known to cause some specific problems in certain situations.
'' ]
else [];
}
}
</programlisting>
</section>
<section xml:id="sec-assertions-assetions">
<title>Assertions</title>
<para>
This example, extracted from the
<link xlink:href="https://github.com/NixOS/nixpkgs/blob/release-17.09/nixos/modules/services/logging/syslogd.nix"><literal>syslogd</literal>
module</link> shows how to use <literal>assertions</literal>.
Since there can only be one active syslog daemon at a time, an
assertion is useful to prevent such a broken system from being
built.
</para>
<programlisting language="nix">
{ config, lib, ... }:
{
config = lib.mkIf config.services.syslogd.enable {
assertions =
[ { assertion = !config.services.rsyslogd.enable;
message = &quot;rsyslogd conflicts with syslogd&quot;;
}
];
}
}
</programlisting>
</section>
</section>

View File

@ -1,73 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-experimental-bootspec">
<title>Experimental feature: Bootspec</title>
<para>
Bootspec is a experimental feature, introduced in the
<link xlink:href="https://github.com/NixOS/rfcs/pull/125">RFC-0125
proposal</link>, the reference implementation can be found
<link xlink:href="https://github.com/NixOS/nixpkgs/pull/172237">there</link>
in order to standardize bootloader support and advanced boot
workflows such as SecureBoot and potentially more.
</para>
<para>
You can enable the creation of bootspec documents through
<link xlink:href="options.html#opt-boot.bootspec.enable"><literal>boot.bootspec.enable = true</literal></link>,
which will prompt a warning until
<link xlink:href="https://github.com/NixOS/rfcs/pull/125">RFC-0125</link>
is officially merged.
</para>
<section xml:id="sec-experimental-bootspec-schema">
<title>Schema</title>
<para>
The bootspec schema is versioned and validated against
<link xlink:href="https://cuelang.org/">a CUE schema file</link>
which should considered as the source of truth for your
applications.
</para>
<para>
You will find the current version
<link xlink:href="../../../modules/system/activation/bootspec.cue">here</link>.
</para>
</section>
<section xml:id="sec-experimental-bootspec-extensions">
<title>Extensions mechanism</title>
<para>
Bootspec cannot account for all usecases.
</para>
<para>
For this purpose, Bootspec offers a generic extension facility
<link xlink:href="options.html#opt-boot.bootspec.extensions"><literal>boot.bootspec.extensions</literal></link>
which can be used to inject any data needed for your usecases.
</para>
<para>
An example for SecureBoot is to get the Nix store path to
<literal>/etc/os-release</literal> in order to bake it into a
unified kernel image:
</para>
<programlisting language="nix">
{ config, lib, ... }: {
boot.bootspec.extensions = {
&quot;org.secureboot.osRelease&quot; = config.environment.etc.&quot;os-release&quot;.source;
};
}
</programlisting>
<para>
To reduce incompatibility and prevent names from clashing between
applications, it is <emphasis role="strong">highly
recommended</emphasis> to use a unique namespace for your
extensions.
</para>
</section>
<section xml:id="sec-experimental-bootspec-external-bootloaders">
<title>External bootloaders</title>
<para>
It is possible to enable your own bootloader through
<link xlink:href="options.html#opt-boot.loader.external.installHook"><literal>boot.loader.external.installHook</literal></link>
which can wrap an existing bootloader.
</para>
<para>
Currently, there is no good story to compose existing bootloaders
to enrich their features, e.g. SecureBoot, etc. It will be
necessary to reimplement or reuse existing parts.
</para>
</section>
</chapter>

View File

@ -1,124 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-building-parts">
<title>Building Specific Parts of NixOS</title>
<para>
With the command <literal>nix-build</literal>, you can build
specific parts of your NixOS configuration. This is done as follows:
</para>
<programlisting>
$ cd /path/to/nixpkgs/nixos
$ nix-build -A config.option
</programlisting>
<para>
where <literal>option</literal> is a NixOS option with type
<quote>derivation</quote> (i.e. something that can be built).
Attributes of interest include:
</para>
<variablelist>
<varlistentry>
<term>
<literal>system.build.toplevel</literal>
</term>
<listitem>
<para>
The top-level option that builds the entire NixOS system.
Everything else in your configuration is indirectly pulled in
by this option. This is what <literal>nixos-rebuild</literal>
builds and what <literal>/run/current-system</literal> points
to afterwards.
</para>
<para>
A shortcut to build this is:
</para>
<programlisting>
$ nix-build -A system
</programlisting>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>system.build.manual.manualHTML</literal>
</term>
<listitem>
<para>
The NixOS manual.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>system.build.etc</literal>
</term>
<listitem>
<para>
A tree of symlinks that form the static parts of
<literal>/etc</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>system.build.initialRamdisk</literal> ,
<literal>system.build.kernel</literal>
</term>
<listitem>
<para>
The initial ramdisk and kernel of the system. This allows a
quick way to test whether the kernel and the initial ramdisk
boot correctly, by using QEMUs <literal>-kernel</literal> and
<literal>-initrd</literal> options:
</para>
<programlisting>
$ nix-build -A config.system.build.initialRamdisk -o initrd
$ nix-build -A config.system.build.kernel -o kernel
$ qemu-system-x86_64 -kernel ./kernel/bzImage -initrd ./initrd/initrd -hda /dev/null
</programlisting>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>system.build.nixos-rebuild</literal> ,
<literal>system.build.nixos-install</literal> ,
<literal>system.build.nixos-generate-config</literal>
</term>
<listitem>
<para>
These build the corresponding NixOS commands.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>systemd.units.unit-name.unit</literal>
</term>
<listitem>
<para>
This builds the unit with the specified name. Note that since
unit names contain dots (e.g.
<literal>httpd.service</literal>), you need to put them
between quotes, like this:
</para>
<programlisting>
$ nix-build -A 'config.systemd.units.&quot;httpd.service&quot;.unit'
</programlisting>
<para>
You can also test individual units, without rebuilding the
whole system, by putting them in
<literal>/run/systemd/system</literal>:
</para>
<programlisting>
$ cp $(nix-build -A 'config.systemd.units.&quot;httpd.service&quot;.unit')/httpd.service \
/run/systemd/system/tmp-httpd.service
# systemctl daemon-reload
# systemctl start tmp-httpd.service
</programlisting>
<para>
Note that the unit must not have the same name as any unit in
<literal>/etc/systemd/system</literal> since those take
precedence over <literal>/run/systemd/system</literal>. Thats
why the unit is installed as
<literal>tmp-httpd.service</literal> here.
</para>
</listitem>
</varlistentry>
</variablelist>
</chapter>

View File

@ -1,87 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-freeform-modules">
<title>Freeform modules</title>
<para>
Freeform modules allow you to define values for option paths that
have not been declared explicitly. This can be used to add
attribute-specific types to what would otherwise have to be
<literal>attrsOf</literal> options in order to accept all attribute
names.
</para>
<para>
This feature can be enabled by using the attribute
<literal>freeformType</literal> to define a freeform type. By doing
this, all assignments without an associated option will be merged
using the freeform type and combined into the resulting
<literal>config</literal> set. Since this feature nullifies name
checking for entire option trees, it is only recommended for use in
submodules.
</para>
<anchor xml:id="ex-freeform-module" />
<para>
<emphasis role="strong">Example: Freeform submodule</emphasis>
</para>
<para>
The following shows a submodule assigning a freeform type that
allows arbitrary attributes with <literal>str</literal> values below
<literal>settings</literal>, but also declares an option for the
<literal>settings.port</literal> attribute to have it type-checked
and assign a default value. See
<link linkend="ex-settings-typed-attrs">Example: Declaring a
type-checked <literal>settings</literal> attribute</link> for a more
complete example.
</para>
<programlisting language="nix">
{ lib, config, ... }: {
options.settings = lib.mkOption {
type = lib.types.submodule {
freeformType = with lib.types; attrsOf str;
# We want this attribute to be checked for the correct type
options.port = lib.mkOption {
type = lib.types.port;
# Declaring the option also allows defining a default value
default = 8080;
};
};
};
}
</programlisting>
<para>
And the following shows what such a module then allows
</para>
<programlisting language="nix">
{
# Not a declared option, but the freeform type allows this
settings.logLevel = &quot;debug&quot;;
# Not allowed because the the freeform type only allows strings
# settings.enable = true;
# Allowed because there is a port option declared
settings.port = 80;
# Not allowed because the port option doesn't allow strings
# settings.port = &quot;443&quot;;
}
</programlisting>
<note>
<para>
Freeform attributes cannot depend on other attributes of the same
set without infinite recursion:
</para>
<programlisting language="nix">
{
# This throws infinite recursion encountered
settings.logLevel = lib.mkIf (config.settings.port == 80) &quot;debug&quot;;
}
</programlisting>
<para>
To prevent this, declare options for all attributes that need to
depend on others. For above example this means to declare
<literal>logLevel</literal> to be an option.
</para>
</note>
</section>

View File

@ -1,47 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-importing-modules">
<title>Importing Modules</title>
<para>
Sometimes NixOS modules need to be used in configuration but exist
outside of Nixpkgs. These modules can be imported:
</para>
<programlisting language="nix">
{ config, lib, pkgs, ... }:
{
imports =
[ # Use a locally-available module definition in
# ./example-module/default.nix
./example-module
];
services.exampleModule.enable = true;
}
</programlisting>
<para>
The environment variable <literal>NIXOS_EXTRA_MODULE_PATH</literal>
is an absolute path to a NixOS module that is included alongside the
Nixpkgs NixOS modules. Like any NixOS module, this module can import
additional modules:
</para>
<programlisting language="nix">
# ./module-list/default.nix
[
./example-module1
./example-module2
]
</programlisting>
<programlisting language="nix">
# ./extra-module/default.nix
{ imports = import ./module-list.nix; }
</programlisting>
<programlisting language="nix">
# NIXOS_EXTRA_MODULE_PATH=/absolute/path/to/extra-module
{ config, lib, pkgs, ... }:
{
# No `imports` needed
services.exampleModule1.enable = true;
}
</programlisting>
</section>

View File

@ -1,10 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-linking-nixos-tests-to-packages">
<title>Linking NixOS tests to packages</title>
<para>
You can link NixOS module tests to the packages that they exercised,
so that the tests can be run automatically during code review when
the package gets changed. This is
<link xlink:href="https://nixos.org/manual/nixpkgs/stable/#ssec-nixos-tests-linking">described
in the nixpkgs manual</link>.
</para>
</section>

View File

@ -1,97 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-meta-attributes">
<title>Meta Attributes</title>
<para>
Like Nix packages, NixOS modules can declare meta-attributes to
provide extra information. Module meta attributes are defined in the
<literal>meta.nix</literal> special module.
</para>
<para>
<literal>meta</literal> is a top level attribute like
<literal>options</literal> and <literal>config</literal>. Available
meta-attributes are <literal>maintainers</literal>,
<literal>doc</literal>, and <literal>buildDocsInSandbox</literal>.
</para>
<para>
Each of the meta-attributes must be defined at most once per module
file.
</para>
<programlisting language="nix">
{ config, lib, pkgs, ... }:
{
options = {
...
};
config = {
...
};
meta = {
maintainers = with lib.maintainers; [ ericsagnes ];
doc = ./default.md;
buildDocsInSandbox = true;
};
}
</programlisting>
<itemizedlist>
<listitem>
<para>
<literal>maintainers</literal> contains a list of the module
maintainers.
</para>
</listitem>
<listitem>
<para>
<literal>doc</literal> points to a valid
<link xlink:href="https://nixos.org/manual/nixpkgs/unstable/#sec-contributing-markup">Nixpkgs-flavored
CommonMark</link> file containing the module documentation. Its
contents is automatically added to
<xref linkend="ch-configuration" />. Changes to a module
documentation have to be checked to not break building the NixOS
manual:
</para>
<programlisting>
$ nix-build nixos/release.nix -A manual.x86_64-linux
</programlisting>
</listitem>
<listitem>
<para>
<literal>buildDocsInSandbox</literal> indicates whether the
option documentation for the module can be built in a derivation
sandbox. This option is currently only honored for modules
shipped by nixpkgs. User modules and modules taken from
<literal>NIXOS_EXTRA_MODULE_PATH</literal> are always built
outside of the sandbox, as has been the case in previous
releases.
</para>
<para>
Building NixOS option documentation in a sandbox allows caching
of the built documentation, which greatly decreases the amount
of time needed to evaluate a system configuration that has NixOS
documentation enabled. The sandbox also restricts which
attributes may be referenced by documentation attributes (such
as option descriptions) to the <literal>options</literal> and
<literal>lib</literal> module arguments and the
<literal>pkgs.formats</literal> attribute of the
<literal>pkgs</literal> argument, <literal>config</literal> and
the rest of <literal>pkgs</literal> are disallowed and will
cause doc build failures when used. This restriction is
necessary because we cannot reproduce the full nixpkgs
instantiation with configuration and overlays from a system
configuration inside the sandbox. The <literal>options</literal>
argument only includes options of modules that are also built
inside the sandbox, referencing an option of a module that isnt
built in the sandbox is also forbidden.
</para>
<para>
The default is <literal>true</literal> and should usually not be
changed; set it to <literal>false</literal> only if the module
requires access to <literal>pkgs</literal> in its documentation
(e.g. because it loads information from a linked package to
build an option type) or if its documentation depends on other
modules that also arent sandboxed (e.g. by using types defined
in the other module).
</para>
</listitem>
</itemizedlist>
</section>

View File

@ -1,14 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="sec-nixos-tests">
<title>NixOS Tests</title>
<para>
When you add some feature to NixOS, you should write a test for it.
NixOS tests are kept in the directory
<literal>nixos/tests</literal>, and are executed (using Nix) by a
testing framework that automatically starts one or more virtual
machines containing the NixOS system(s) required for the test.
</para>
<xi:include href="writing-nixos-tests.section.xml" />
<xi:include href="running-nixos-tests.section.xml" />
<xi:include href="running-nixos-tests-interactively.section.xml" />
<xi:include href="linking-nixos-tests-to-packages.section.xml" />
</chapter>

View File

@ -1,345 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-option-declarations">
<title>Option Declarations</title>
<para>
An option declaration specifies the name, type and description of a
NixOS configuration option. It is invalid to define an option that
hasnt been declared in any module. An option declaration generally
looks like this:
</para>
<programlisting language="nix">
options = {
name = mkOption {
type = type specification;
default = default value;
example = example value;
description = lib.mdDoc &quot;Description for use in the NixOS manual.&quot;;
};
};
</programlisting>
<para>
The attribute names within the <literal>name</literal> attribute
path must be camel cased in general but should, as an exception,
match the
<link xlink:href="https://nixos.org/nixpkgs/manual/#sec-package-naming">
package attribute name</link> when referencing a Nixpkgs package.
For example, the option
<literal>services.nix-serve.bindAddress</literal> references the
<literal>nix-serve</literal> Nixpkgs package.
</para>
<para>
The function <literal>mkOption</literal> accepts the following
arguments.
</para>
<variablelist>
<varlistentry>
<term>
<literal>type</literal>
</term>
<listitem>
<para>
The type of the option (see
<xref linkend="sec-option-types" />). This argument is
mandatory for nixpkgs modules. Setting this is highly
recommended for the sake of documentation and type checking.
In case it is not set, a fallback type with unspecified
behavior is used.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>default</literal>
</term>
<listitem>
<para>
The default value used if no value is defined by any module. A
default is not required; but if a default is not given, then
users of the module will have to define the value of the
option, otherwise an error will be thrown.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>defaultText</literal>
</term>
<listitem>
<para>
A textual representation of the default value to be rendered
verbatim in the manual. Useful if the default value is a
complex expression or depends on other values or packages. Use
<literal>lib.literalExpression</literal> for a Nix expression,
<literal>lib.literalMD</literal> for a plain English
description in
<link xlink:href="https://nixos.org/nixpkgs/manual/#sec-contributing-markup">Nixpkgs-flavored
Markdown</link> format.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>example</literal>
</term>
<listitem>
<para>
An example value that will be shown in the NixOS manual. You
can use <literal>lib.literalExpression</literal> and
<literal>lib.literalMD</literal> in the same way as in
<literal>defaultText</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>description</literal>
</term>
<listitem>
<para>
A textual description of the option, in
<link xlink:href="https://nixos.org/nixpkgs/manual/#sec-contributing-markup">Nixpkgs-flavored
Markdown</link> format, that will be included in the NixOS
manual. During the migration process from DocBook it is
necessary to mark descriptions written in CommonMark with
<literal>lib.mdDoc</literal>. The description may still be
written in DocBook (without any marker), but this is
discouraged and will be deprecated in the future.
</para>
</listitem>
</varlistentry>
</variablelist>
<section xml:id="sec-option-declarations-util">
<title>Utility functions for common option patterns</title>
<section xml:id="sec-option-declarations-util-mkEnableOption">
<title><literal>mkEnableOption</literal></title>
<para>
Creates an Option attribute set for a boolean value option i.e
an option to be toggled on or off.
</para>
<para>
This function takes a single string argument, the name of the
thing to be toggled.
</para>
<para>
The options description is <quote>Whether to enable
&lt;name&gt;.</quote>.
</para>
<para>
For example:
</para>
<anchor xml:id="ex-options-declarations-util-mkEnableOption-magic" />
<programlisting language="nix">
lib.mkEnableOption (lib.mdDoc &quot;magic&quot;)
# is like
lib.mkOption {
type = lib.types.bool;
default = false;
example = true;
description = lib.mdDoc &quot;Whether to enable magic.&quot;;
}
</programlisting>
<section xml:id="sec-option-declarations-util-mkPackageOption">
<title><literal>mkPackageOption</literal>,
<literal>mkPackageOptionMD</literal></title>
<para>
Usage:
</para>
<programlisting language="nix">
mkPackageOption pkgs &quot;name&quot; { default = [ &quot;path&quot; &quot;in&quot; &quot;pkgs&quot; ]; example = &quot;literal example&quot;; }
</programlisting>
<para>
Creates an Option attribute set for an option that specifies
the package a module should use for some purpose.
</para>
<para>
<emphasis role="strong">Note</emphasis>: You shouldnt
necessarily make package options for all of your modules. You
can always overwrite a specific package throughout nixpkgs by
using
<link xlink:href="https://nixos.org/manual/nixpkgs/stable/#chap-overlays">nixpkgs
overlays</link>.
</para>
<para>
The default package is specified as a list of strings
representing its attribute path in nixpkgs. Because of this,
you need to pass nixpkgs itself as the first argument.
</para>
<para>
The second argument is the name of the option, used in the
description <quote>The &lt;name&gt; package to use.</quote>.
You can also pass an example value, either a literal string or
a packages attribute path.
</para>
<para>
You can omit the default path if the name of the option is
also attribute path in nixpkgs.
</para>
<para>
During the transition to CommonMark documentation
<literal>mkPackageOption</literal> creates an option with a
DocBook description attribute, once the transition is
completed it will create a CommonMark description instead.
<literal>mkPackageOptionMD</literal> always creates an option
with a CommonMark description attribute and will be removed
some time after the transition is completed.
</para>
<anchor xml:id="ex-options-declarations-util-mkPackageOption" />
<para>
Examples:
</para>
<anchor xml:id="ex-options-declarations-util-mkPackageOption-hello" />
<programlisting language="nix">
lib.mkPackageOptionMD pkgs &quot;hello&quot; { }
# is like
lib.mkOption {
type = lib.types.package;
default = pkgs.hello;
defaultText = lib.literalExpression &quot;pkgs.hello&quot;;
description = lib.mdDoc &quot;The hello package to use.&quot;;
}
</programlisting>
<anchor xml:id="ex-options-declarations-util-mkPackageOption-ghc" />
<programlisting language="nix">
lib.mkPackageOptionMD pkgs &quot;GHC&quot; {
default = [ &quot;ghc&quot; ];
example = &quot;pkgs.haskell.packages.ghc92.ghc.withPackages (hkgs: [ hkgs.primes ])&quot;;
}
# is like
lib.mkOption {
type = lib.types.package;
default = pkgs.ghc;
defaultText = lib.literalExpression &quot;pkgs.ghc&quot;;
example = lib.literalExpression &quot;pkgs.haskell.packages.ghc92.ghc.withPackages (hkgs: [ hkgs.primes ])&quot;;
description = lib.mdDoc &quot;The GHC package to use.&quot;;
}
</programlisting>
<section xml:id="sec-option-declarations-eot">
<title>Extensible Option Types</title>
<para>
Extensible option types is a feature that allow to extend
certain types declaration through multiple module files.
This feature only work with a restricted set of types,
namely <literal>enum</literal> and
<literal>submodules</literal> and any composed forms of
them.
</para>
<para>
Extensible option types can be used for
<literal>enum</literal> options that affects multiple
modules, or as an alternative to related
<literal>enable</literal> options.
</para>
<para>
As an example, we will take the case of display managers.
There is a central display manager module for generic
display manager options and a module file per display
manager backend (sddm, gdm …).
</para>
<para>
There are two approaches we could take with this module
structure:
</para>
<itemizedlist>
<listitem>
<para>
Configuring the display managers independently by adding
an enable option to every display manager module
backend. (NixOS)
</para>
</listitem>
<listitem>
<para>
Configuring the display managers in the central module
by adding an option to select which display manager
backend to use.
</para>
</listitem>
</itemizedlist>
<para>
Both approaches have problems.
</para>
<para>
Making backends independent can quickly become hard to
manage. For display managers, there can only be one enabled
at a time, but the type system cannot enforce this
restriction as there is no relation between each backends
<literal>enable</literal> option. As a result, this
restriction has to be done explicitly by adding assertions
in each display manager backend module.
</para>
<para>
On the other hand, managing the display manager backends in
the central module will require changing the central module
option every time a new backend is added or removed.
</para>
<para>
By using extensible option types, it is possible to create a
placeholder option in the central module
(<link linkend="ex-option-declaration-eot-service">Example:
Extensible type placeholder in the service module</link>),
and to extend it in each backend module
(<link linkend="ex-option-declaration-eot-backend-gdm">Example:
Extending
<literal>services.xserver.displayManager.enable</literal> in
the <literal>gdm</literal> module</link>,
<link linkend="ex-option-declaration-eot-backend-sddm">Example:
Extending
<literal>services.xserver.displayManager.enable</literal> in
the <literal>sddm</literal> module</link>).
</para>
<para>
As a result, <literal>displayManager.enable</literal> option
values can be added without changing the main service module
file and the type system automatically enforces that there
can only be a single display manager enabled.
</para>
<anchor xml:id="ex-option-declaration-eot-service" />
<para>
<emphasis role="strong">Example: Extensible type placeholder
in the service module</emphasis>
</para>
<programlisting language="nix">
services.xserver.displayManager.enable = mkOption {
description = &quot;Display manager to use&quot;;
type = with types; nullOr (enum [ ]);
};
</programlisting>
<anchor xml:id="ex-option-declaration-eot-backend-gdm" />
<para>
<emphasis role="strong">Example: Extending
<literal>services.xserver.displayManager.enable</literal> in
the <literal>gdm</literal> module</emphasis>
</para>
<programlisting language="nix">
services.xserver.displayManager.enable = mkOption {
type = with types; nullOr (enum [ &quot;gdm&quot; ]);
};
</programlisting>
<anchor xml:id="ex-option-declaration-eot-backend-sddm" />
<para>
<emphasis role="strong">Example: Extending
<literal>services.xserver.displayManager.enable</literal> in
the <literal>sddm</literal> module</emphasis>
</para>
<programlisting language="nix">
services.xserver.displayManager.enable = mkOption {
type = with types; nullOr (enum [ &quot;sddm&quot; ]);
};
</programlisting>
<para>
The placeholder declaration is a standard
<literal>mkOption</literal> declaration, but it is important
that extensible option declarations only use the
<literal>type</literal> argument.
</para>
<para>
Extensible option types work with any of the composed
variants of <literal>enum</literal> such as
<literal>with types; nullOr (enum [ &quot;foo&quot; &quot;bar&quot; ])</literal>
or
<literal>with types; listOf (enum [ &quot;foo&quot; &quot;bar&quot; ])</literal>.
</para>
</section>
</section>
</section>
</section>
</section>

View File

@ -1,132 +0,0 @@
<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="nix">
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="nix">
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="nix">
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="nix">
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="nix">
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 an <emphasis>override priority</emphasis>. All
option definitions that do not have the lowest priority value are
discarded. By default, option definitions have priority 100 and
option defaults have priority 1500. You can specify an explicit
priority by using <literal>mkOverride</literal>, e.g.
</para>
<programlisting language="nix">
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>, and
<literal>mkDefault</literal> is equal to
<literal>mkOverride 1000</literal>.
</para>
</section>
<section xml:id="sec-option-definitions-ordering">
<title>Ordering Definitions</title>
<para>
It is also possible to influence the order in which the
definitions for an option are merged by setting an <emphasis>order
priority</emphasis> with <literal>mkOrder</literal>. The default
order priority is 1000. The functions <literal>mkBefore</literal>
and <literal>mkAfter</literal> are equal to
<literal>mkOrder 500</literal> and
<literal>mkOrder 1500</literal>, respectively. As an example,
</para>
<programlisting language="nix">
hardware.firmware = mkBefore [ myFirmware ];
</programlisting>
<para>
This definition ensures that <literal>myFirmware</literal> comes
before other unordered definitions in the final list value of
<literal>hardware.firmware</literal>.
</para>
<para>
Note that this is different from
<link linkend="sec-option-definitions-setting-priorities">override
priorities</link>: setting an order does not affect whether the
definition is included or not.
</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="nix">
config = mkMerge
[ # Unconditional stuff.
{ environment.systemPackages = [ ... ];
}
# Conditional stuff.
(mkIf config.services.bla.enable {
environment.systemPackages = [ ... ];
})
];
</programlisting>
</section>
</section>

File diff suppressed because it is too large Load Diff

View File

@ -1,70 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-replace-modules">
<title>Replace Modules</title>
<para>
Modules that are imported can also be disabled. The option
declarations, config implementation and the imports of a disabled
module will be ignored, allowing another to take its place. This can
be used to import a set of modules from another channel while
keeping the rest of the system on a stable release.
</para>
<para>
<literal>disabledModules</literal> is a top level attribute like
<literal>imports</literal>, <literal>options</literal> and
<literal>config</literal>. It contains a list of modules that will
be disabled. This can either be the full path to the module or a
string with the filename relative to the modules path (eg.
&lt;nixpkgs/nixos/modules&gt; for nixos).
</para>
<para>
This example will replace the existing postgresql module with the
version defined in the nixos-unstable channel while keeping the rest
of the modules and packages from the original nixos channel. This
only overrides the module definition, this wont use postgresql from
nixos-unstable unless explicitly configured to do so.
</para>
<programlisting language="nix">
{ config, lib, pkgs, ... }:
{
disabledModules = [ &quot;services/databases/postgresql.nix&quot; ];
imports =
[ # Use postgresql service from nixos-unstable channel.
# sudo nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable
&lt;nixos-unstable/nixos/modules/services/databases/postgresql.nix&gt;
];
services.postgresql.enable = true;
}
</programlisting>
<para>
This example shows how to define a custom module as a replacement
for an existing module. Importing this module will disable the
original module without having to know its implementation details.
</para>
<programlisting language="nix">
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.man;
in
{
disabledModules = [ &quot;services/programs/man.nix&quot; ];
options = {
programs.man.enable = mkOption {
type = types.bool;
default = true;
description = &quot;Whether to enable manual pages.&quot;;
};
};
config = mkIf cfg.enabled {
warnings = [ &quot;disabled manpages for production deployments.&quot; ];
};
}
</programlisting>
</section>

View File

@ -1,104 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-running-nixos-tests-interactively">
<title>Running Tests interactively</title>
<para>
The test itself can be run interactively. This is particularly
useful when developing or debugging a test:
</para>
<programlisting>
$ nix-build . -A nixosTests.login.driverInteractive
$ ./result/bin/nixos-test-driver
[...]
&gt;&gt;&gt;
</programlisting>
<para>
You can then take any Python statement, e.g.
</para>
<programlisting language="python">
&gt;&gt;&gt; start_all()
&gt;&gt;&gt; test_script()
&gt;&gt;&gt; machine.succeed(&quot;touch /tmp/foo&quot;)
&gt;&gt;&gt; print(machine.succeed(&quot;pwd&quot;)) # Show stdout of command
</programlisting>
<para>
The function <literal>test_script</literal> executes the entire test
script and drops you back into the test driver command line upon its
completion. This allows you to inspect the state of the VMs after
the test (e.g. to debug the test script).
</para>
<section xml:id="sec-nixos-test-shell-access">
<title>Shell access in interactive mode</title>
<para>
The function
<literal>&lt;yourmachine&gt;.shell_interact()</literal> grants
access to a shell running inside a virtual machine. To use it,
replace <literal>&lt;yourmachine&gt;</literal> with the name of a
virtual machine defined in the test, for example:
<literal>machine.shell_interact()</literal>. Keep in mind that
this shell may not display everything correctly as it is running
within an interactive Python REPL, and logging output from the
virtual machine may overwrite input and output from the guest
shell:
</para>
<programlisting language="python">
&gt;&gt;&gt; machine.shell_interact()
machine: Terminal is ready (there is no initial prompt):
$ hostname
machine
</programlisting>
<para>
As an alternative, you can proxy the guest shell to a local TCP
server by first starting a TCP server in a terminal using the
command:
</para>
<programlisting>
$ socat 'READLINE,PROMPT=$ ' tcp-listen:4444,reuseaddr`
</programlisting>
<para>
In the terminal where the test driver is running, connect to this
server by using:
</para>
<programlisting language="python">
&gt;&gt;&gt; machine.shell_interact(&quot;tcp:127.0.0.1:4444&quot;)
</programlisting>
<para>
Once the connection is established, you can enter commands in the
socat terminal where socat is running.
</para>
</section>
<section xml:id="sec-nixos-test-reuse-vm-state">
<title>Reuse VM state</title>
<para>
You can re-use the VM states coming from a previous run by setting
the <literal>--keep-vm-state</literal> flag.
</para>
<programlisting>
$ ./result/bin/nixos-test-driver --keep-vm-state
</programlisting>
<para>
The machine state is stored in the
<literal>$TMPDIR/vm-state-machinename</literal> directory.
</para>
</section>
<section xml:id="sec-nixos-test-interactive-configuration">
<title>Interactive-only test configuration</title>
<para>
The <literal>.driverInteractive</literal> attribute combines the
regular test configuration with definitions from the
<link linkend="test-opt-interactive"><literal>interactive</literal>
submodule</link>. This gives you a more usable, graphical, but
slightly different configuration.
</para>
<para>
You can add your own interactive-only test configuration by adding
extra configuration to the
<link linkend="test-opt-interactive"><literal>interactive</literal>
submodule</link>.
</para>
<para>
To interactively run only the regular configuration, build the
<literal>&lt;test&gt;.driver</literal> attribute instead, and call
it with the flag
<literal>result/bin/nixos-test-driver --interactive</literal>.
</para>
</section>
</section>

View File

@ -1,23 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-running-nixos-tests">
<title>Running Tests</title>
<para>
You can run tests using <literal>nix-build</literal>. For example,
to run the test
<link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/login.nix"><literal>login.nix</literal></link>,
you do:
</para>
<programlisting>
$ cd /my/git/clone/of/nixpkgs
$ nix-build -A nixosTests.login
</programlisting>
<para>
After building/downloading all required dependencies, this will
perform a build that starts a QEMU/KVM virtual machine containing a
NixOS system. The virtual machine mounts the Nix store of the host;
this makes VM creation very fast, as no disk image needs to be
created. Afterwards, you can view a log of the test:
</para>
<programlisting>
$ nix-store --read-log result
</programlisting>
</section>

View File

@ -1,420 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-settings-options">
<title>Options for Program Settings</title>
<para>
Many programs have configuration files where program-specific
settings can be declared. File formats can be separated into two
categories:
</para>
<itemizedlist>
<listitem>
<para>
Nix-representable ones: These can trivially be mapped to a
subset of Nix syntax. E.g. JSON is an example, since its values
like <literal>{&quot;foo&quot;:{&quot;bar&quot;:10}}</literal>
can be mapped directly to Nix:
<literal>{ foo = { bar = 10; }; }</literal>. Other examples are
INI, YAML and TOML. The following section explains the
convention for these settings.
</para>
</listitem>
<listitem>
<para>
Non-nix-representable ones: These cant be trivially mapped to a
subset of Nix syntax. Most generic programming languages are in
this group, e.g. bash, since the statement
<literal>if true; then echo hi; fi</literal> doesnt have a
trivial representation in Nix.
</para>
<para>
Currently there are no fixed conventions for these, but it is
common to have a <literal>configFile</literal> option for
setting the configuration file path directly. The default value
of <literal>configFile</literal> can be an auto-generated file,
with convenient options for controlling the contents. For
example an option of type <literal>attrsOf str</literal> can be
used for representing environment variables which generates a
section like <literal>export FOO=&quot;foo&quot;</literal>.
Often it can also be useful to also include an
<literal>extraConfig</literal> option of type
<literal>lines</literal> to allow arbitrary text after the
autogenerated part of the file.
</para>
</listitem>
</itemizedlist>
<section xml:id="sec-settings-nix-representable">
<title>Nix-representable Formats (JSON, YAML, TOML, INI, …)</title>
<para>
By convention, formats like this are handled with a generic
<literal>settings</literal> option, representing the full program
configuration as a Nix value. The type of this option should
represent the format. The most common formats have a predefined
type and string generator already declared under
<literal>pkgs.formats</literal>:
</para>
<variablelist>
<varlistentry>
<term>
<literal>pkgs.formats.javaProperties</literal> {
<emphasis><literal>comment</literal></emphasis> ?
<literal>&quot;Generated with Nix&quot;</literal> }
</term>
<listitem>
<para>
A function taking an attribute set with values
</para>
<variablelist>
<varlistentry>
<term>
<literal>comment</literal>
</term>
<listitem>
<para>
A string to put at the start of the file in a comment.
It can have multiple lines.
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
It returns the <literal>type</literal>:
<literal>attrsOf str</literal> and a function
<literal>generate</literal> to build a Java
<literal>.properties</literal> file, taking care of the
correct escaping, etc.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>pkgs.formats.json</literal> { }
</term>
<listitem>
<para>
A function taking an empty attribute set (for future
extensibility) and returning a set with JSON-specific
attributes <literal>type</literal> and
<literal>generate</literal> as specified
<link linkend="pkgs-formats-result">below</link>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>pkgs.formats.yaml</literal> { }
</term>
<listitem>
<para>
A function taking an empty attribute set (for future
extensibility) and returning a set with YAML-specific
attributes <literal>type</literal> and
<literal>generate</literal> as specified
<link linkend="pkgs-formats-result">below</link>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>pkgs.formats.ini</literal> {
<emphasis><literal>listsAsDuplicateKeys</literal></emphasis> ?
false, <emphasis><literal>listToValue</literal></emphasis> ?
null, ... }
</term>
<listitem>
<para>
A function taking an attribute set with values
</para>
<variablelist>
<varlistentry>
<term>
<literal>listsAsDuplicateKeys</literal>
</term>
<listitem>
<para>
A boolean for controlling whether list values can be
used to represent duplicate INI keys
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>listToValue</literal>
</term>
<listitem>
<para>
A function for turning a list of values into a single
value.
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
It returns a set with INI-specific attributes
<literal>type</literal> and <literal>generate</literal> as
specified <link linkend="pkgs-formats-result">below</link>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>pkgs.formats.toml</literal> { }
</term>
<listitem>
<para>
A function taking an empty attribute set (for future
extensibility) and returning a set with TOML-specific
attributes <literal>type</literal> and
<literal>generate</literal> as specified
<link linkend="pkgs-formats-result">below</link>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>pkgs.formats.elixirConf { elixir ? pkgs.elixir }</literal>
</term>
<listitem>
<para>
A function taking an attribute set with values
</para>
<variablelist>
<varlistentry>
<term>
<literal>elixir</literal>
</term>
<listitem>
<para>
The Elixir package which will be used to format the
generated output
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
It returns a set with Elixir-Config-specific attributes
<literal>type</literal>, <literal>lib</literal>, and
<literal>generate</literal> as specified
<link linkend="pkgs-formats-result">below</link>.
</para>
<para>
The <literal>lib</literal> attribute contains functions to
be used in settings, for generating special Elixir values:
</para>
<variablelist>
<varlistentry>
<term>
<literal>mkRaw elixirCode</literal>
</term>
<listitem>
<para>
Outputs the given string as raw Elixir code
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>mkGetEnv { envVariable, fallback ? null }</literal>
</term>
<listitem>
<para>
Makes the configuration fetch an environment variable
at runtime
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>mkAtom atom</literal>
</term>
<listitem>
<para>
Outputs the given string as an Elixir atom, instead of
the default Elixir binary string. Note: lowercase
atoms still needs to be prefixed with
<literal>:</literal>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>mkTuple array</literal>
</term>
<listitem>
<para>
Outputs the given array as an Elixir tuple, instead of
the default Elixir list
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>mkMap attrset</literal>
</term>
<listitem>
<para>
Outputs the given attribute set as an Elixir map,
instead of the default Elixir keyword list
</para>
</listitem>
</varlistentry>
</variablelist>
</listitem>
</varlistentry>
</variablelist>
<para xml:id="pkgs-formats-result">
These functions all return an attribute set with these values:
</para>
<variablelist>
<varlistentry>
<term>
<literal>type</literal>
</term>
<listitem>
<para>
A module system type representing a value of the format
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>lib</literal>
</term>
<listitem>
<para>
Utility functions for convenience, or special interactions
with the format. This attribute is optional. It may contain
inside a <literal>types</literal> attribute containing types
specific to this format.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>generate</literal>
<emphasis><literal>filename jsonValue</literal></emphasis>
</term>
<listitem>
<para>
A function that can render a value of the format to a file.
Returns a file path.
</para>
<note>
<para>
This function puts the value contents in the Nix store. So
this should be avoided for secrets.
</para>
</note>
</listitem>
</varlistentry>
</variablelist>
<anchor xml:id="ex-settings-nix-representable" />
<para>
<emphasis role="strong">Example: Module with conventional
<literal>settings</literal> option</emphasis>
</para>
<para>
The following shows a module for an example program that uses a
JSON configuration file. It demonstrates how above values can be
used, along with some other related best practices. See the
comments for explanations.
</para>
<programlisting language="nix">
{ options, config, lib, pkgs, ... }:
let
cfg = config.services.foo;
# Define the settings format used for this program
settingsFormat = pkgs.formats.json {};
in {
options.services.foo = {
enable = lib.mkEnableOption &quot;foo service&quot;;
settings = lib.mkOption {
# Setting this type allows for correct merging behavior
type = settingsFormat.type;
default = {};
description = ''
Configuration for foo, see
&lt;link xlink:href=&quot;https://example.com/docs/foo&quot;/&gt;
for supported settings.
'';
};
};
config = lib.mkIf cfg.enable {
# We can assign some default settings here to make the service work by just
# enabling it. We use `mkDefault` for values that can be changed without
# problems
services.foo.settings = {
# Fails at runtime without any value set
log_level = lib.mkDefault &quot;WARN&quot;;
# We assume systemd's `StateDirectory` is used, so we require this value,
# therefore no mkDefault
data_path = &quot;/var/lib/foo&quot;;
# Since we use this to create a user we need to know the default value at
# eval time
user = lib.mkDefault &quot;foo&quot;;
};
environment.etc.&quot;foo.json&quot;.source =
# The formats generator function takes a filename and the Nix value
# representing the format value and produces a filepath with that value
# rendered in the format
settingsFormat.generate &quot;foo-config.json&quot; cfg.settings;
# We know that the `user` attribute exists because we set a default value
# for it above, allowing us to use it without worries here
users.users.${cfg.settings.user} = { isSystemUser = true; };
# ...
};
}
</programlisting>
<section xml:id="sec-settings-attrs-options">
<title>Option declarations for attributes</title>
<para>
Some <literal>settings</literal> attributes may deserve some
extra care. They may need a different type, default or merging
behavior, or they are essential options that should show their
documentation in the manual. This can be done using
<xref linkend="sec-freeform-modules" />.
</para>
<para>
We extend above example using freeform modules to declare an
option for the port, which will enforce it to be a valid integer
and make it show up in the manual.
</para>
<anchor xml:id="ex-settings-typed-attrs" />
<para>
<emphasis role="strong">Example: Declaring a type-checked
<literal>settings</literal> attribute</emphasis>
</para>
<programlisting language="nix">
settings = lib.mkOption {
type = lib.types.submodule {
freeformType = settingsFormat.type;
# Declare an option for the port such that the type is checked and this option
# is shown in the manual.
options.port = lib.mkOption {
type = lib.types.port;
default = 8080;
description = ''
Which port this service should listen on.
'';
};
};
default = {};
description = ''
Configuration for Foo, see
&lt;link xlink:href=&quot;https://example.com/docs/foo&quot;/&gt;
for supported values.
'';
};
</programlisting>
</section>
</section>
</section>

View File

@ -1,90 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-getting-sources">
<title>Getting the Sources</title>
<para>
By default, NixOSs <literal>nixos-rebuild</literal> command uses
the NixOS and Nixpkgs sources provided by the
<literal>nixos</literal> channel (kept in
<literal>/nix/var/nix/profiles/per-user/root/channels/nixos</literal>).
To modify NixOS, however, you should check out the latest sources
from Git. This is as follows:
</para>
<programlisting>
$ git clone https://github.com/NixOS/nixpkgs
$ cd nixpkgs
$ git remote update origin
</programlisting>
<para>
This will check out the latest Nixpkgs sources to
<literal>./nixpkgs</literal> the NixOS sources to
<literal>./nixpkgs/nixos</literal>. (The NixOS source tree lives in
a subdirectory of the Nixpkgs repository.) The
<literal>nixpkgs</literal> repository has branches that correspond
to each Nixpkgs/NixOS channel (see <xref linkend="sec-upgrading" />
for more information about channels). Thus, the Git branch
<literal>origin/nixos-17.03</literal> will contain the latest built
and tested version available in the <literal>nixos-17.03</literal>
channel.
</para>
<para>
Its often inconvenient to develop directly on the master branch,
since if somebody has just committed (say) a change to GCC, then the
binary cache may not have caught up yet and youll have to rebuild
everything from source. So you may want to create a local branch
based on your current NixOS version:
</para>
<programlisting>
$ nixos-version
17.09pre104379.6e0b727 (Hummingbird)
$ git checkout -b local 6e0b727
</programlisting>
<para>
Or, to base your local branch on the latest version available in a
NixOS channel:
</para>
<programlisting>
$ git remote update origin
$ git checkout -b local origin/nixos-17.03
</programlisting>
<para>
(Replace <literal>nixos-17.03</literal> with the name of the channel
you want to use.) You can use <literal>git merge</literal> or
<literal>git rebase</literal> to keep your local branch in sync with
the channel, e.g.
</para>
<programlisting>
$ git remote update origin
$ git merge origin/nixos-17.03
</programlisting>
<para>
You can use <literal>git cherry-pick</literal> to copy commits from
your local branch to the upstream branch.
</para>
<para>
If you want to rebuild your system using your (modified) sources,
you need to tell <literal>nixos-rebuild</literal> about them using
the <literal>-I</literal> flag:
</para>
<programlisting>
# nixos-rebuild switch -I nixpkgs=/my/sources/nixpkgs
</programlisting>
<para>
If you want <literal>nix-env</literal> to use the expressions in
<literal>/my/sources</literal>, use
<literal>nix-env -f /my/sources/nixpkgs</literal>, or change the
default by adding a symlink in <literal>~/.nix-defexpr</literal>:
</para>
<programlisting>
$ ln -s /my/sources/nixpkgs ~/.nix-defexpr/nixpkgs
</programlisting>
<para>
You may want to delete the symlink
<literal>~/.nix-defexpr/channels_root</literal> to prevent roots
NixOS channel from clashing with your own tree (this may break the
command-not-found utility though). If you want to go back to the
default state, you may just remove the
<literal>~/.nix-defexpr</literal> directory completely, log out and
log in again and it should have been recreated with a link to the
root channels.
</para>
</chapter>

View File

@ -1,22 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="ch-testing-installer">
<title>Testing the Installer</title>
<para>
Building, burning, and booting from an installation CD is rather
tedious, so here is a quick way to see if the installer works
properly:
</para>
<programlisting>
# mount -t tmpfs none /mnt
# nixos-generate-config --root /mnt
$ nix-build '&lt;nixpkgs/nixos&gt;' -A config.system.build.nixos-install
# ./result/bin/nixos-install
</programlisting>
<para>
To start a login shell in the new NixOS installation in
<literal>/mnt</literal>:
</para>
<programlisting>
$ nix-build '&lt;nixpkgs/nixos&gt;' -A config.system.build.nixos-enter
# ./result/bin/nixos-enter
</programlisting>
</chapter>

View File

@ -1,131 +0,0 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-unit-handling">
<title>Unit handling</title>
<para>
To figure out what units need to be
started/stopped/restarted/reloaded, the script first checks the
current state of the system, similar to what
<literal>systemctl list-units</literal> shows. For each of the
units, the script goes through the following checks:
</para>
<itemizedlist>
<listitem>
<para>
Is the unit file still in the new system? If not,
<emphasis role="strong">stop</emphasis> the service unless it
sets <literal>X-StopOnRemoval</literal> in the
<literal>[Unit]</literal> section to <literal>false</literal>.
</para>
</listitem>
<listitem>
<para>
Is it a <literal>.target</literal> unit? If so,
<emphasis role="strong">start</emphasis> it unless it sets
<literal>RefuseManualStart</literal> in the
<literal>[Unit]</literal> section to <literal>true</literal> or
<literal>X-OnlyManualStart</literal> in the
<literal>[Unit]</literal> section to <literal>true</literal>.
Also <emphasis role="strong">stop</emphasis> the unit again
unless it sets <literal>X-StopOnReconfiguration</literal> to
<literal>false</literal>.
</para>
</listitem>
<listitem>
<para>
Are the contents of the unit files different? They are compared
by parsing them and comparing their contents. If they are
different but only <literal>X-Reload-Triggers</literal> in the
<literal>[Unit]</literal> section is changed,
<emphasis role="strong">reload</emphasis> the unit. The NixOS
module system allows setting these triggers with the option
<link linkend="opt-systemd.services">systemd.services.&lt;name&gt;.reloadTriggers</link>.
There are some additional keys in the <literal>[Unit]</literal>
section that are ignored as well. If the unit files differ in
any way, the following actions are performed:
</para>
<itemizedlist>
<listitem>
<para>
<literal>.path</literal> and <literal>.slice</literal> units
are ignored. There is no need to restart them since changes
in their values are applied by systemd when systemd is
reloaded.
</para>
</listitem>
<listitem>
<para>
<literal>.mount</literal> units are
<emphasis role="strong">reload</emphasis>ed. These mostly
come from the <literal>/etc/fstab</literal> parser.
</para>
</listitem>
<listitem>
<para>
<literal>.socket</literal> units are currently ignored. This
is to be fixed at a later point.
</para>
</listitem>
<listitem>
<para>
The rest of the units (mostly <literal>.service</literal>
units) are then <emphasis role="strong">reload</emphasis>ed
if <literal>X-ReloadIfChanged</literal> in the
<literal>[Service]</literal> section is set to
<literal>true</literal> (exposed via
<link linkend="opt-systemd.services">systemd.services.&lt;name&gt;.reloadIfChanged</link>).
A little exception is done for units that were deactivated
in the meantime, for example because they require a unit
that got stopped before. These are
<emphasis role="strong">start</emphasis>ed instead of
reloaded.
</para>
</listitem>
<listitem>
<para>
If the reload flag is not set, some more flags decide if the
unit is skipped. These flags are
<literal>X-RestartIfChanged</literal> in the
<literal>[Service]</literal> section (exposed via
<link linkend="opt-systemd.services">systemd.services.&lt;name&gt;.restartIfChanged</link>),
<literal>RefuseManualStop</literal> in the
<literal>[Unit]</literal> section, and
<literal>X-OnlyManualStart</literal> in the
<literal>[Unit]</literal> section.
</para>
</listitem>
<listitem>
<para>
Further behavior depends on the unit having
<literal>X-StopIfChanged</literal> in the
<literal>[Service]</literal> section set to
<literal>true</literal> (exposed via
<link linkend="opt-systemd.services">systemd.services.&lt;name&gt;.stopIfChanged</link>).
This is set to <literal>true</literal> by default and must
be explicitly turned off if not wanted. If the flag is
enabled, the unit is
<emphasis role="strong">stop</emphasis>ped and then
<emphasis role="strong">start</emphasis>ed. If not, the unit
is <emphasis role="strong">restart</emphasis>ed. The goal of
the flag is to make sure that the new unit never runs in the
old environment which is still in place before the
activation script is run. This behavior is different when
the service is socket-activated, as outlined in the
following steps.
</para>
</listitem>
<listitem>
<para>
The last thing that is taken into account is whether the
unit is a service and socket-activated. If
<literal>X-StopIfChanged</literal> is
<emphasis role="strong">not</emphasis> set, the service is
<emphasis role="strong">restart</emphasis>ed with the
others. If it is set, both the service and the socket are
<emphasis role="strong">stop</emphasis>ped and the socket is
<emphasis role="strong">start</emphasis>ed, leaving socket
activation to start the service when its needed.
</para>
</listitem>
</itemizedlist>
</listitem>
</itemizedlist>
</section>

View File

@ -1,122 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="sec-switching-systems">
<title>What happens during a system switch?</title>
<para>
Running <literal>nixos-rebuild switch</literal> is one of the more
common tasks under NixOS. This chapter explains some of the
internals of this command to make it simpler for new module
developers to configure their units correctly and to make it easier
to understand what is happening and why for curious administrators.
</para>
<para>
<literal>nixos-rebuild</literal>, like many deployment solutions,
calls <literal>switch-to-configuration</literal> which resides in a
NixOS system at <literal>$out/bin/switch-to-configuration</literal>.
The script is called with the action that is to be performed like
<literal>switch</literal>, <literal>test</literal>,
<literal>boot</literal>. There is also the
<literal>dry-activate</literal> action which does not really perform
the actions but rather prints what it would do if you called it with
<literal>test</literal>. This feature can be used to check what
service states would be changed if the configuration was switched
to.
</para>
<para>
If the action is <literal>switch</literal> or
<literal>boot</literal>, the bootloader is updated first so the
configuration will be the next one to boot. Unless
<literal>NIXOS_NO_SYNC</literal> is set to <literal>1</literal>,
<literal>/nix/store</literal> is synced to disk.
</para>
<para>
If the action is <literal>switch</literal> or
<literal>test</literal>, the currently running system is inspected
and the actions to switch to the new system are calculated. This
process takes two data sources into account:
<literal>/etc/fstab</literal> and the current systemd status. Mounts
and swaps are read from <literal>/etc/fstab</literal> and the
corresponding actions are generated. If a new mount is added, for
example, the proper <literal>.mount</literal> unit is marked to be
started. The current systemd state is inspected, the difference
between the current system and the desired configuration is
calculated and actions are generated to get to this state. There are
a lot of nuances that can be controlled by the units which are
explained here.
</para>
<para>
After calculating what should be done, the actions are carried out.
The order of actions is always the same:
</para>
<itemizedlist spacing="compact">
<listitem>
<para>
Stop units (<literal>systemctl stop</literal>)
</para>
</listitem>
<listitem>
<para>
Run activation script (<literal>$out/activate</literal>)
</para>
</listitem>
<listitem>
<para>
See if the activation script requested more units to restart
</para>
</listitem>
<listitem>
<para>
Restart systemd if needed
(<literal>systemd daemon-reexec</literal>)
</para>
</listitem>
<listitem>
<para>
Forget about the failed state of units
(<literal>systemctl reset-failed</literal>)
</para>
</listitem>
<listitem>
<para>
Reload systemd (<literal>systemctl daemon-reload</literal>)
</para>
</listitem>
<listitem>
<para>
Reload systemd user instances
(<literal>systemctl --user daemon-reload</literal>)
</para>
</listitem>
<listitem>
<para>
Set up tmpfiles (<literal>systemd-tmpfiles --create</literal>)
</para>
</listitem>
<listitem>
<para>
Reload units (<literal>systemctl reload</literal>)
</para>
</listitem>
<listitem>
<para>
Restart units (<literal>systemctl restart</literal>)
</para>
</listitem>
<listitem>
<para>
Start units (<literal>systemctl start</literal>)
</para>
</listitem>
<listitem>
<para>
Inspect what changed during these actions and print units that
failed and that were newly started
</para>
</listitem>
</itemizedlist>
<para>
Most of these actions are either self-explaining but some of them
have to do with our units or the activation script. For this reason,
these topics are explained in the next sections.
</para>
<xi:include href="unit-handling.section.xml" />
<xi:include href="activation-script.section.xml" />
</chapter>

View File

@ -1,144 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="sec-writing-documentation">
<title>Writing NixOS Documentation</title>
<para>
As NixOS grows, so too does the need for a catalogue and explanation
of its extensive functionality. Collecting pertinent information
from disparate sources and presenting it in an accessible style
would be a worthy contribution to the project.
</para>
<section xml:id="sec-writing-docs-building-the-manual">
<title>Building the Manual</title>
<para>
The DocBook sources of the <xref linkend="book-nixos-manual" />
are in the
<link xlink:href="https://github.com/NixOS/nixpkgs/tree/master/nixos/doc/manual"><literal>nixos/doc/manual</literal></link>
subdirectory of the Nixpkgs repository.
</para>
<para>
You can quickly validate your edits with <literal>make</literal>:
</para>
<programlisting>
$ cd /path/to/nixpkgs/nixos/doc/manual
$ nix-shell
nix-shell$ make
</programlisting>
<para>
Once you are done making modifications to the manual, its
important to build it before committing. You can do that as
follows:
</para>
<programlisting>
nix-build nixos/release.nix -A manual.x86_64-linux
</programlisting>
<para>
When this command successfully finishes, it will tell you where
the manual got generated. The HTML will be accessible through the
<literal>result</literal> symlink at
<literal>./result/share/doc/nixos/index.html</literal>.
</para>
</section>
<section xml:id="sec-writing-docs-editing-docbook-xml">
<title>Editing DocBook XML</title>
<para>
For general information on how to write in DocBook, see
<link xlink:href="http://www.docbook.org/tdg5/en/html/docbook.html">DocBook
5: The Definitive Guide</link>.
</para>
<para>
Emacs nXML Mode is very helpful for editing DocBook XML because it
validates the document as you write, and precisely locates errors.
To use it, see <xref linkend="sec-emacs-docbook-xml" />.
</para>
<para>
<link xlink:href="http://pandoc.org">Pandoc</link> can generate
DocBook XML from a multitude of formats, which makes a good
starting point. Here is an example of Pandoc invocation to convert
GitHub-Flavoured MarkDown to DocBook 5 XML:
</para>
<programlisting>
pandoc -f markdown_github -t docbook5 docs.md -o my-section.md
</programlisting>
<para>
Pandoc can also quickly convert a single
<literal>section.xml</literal> to HTML, which is helpful when
drafting.
</para>
<para>
Sometimes writing valid DocBook is simply too difficult. In this
case, submit your documentation updates in a
<link xlink:href="https://github.com/NixOS/nixpkgs/issues/new">GitHub
Issue</link> and someone will handle the conversion to XML for
you.
</para>
</section>
<section xml:id="sec-writing-docs-creating-a-topic">
<title>Creating a Topic</title>
<para>
You can use an existing topic as a basis for the new topic or
create a topic from scratch.
</para>
<para>
Keep the following guidelines in mind when you create and add a
topic:
</para>
<itemizedlist>
<listitem>
<para>
The NixOS
<link xlink:href="http://www.docbook.org/tdg5/en/html/book.html"><literal>book</literal></link>
element is in <literal>nixos/doc/manual/manual.xml</literal>.
It includes several
<link xlink:href="http://www.docbook.org/tdg5/en/html/book.html"><literal>parts</literal></link>
which are in subdirectories.
</para>
</listitem>
<listitem>
<para>
Store the topic file in the same directory as the
<literal>part</literal> to which it belongs. If your topic is
about configuring a NixOS module, then the XML file can be
stored alongside the module definition <literal>nix</literal>
file.
</para>
</listitem>
<listitem>
<para>
If you include multiple words in the file name, separate the
words with a dash. For example:
<literal>ipv6-config.xml</literal>.
</para>
</listitem>
<listitem>
<para>
Make sure that the <literal>xml:id</literal> value is unique.
You can use abbreviations if the ID is too long. For example:
<literal>nixos-config</literal>.
</para>
</listitem>
<listitem>
<para>
Determine whether your topic is a chapter or a section. If you
are unsure, open an existing topic file and check whether the
main element is chapter or section.
</para>
</listitem>
</itemizedlist>
</section>
<section xml:id="sec-writing-docs-adding-a-topic">
<title>Adding a Topic to the Book</title>
<para>
Open the parent XML file and add an <literal>xi:include</literal>
element to the list of chapters with the file name of the topic
that you created. If you created a <literal>section</literal>, you
add the file to the <literal>chapter</literal> file. If you
created a <literal>chapter</literal>, you add the file to the
<literal>part</literal> file.
</para>
<para>
If the topic is about configuring a NixOS module, it can be
automatically included in the manual by using the
<literal>meta.doc</literal> attribute. See
<xref linkend="sec-meta-attributes" /> for an explanation.
</para>
</section>
</chapter>

View File

@ -1,245 +0,0 @@
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="sec-writing-modules">
<title>Writing NixOS Modules</title>
<para>
NixOS has a modular system for declarative configuration. This
system combines multiple <emphasis>modules</emphasis> to produce the
full system configuration. One of the modules that constitute the
configuration is <literal>/etc/nixos/configuration.nix</literal>.
Most of the others live in the
<link xlink:href="https://github.com/NixOS/nixpkgs/tree/master/nixos/modules"><literal>nixos/modules</literal></link>
subdirectory of the Nixpkgs tree.
</para>
<para>
Each NixOS module is a file that handles one logical aspect of the
configuration, such as a specific kind of hardware, a service, or
network settings. A module configuration does not have to handle
everything from scratch; it can use the functionality provided by
other modules for its implementation. Thus a module can
<emphasis>declare</emphasis> options that can be used by other
modules, and conversely can <emphasis>define</emphasis> options
provided by other modules in its own implementation. For example,
the module
<link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/security/pam.nix"><literal>pam.nix</literal></link>
declares the option <literal>security.pam.services</literal> that
allows other modules (e.g.
<link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/networking/ssh/sshd.nix"><literal>sshd.nix</literal></link>)
to define PAM services; and it defines the option
<literal>environment.etc</literal> (declared by
<link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/system/etc/etc.nix"><literal>etc.nix</literal></link>)
to cause files to be created in <literal>/etc/pam.d</literal>.
</para>
<para>
In <xref linkend="sec-configuration-syntax" />, we saw the following
structure of NixOS modules:
</para>
<programlisting language="nix">
{ config, pkgs, ... }:
{ option definitions
}
</programlisting>
<para>
This is actually an <emphasis>abbreviated</emphasis> form of module
that only defines options, but does not declare any. The structure
of full NixOS modules is shown in
<link linkend="ex-module-syntax">Example: Structure of NixOS
Modules</link>.
</para>
<anchor xml:id="ex-module-syntax" />
<para>
<emphasis role="strong">Example: Structure of NixOS
Modules</emphasis>
</para>
<programlisting language="nix">
{ config, pkgs, ... }:
{
imports =
[ paths of other modules
];
options = {
option declarations
};
config = {
option definitions
};
}
</programlisting>
<para>
The meaning of each part is as follows.
</para>
<itemizedlist>
<listitem>
<para>
The first line makes the current Nix expression a function. The
variable <literal>pkgs</literal> contains Nixpkgs (by default,
it takes the <literal>nixpkgs</literal> entry of
<literal>NIX_PATH</literal>, see the
<link xlink:href="https://nixos.org/manual/nix/stable/#sec-common-env">Nix
manual</link> for further details), while
<literal>config</literal> contains the full system
configuration. This line can be omitted if there is no reference
to <literal>pkgs</literal> and <literal>config</literal> inside
the module.
</para>
</listitem>
<listitem>
<para>
This <literal>imports</literal> list enumerates the paths to
other NixOS modules that should be included in the evaluation of
the system configuration. A default set of modules is defined in
the file <literal>modules/module-list.nix</literal>. These dont
need to be added in the import list.
</para>
</listitem>
<listitem>
<para>
The attribute <literal>options</literal> is a nested set of
<emphasis>option declarations</emphasis> (described below).
</para>
</listitem>
<listitem>
<para>
The attribute <literal>config</literal> is a nested set of
<emphasis>option definitions</emphasis> (also described below).
</para>
</listitem>
</itemizedlist>
<para>
<link linkend="locate-example">Example: NixOS Module for the
<quote>locate</quote> Service</link> shows a module that handles the
regular update of the <quote>locate</quote> database, an index of
all files in the file system. This module declares two options that
can be defined by other modules (typically the users
<literal>configuration.nix</literal>):
<literal>services.locate.enable</literal> (whether the database
should be updated) and <literal>services.locate.interval</literal>
(when the update should be done). It implements its functionality by
defining two options declared by other modules:
<literal>systemd.services</literal> (the set of all systemd
services) and <literal>systemd.timers</literal> (the list of
commands to be executed periodically by <literal>systemd</literal>).
</para>
<para>
Care must be taken when writing systemd services using
<literal>Exec*</literal> directives. By default systemd performs
substitution on <literal>%&lt;char&gt;</literal> specifiers in these
directives, expands environment variables from
<literal>$FOO</literal> and <literal>${FOO}</literal>, splits
arguments on whitespace, and splits commands on
<literal>;</literal>. All of these must be escaped to avoid
unexpected substitution or splitting when interpolating into an
<literal>Exec*</literal> directive, e.g. when using an
<literal>extraArgs</literal> option to pass additional arguments to
the service. The functions
<literal>utils.escapeSystemdExecArg</literal> and
<literal>utils.escapeSystemdExecArgs</literal> are provided for
this, see <link linkend="exec-escaping-example">Example: Escaping in
Exec directives</link> for an example. When using these functions
system environment substitution should <emphasis>not</emphasis> be
disabled explicitly.
</para>
<anchor xml:id="locate-example" />
<para>
<emphasis role="strong">Example: NixOS Module for the
<quote>locate</quote> Service</emphasis>
</para>
<programlisting language="nix">
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.locate;
in {
options.services.locate = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
If enabled, NixOS will periodically update the database of
files used by the locate command.
'';
};
interval = mkOption {
type = types.str;
default = &quot;02:15&quot;;
example = &quot;hourly&quot;;
description = ''
Update the locate database at this interval. Updates by
default at 2:15 AM every day.
The format is described in
systemd.time(7).
'';
};
# Other options omitted for documentation
};
config = {
systemd.services.update-locatedb =
{ description = &quot;Update Locate Database&quot;;
path = [ pkgs.su ];
script =
''
mkdir -m 0755 -p $(dirname ${toString cfg.output})
exec updatedb \
--localuser=${cfg.localuser} \
${optionalString (!cfg.includeStore) &quot;--prunepaths='/nix/store'&quot;} \
--output=${toString cfg.output} ${concatStringsSep &quot; &quot; cfg.extraFlags}
'';
};
systemd.timers.update-locatedb = mkIf cfg.enable
{ description = &quot;Update timer for locate database&quot;;
partOf = [ &quot;update-locatedb.service&quot; ];
wantedBy = [ &quot;timers.target&quot; ];
timerConfig.OnCalendar = cfg.interval;
};
};
}
</programlisting>
<anchor xml:id="exec-escaping-example" />
<para>
<emphasis role="strong">Example: Escaping in Exec
directives</emphasis>
</para>
<programlisting language="nix">
{ config, lib, pkgs, utils, ... }:
with lib;
let
cfg = config.services.echo;
echoAll = pkgs.writeScript &quot;echo-all&quot; ''
#! ${pkgs.runtimeShell}
for s in &quot;$@&quot;; do
printf '%s\n' &quot;$s&quot;
done
'';
args = [ &quot;a%Nything&quot; &quot;lang=\${LANG}&quot; &quot;;&quot; &quot;/bin/sh -c date&quot; ];
in {
systemd.services.echo =
{ description = &quot;Echo to the journal&quot;;
wantedBy = [ &quot;multi-user.target&quot; ];
serviceConfig.Type = &quot;oneshot&quot;;
serviceConfig.ExecStart = ''
${echoAll} ${utils.escapeSystemdExecArgs args}
'';
};
}
</programlisting>
<xi:include href="option-declarations.section.xml" />
<xi:include href="option-types.section.xml" />
<xi:include href="option-def.section.xml" />
<xi:include href="assertions.section.xml" />
<xi:include href="meta-attributes.section.xml" />
<xi:include href="importing-modules.section.xml" />
<xi:include href="replace-modules.section.xml" />
<xi:include href="freeform-modules.section.xml" />
<xi:include href="settings-options.section.xml" />
</chapter>

Some files were not shown because too many files have changed in this diff Show More