Project import generated by Copybara.

GitOrigin-RevId: ac1f5b72a9e95873d1de0233fddcb56f99884b37
This commit is contained in:
Default email 2023-02-16 18:41:37 +01:00
parent a811f0616a
commit 686ce24904
1603 changed files with 23055 additions and 51483 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 - [ ] (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 updates) Added a release notes entry if the change is significant
- [ ] (Module addition) Added a release notes entry if adding a new NixOS module - [ ] (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). - [ ] Fits [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md).
<!-- <!--

View file

@ -19,7 +19,7 @@ jobs:
# we don't limit this action to only NixOS repo since the checks are cheap and useful developer feedback # we don't limit this action to only NixOS repo since the checks are cheap and useful developer feedback
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: cachix/install-nix-action@v18 - uses: cachix/install-nix-action@v19
- uses: cachix/cachix-action@v12 - uses: cachix/cachix-action@v12
with: with:
# This cache is for the nixpkgs repo checks and should not be trusted or used elsewhere. # This cache is for the nixpkgs repo checks and should not be trusted or used elsewhere.

View file

@ -28,7 +28,7 @@ jobs:
with: with:
# pull_request_target checks out the base branch by default # pull_request_target checks out the base branch by default
ref: refs/pull/${{ github.event.pull_request.number }}/merge ref: refs/pull/${{ github.event.pull_request.number }}/merge
- uses: cachix/install-nix-action@v18 - uses: cachix/install-nix-action@v19
with: with:
# nixpkgs commit is pinned so that it doesn't break # nixpkgs commit is pinned so that it doesn't break
# editorconfig-checker 2.4.0 # editorconfig-checker 2.4.0

View file

@ -18,7 +18,7 @@ jobs:
with: with:
# pull_request_target checks out the base branch by default # pull_request_target checks out the base branch by default
ref: refs/pull/${{ github.event.pull_request.number }}/merge ref: refs/pull/${{ github.event.pull_request.number }}/merge
- uses: cachix/install-nix-action@v18 - uses: cachix/install-nix-action@v19
with: with:
# explicitly enable sandbox # explicitly enable sandbox
extra_nix_config: sandbox = true extra_nix_config: sandbox = true

View file

@ -18,7 +18,7 @@ jobs:
with: with:
# pull_request_target checks out the base branch by default # pull_request_target checks out the base branch by default
ref: refs/pull/${{ github.event.pull_request.number }}/merge ref: refs/pull/${{ github.event.pull_request.number }}/merge
- uses: cachix/install-nix-action@v18 - uses: cachix/install-nix-action@v19
with: with:
# explicitly enable sandbox # explicitly enable sandbox
extra_nix_config: sandbox = true extra_nix_config: sandbox = true

View file

@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: cachix/install-nix-action@v18 - uses: cachix/install-nix-action@v19
with: with:
# explicitly enable sandbox # explicitly enable sandbox
extra_nix_config: sandbox = true extra_nix_config: sandbox = true

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

@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: cachix/install-nix-action@v18 - uses: cachix/install-nix-action@v19
with: with:
nix_path: nixpkgs=channel:nixpkgs-unstable nix_path: nixpkgs=channel:nixpkgs-unstable
- name: setup - name: setup

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`) - Security critical applications (E.g. `firefox`)
## Generating 23.05 Release Notes ## 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: Steps for updating 23.05 Release notes:
1. Edit `nixos/doc/manual/release-notes/rl-2305.section.md` with the desired changes 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` 2. Commit changes to `rl-2305.section.md`.
3. Include changes to `rl-2305.section.md` and `rl-2305.section.xml` in the same commit.
## Reviewing contributions ## Reviewing contributions

View file

@ -3,7 +3,7 @@ MD_TARGETS=$(addsuffix .xml, $(basename $(shell find . -type f -regex '.*\.md$$'
PANDOC ?= pandoc PANDOC ?= pandoc
pandoc_media_dir = media 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. # 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 pandoc_commonmark_enabled_extensions = +attributes+fenced_divs+footnotes+bracketed_spans+definition_lists+pipe_tables+raw_attribute
# Not needed: # 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

@ -11,4 +11,5 @@
<xi:include href="images/snaptools.section.xml" /> <xi:include href="images/snaptools.section.xml" />
<xi:include href="images/portableservice.section.xml" /> <xi:include href="images/portableservice.section.xml" />
<xi:include href="images/makediskimage.section.xml" /> <xi:include href="images/makediskimage.section.xml" />
<xi:include href="images/binarycache.section.xml" />
</chapter> </chapter>

View file

@ -0,0 +1,49 @@
# pkgs.mkBinaryCache {#sec-pkgs-binary-cache}
`pkgs.mkBinaryCache` is a function for creating Nix flat-file binary caches. Such a cache exists as a directory on disk, and can be used as a Nix substituter by passing `--substituter file:///path/to/cache` to Nix commands.
Nix packages are most commonly shared between machines using [HTTP, SSH, or S3](https://nixos.org/manual/nix/stable/package-management/sharing-packages.html), but a flat-file binary cache can still be useful in some situations. For example, you can copy it directly to another machine, or make it available on a network file system. It can also be a convenient way to make some Nix packages available inside a container via bind-mounting.
Note that this function is meant for advanced use-cases. The more idiomatic way to work with flat-file binary caches is via the [nix-copy-closure](https://nixos.org/manual/nix/stable/command-ref/nix-copy-closure.html) command. You may also want to consider [dockerTools](#sec-pkgs-dockerTools) for your containerization needs.
## Example
The following derivation will construct a flat-file binary cache containing the closure of `hello`.
```nix
mkBinaryCache {
rootPaths = [hello];
}
```
- `rootPaths` specifies a list of root derivations. The transitive closure of these derivations' outputs will be copied into the cache.
Here's an example of building and using the cache.
Build the cache on one machine, `host1`:
```shellSession
nix-build -E 'with import <nixpkgs> {}; mkBinaryCache { rootPaths = [hello]; }'
```
```shellSession
/nix/store/cc0562q828rnjqjyfj23d5q162gb424g-binary-cache
```
Copy the resulting directory to the other machine, `host2`:
```shellSession
scp result host2:/tmp/hello-cache
```
Substitute the derivation using the flat-file binary cache on the other machine, `host2`:
```shellSession
nix-build -A hello '<nixpkgs>' \
--option require-sigs false \
--option trusted-substituters file:///tmp/hello-cache \
--option substituters file:///tmp/hello-cache
```
```shellSession
/nix/store/gl5a41azbpsadfkfmbilh9yk40dh5dl0-hello-2.12.1
```

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. When a build failure happens there will be an instruction printed that shows how to attach with `cntr` to the build sandbox.
::: {.note} ::: {.note}
::: {.title}
Caution with remote builds 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`. 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

@ -171,6 +171,7 @@ let
inherit src version; inherit src version;
# nix will complain and tell you the right value to replace this with # nix will complain and tell you the right value to replace this with
hash = lib.fakeHash; hash = lib.fakeHash;
mixEnv = ""; # default is "prod", when empty includes all dependencies, such as "dev", "test".
# if you have build time environment variables add them here # if you have build time environment variables add them here
MY_ENV_VAR="my_value"; MY_ENV_VAR="my_value";
}; };

View file

@ -6,7 +6,7 @@ Nixpkgs provides a couple of facilities for working with this tool.
## Writing packages providing pkg-config modules ## Writing packages providing pkg-config modules
Packages should set `meta.pkgConfigProvides` with the list of package config modules they provide. Packages should set `meta.pkgConfigModules` with the list of package config modules they provide.
They should also use `testers.testMetaPkgConfig` to check that the final built package matches that list. They should also use `testers.testMetaPkgConfig` to check that the final built package matches that list.
Additionally, the [`validatePkgConfig` setup hook](https://nixos.org/manual/nixpkgs/stable/#validatepkgconfig), will do extra checks on to-be-installed pkg-config modules. Additionally, the [`validatePkgConfig` setup hook](https://nixos.org/manual/nixpkgs/stable/#validatepkgconfig), will do extra checks on to-be-installed pkg-config modules.

View file

@ -116,6 +116,82 @@ On Linux, `stdenv` also includes the `patchelf` utility.
## Specifying dependencies {#ssec-stdenv-dependencies} ## Specifying dependencies {#ssec-stdenv-dependencies}
Build systems often require more dependencies than just what `stdenv` provides. This section describes attributes accepted by `stdenv.mkDerivation` that can be used to make these dependencies available to the build system.
### Overview {#ssec-stdenv-dependencies-overview}
A full reference of the different kinds of dependencies is provided in [](#ssec-stdenv-dependencies-reference), but here is an overview of the most common ones.
It should cover most use cases.
Add dependencies to `nativeBuildInputs` if they are executed during the build:
- those which are needed on `$PATH` during the build, for example `cmake` and `pkg-config`
- [setup hooks](#ssec-setup-hooks), for example [`makeWrapper`](#fun-makeWrapper)
- interpreters needed by [`patchShebangs`](#patch-shebangs.sh) for build scripts (with the `--build` flag), which can be the case for e.g. `perl`
Add dependencies to `buildInputs` if they will end up copied or linked into the final output or otherwise used at runtime:
- libraries used by compilers, for example `zlib`,
- interpreters needed by [`patchShebangs`](#patch-shebangs.sh) for scripts which are installed, which can be the case for e.g. `perl`
::: {.note}
These criteria are independent.
For example, software using Wayland usually needs the `wayland` library at runtime, so `wayland` should be added to `buildInputs`.
But it also executes the `wayland-scanner` program as part of the build to generate code, so `wayland` should also be added to `nativeBuildInputs`.
:::
Dependencies needed only to run tests are similarly classified between native (executed during build) and non-native (executed at runtime):
- `nativeCheckInputs` for test tools needed on `$PATH` (such as `ctest`) and [setup hooks](#ssec-setup-hooks) (for example [`pytestCheckHook`](#python))
- `checkInputs` for libraries linked into test executables (for example the `qcheck` OCaml package)
These dependencies are only injected when [`doCheck`](#var-stdenv-doCheck) is set to `true`.
#### Example {#ssec-stdenv-dependencies-overview-example}
Consider for example this simplified derivation for `solo5`, a sandboxing tool:
```nix
stdenv.mkDerivation rec {
pname = "solo5";
version = "0.7.5";
src = fetchurl {
url = "https://github.com/Solo5/solo5/releases/download/v${version}/solo5-v${version}.tar.gz";
sha256 = "sha256-viwrS9lnaU8sTGuzK/+L/PlMM/xRRtgVuK5pixVeDEw=";
};
nativeBuildInputs = [ makeWrapper pkg-config ];
buildInputs = [ libseccomp ];
postInstall = ''
substituteInPlace $out/bin/solo5-virtio-mkimage \
--replace "/usr/lib/syslinux" "${syslinux}/share/syslinux" \
--replace "/usr/share/syslinux" "${syslinux}/share/syslinux" \
--replace "cp " "cp --no-preserve=mode "
wrapProgram $out/bin/solo5-virtio-mkimage \
--prefix PATH : ${lib.makeBinPath [ dosfstools mtools parted syslinux ]}
'';
doCheck = true;
nativeCheckInputs = [ util-linux qemu ];
checkPhase = '' [elided] '';
}
```
- `makeWrapper` is a setup hook, i.e., a shell script sourced by the generic builder of `stdenv`.
It is thus executed during the build and must be added to `nativeBuildInputs`.
- `pkg-config` is a build tool which the configure script of `solo5` expects to be on `$PATH` during the build:
therefore, it must be added to `nativeBuildInputs`.
- `libseccomp` is a library linked into `$out/bin/solo5-elftool`.
As it is used at runtime, it must be added to `buildInputs`.
- Tests need `qemu` and `getopt` (from `util-linux`) on `$PATH`, these must be added to `nativeCheckInputs`.
- Some dependencies are injected directly in the shell code of phases: `syslinux`, `dosfstools`, `mtools`, and `parted`.
In this specific case, they will end up in the output of the derivation (`$out` here).
As Nix marks dependencies whose absolute path is present in the output as runtime dependencies, adding them to `buildInputs` is not required.
For more complex cases, like libraries linked into an executable which is then executed as part of the build system, see [](#ssec-stdenv-dependencies-reference).
### Reference {#ssec-stdenv-dependencies-reference}
As described in the Nix manual, almost any `*.drv` store path in a derivations attribute set will induce a dependency on that derivation. `mkDerivation`, however, takes a few attributes intended to include all the dependencies of a package. This is done both for structure and consistency, but also so that certain other setup can take place. For example, certain dependencies need their bin directories added to the `PATH`. That is built-in, but other setup is done via a pluggable mechanism that works in conjunction with these dependency attributes. See [](#ssec-setup-hooks) for details. As described in the Nix manual, almost any `*.drv` store path in a derivations attribute set will induce a dependency on that derivation. `mkDerivation`, however, takes a few attributes intended to include all the dependencies of a package. This is done both for structure and consistency, but also so that certain other setup can take place. For example, certain dependencies need their bin directories added to the `PATH`. That is built-in, but other setup is done via a pluggable mechanism that works in conjunction with these dependency attributes. See [](#ssec-setup-hooks) for details.
Dependencies can be broken down along three axes: their host and target platforms relative to the new derivations, and whether they are propagated. The platform distinctions are motivated by cross compilation; see [](#chap-cross) for exactly what each platform means. [^footnote-stdenv-ignored-build-platform] But even if one is not cross compiling, the platforms imply whether or not the dependency is needed at run-time or build-time, a concept that makes perfect sense outside of cross compilation. By default, the run-time/build-time distinction is just a hint for mental clarity, but with `strictDeps` set it is mostly enforced even in the native case. Dependencies can be broken down along three axes: their host and target platforms relative to the new derivations, and whether they are propagated. The platform distinctions are motivated by cross compilation; see [](#chap-cross) for exactly what each platform means. [^footnote-stdenv-ignored-build-platform] But even if one is not cross compiling, the platforms imply whether or not the dependency is needed at run-time or build-time, a concept that makes perfect sense outside of cross compilation. By default, the run-time/build-time distinction is just a hint for mental clarity, but with `strictDeps` set it is mostly enforced even in the native case.
@ -187,21 +263,21 @@ Because of the bounds checks, the uncommon cases are `h = t` and `h + 2 = t`. In
Overall, the unifying theme here is that propagation shouldnt be introducing transitive dependencies involving platforms the depending package is unaware of. \[One can imagine the dependending package asking for dependencies with the platforms it knows about; other platforms it doesnt know how to ask for. The platform description in that scenario is a kind of unforagable capability.\] The offset bounds checking and definition of `mapOffset` together ensure that this is the case. Discovering a new offset is discovering a new platform, and since those platforms werent in the derivation “spec” of the needing package, they cannot be relevant. From a capability perspective, we can imagine that the host and target platforms of a package are the capabilities a package requires, and the depending package must provide the capability to the dependency. Overall, the unifying theme here is that propagation shouldnt be introducing transitive dependencies involving platforms the depending package is unaware of. \[One can imagine the dependending package asking for dependencies with the platforms it knows about; other platforms it doesnt know how to ask for. The platform description in that scenario is a kind of unforagable capability.\] The offset bounds checking and definition of `mapOffset` together ensure that this is the case. Discovering a new offset is discovering a new platform, and since those platforms werent in the derivation “spec” of the needing package, they cannot be relevant. From a capability perspective, we can imagine that the host and target platforms of a package are the capabilities a package requires, and the depending package must provide the capability to the dependency.
### Variables specifying dependencies {#variables-specifying-dependencies} #### Variables specifying dependencies {#variables-specifying-dependencies}
#### `depsBuildBuild` {#var-stdenv-depsBuildBuild} ##### `depsBuildBuild` {#var-stdenv-depsBuildBuild}
A list of dependencies whose host and target platforms are the new derivations build platform. These are programs and libraries used at build time that produce programs and libraries also used at build time. If the dependency doesnt care about the target platform (i.e. isnt a compiler or similar tool), put it in `nativeBuildInputs` instead. The most common use of this `buildPackages.stdenv.cc`, the default C compiler for this role. That example crops up more than one might think in old commonly used C libraries. A list of dependencies whose host and target platforms are the new derivations build platform. These are programs and libraries used at build time that produce programs and libraries also used at build time. If the dependency doesnt care about the target platform (i.e. isnt a compiler or similar tool), put it in `nativeBuildInputs` instead. The most common use of this `buildPackages.stdenv.cc`, the default C compiler for this role. That example crops up more than one might think in old commonly used C libraries.
Since these packages are able to be run at build-time, they are always added to the `PATH`, as described above. But since these packages are only guaranteed to be able to run then, they shouldnt persist as run-time dependencies. This isnt currently enforced, but could be in the future. Since these packages are able to be run at build-time, they are always added to the `PATH`, as described above. But since these packages are only guaranteed to be able to run then, they shouldnt persist as run-time dependencies. This isnt currently enforced, but could be in the future.
#### `nativeBuildInputs` {#var-stdenv-nativeBuildInputs} ##### `nativeBuildInputs` {#var-stdenv-nativeBuildInputs}
A list of dependencies whose host platform is the new derivations build platform, and target platform is the new derivations host platform. These are programs and libraries used at build-time that, if they are a compiler or similar tool, produce code to run at run-time—i.e. tools used to build the new derivation. If the dependency doesnt care about the target platform (i.e. isnt a compiler or similar tool), put it here, rather than in `depsBuildBuild` or `depsBuildTarget`. This could be called `depsBuildHost` but `nativeBuildInputs` is used for historical continuity. A list of dependencies whose host platform is the new derivations build platform, and target platform is the new derivations host platform. These are programs and libraries used at build-time that, if they are a compiler or similar tool, produce code to run at run-time—i.e. tools used to build the new derivation. If the dependency doesnt care about the target platform (i.e. isnt a compiler or similar tool), put it here, rather than in `depsBuildBuild` or `depsBuildTarget`. This could be called `depsBuildHost` but `nativeBuildInputs` is used for historical continuity.
Since these packages are able to be run at build-time, they are added to the `PATH`, as described above. But since these packages are only guaranteed to be able to run then, they shouldnt persist as run-time dependencies. This isnt currently enforced, but could be in the future. Since these packages are able to be run at build-time, they are added to the `PATH`, as described above. But since these packages are only guaranteed to be able to run then, they shouldnt persist as run-time dependencies. This isnt currently enforced, but could be in the future.
#### `depsBuildTarget` {#var-stdenv-depsBuildTarget} ##### `depsBuildTarget` {#var-stdenv-depsBuildTarget}
A list of dependencies whose host platform is the new derivations build platform, and target platform is the new derivations target platform. These are programs used at build time that produce code to run with code produced by the depending package. Most commonly, these are tools used to build the runtime or standard library that the currently-being-built compiler will inject into any code it compiles. In many cases, the currently-being-built-compiler is itself employed for that task, but when that compiler wont run (i.e. its build and host platform differ) this is not possible. Other times, the compiler relies on some other tool, like binutils, that is always built separately so that the dependency is unconditional. A list of dependencies whose host platform is the new derivations build platform, and target platform is the new derivations target platform. These are programs used at build time that produce code to run with code produced by the depending package. Most commonly, these are tools used to build the runtime or standard library that the currently-being-built compiler will inject into any code it compiles. In many cases, the currently-being-built-compiler is itself employed for that task, but when that compiler wont run (i.e. its build and host platform differ) this is not possible. Other times, the compiler relies on some other tool, like binutils, that is always built separately so that the dependency is unconditional.
@ -209,41 +285,41 @@ This is a somewhat confusing concept to wrap ones head around, and for good r
Since these packages are able to run at build time, they are added to the `PATH`, as described above. But since these packages are only guaranteed to be able to run then, they shouldnt persist as run-time dependencies. This isnt currently enforced, but could be in the future. Since these packages are able to run at build time, they are added to the `PATH`, as described above. But since these packages are only guaranteed to be able to run then, they shouldnt persist as run-time dependencies. This isnt currently enforced, but could be in the future.
#### `depsHostHost` {#var-stdenv-depsHostHost} ##### `depsHostHost` {#var-stdenv-depsHostHost}
A list of dependencies whose host and target platforms match the new derivations host platform. In practice, this would usually be tools used by compilers for macros or a metaprogramming system, or libraries used by the macros or metaprogramming code itself. Its always preferable to use a `depsBuildBuild` dependency in the derivation being built over a `depsHostHost` on the tool doing the building for this purpose. A list of dependencies whose host and target platforms match the new derivations host platform. In practice, this would usually be tools used by compilers for macros or a metaprogramming system, or libraries used by the macros or metaprogramming code itself. Its always preferable to use a `depsBuildBuild` dependency in the derivation being built over a `depsHostHost` on the tool doing the building for this purpose.
#### `buildInputs` {#var-stdenv-buildInputs} ##### `buildInputs` {#var-stdenv-buildInputs}
A list of dependencies whose host platform and target platform match the new derivations. This would be called `depsHostTarget` but for historical continuity. If the dependency doesnt care about the target platform (i.e. isnt a compiler or similar tool), put it here, rather than in `depsBuildBuild`. A list of dependencies whose host platform and target platform match the new derivations. This would be called `depsHostTarget` but for historical continuity. If the dependency doesnt care about the target platform (i.e. isnt a compiler or similar tool), put it here, rather than in `depsBuildBuild`.
These are often programs and libraries used by the new derivation at *run*-time, but that isnt always the case. For example, the machine code in a statically-linked library is only used at run-time, but the derivation containing the library is only needed at build-time. Even in the dynamic case, the library may also be needed at build-time to appease the linker. These are often programs and libraries used by the new derivation at *run*-time, but that isnt always the case. For example, the machine code in a statically-linked library is only used at run-time, but the derivation containing the library is only needed at build-time. Even in the dynamic case, the library may also be needed at build-time to appease the linker.
#### `depsTargetTarget` {#var-stdenv-depsTargetTarget} ##### `depsTargetTarget` {#var-stdenv-depsTargetTarget}
A list of dependencies whose host platform matches the new derivations target platform. These are packages that run on the target platform, e.g. the standard library or run-time deps of standard library that a compiler insists on knowing about. Its poor form in almost all cases for a package to depend on another from a future stage \[future stage corresponding to positive offset\]. Do not use this attribute unless you are packaging a compiler and are sure it is needed. A list of dependencies whose host platform matches the new derivations target platform. These are packages that run on the target platform, e.g. the standard library or run-time deps of standard library that a compiler insists on knowing about. Its poor form in almost all cases for a package to depend on another from a future stage \[future stage corresponding to positive offset\]. Do not use this attribute unless you are packaging a compiler and are sure it is needed.
#### `depsBuildBuildPropagated` {#var-stdenv-depsBuildBuildPropagated} ##### `depsBuildBuildPropagated` {#var-stdenv-depsBuildBuildPropagated}
The propagated equivalent of `depsBuildBuild`. This perhaps never ought to be used, but it is included for consistency \[see below for the others\]. The propagated equivalent of `depsBuildBuild`. This perhaps never ought to be used, but it is included for consistency \[see below for the others\].
#### `propagatedNativeBuildInputs` {#var-stdenv-propagatedNativeBuildInputs} ##### `propagatedNativeBuildInputs` {#var-stdenv-propagatedNativeBuildInputs}
The propagated equivalent of `nativeBuildInputs`. This would be called `depsBuildHostPropagated` but for historical continuity. For example, if package `Y` has `propagatedNativeBuildInputs = [X]`, and package `Z` has `buildInputs = [Y]`, then package `Z` will be built as if it included package `X` in its `nativeBuildInputs`. If instead, package `Z` has `nativeBuildInputs = [Y]`, then `Z` will be built as if it included `X` in the `depsBuildBuild` of package `Z`, because of the sum of the two `-1` host offsets. The propagated equivalent of `nativeBuildInputs`. This would be called `depsBuildHostPropagated` but for historical continuity. For example, if package `Y` has `propagatedNativeBuildInputs = [X]`, and package `Z` has `buildInputs = [Y]`, then package `Z` will be built as if it included package `X` in its `nativeBuildInputs`. If instead, package `Z` has `nativeBuildInputs = [Y]`, then `Z` will be built as if it included `X` in the `depsBuildBuild` of package `Z`, because of the sum of the two `-1` host offsets.
#### `depsBuildTargetPropagated` {#var-stdenv-depsBuildTargetPropagated} ##### `depsBuildTargetPropagated` {#var-stdenv-depsBuildTargetPropagated}
The propagated equivalent of `depsBuildTarget`. This is prefixed for the same reason of alerting potential users. The propagated equivalent of `depsBuildTarget`. This is prefixed for the same reason of alerting potential users.
#### `depsHostHostPropagated` {#var-stdenv-depsHostHostPropagated} ##### `depsHostHostPropagated` {#var-stdenv-depsHostHostPropagated}
The propagated equivalent of `depsHostHost`. The propagated equivalent of `depsHostHost`.
#### `propagatedBuildInputs` {#var-stdenv-propagatedBuildInputs} ##### `propagatedBuildInputs` {#var-stdenv-propagatedBuildInputs}
The propagated equivalent of `buildInputs`. This would be called `depsHostTargetPropagated` but for historical continuity. The propagated equivalent of `buildInputs`. This would be called `depsHostTargetPropagated` but for historical continuity.
#### `depsTargetTargetPropagated` {#var-stdenv-depsTargetTargetPropagated} ##### `depsTargetTargetPropagated` {#var-stdenv-depsTargetTargetPropagated}
The propagated equivalent of `depsTargetTarget`. This is prefixed for the same reason of alerting potential users. The propagated equivalent of `depsTargetTarget`. This is prefixed for the same reason of alerting potential users.

View file

@ -36,6 +36,9 @@ let
inherit (lib.types) inherit (lib.types)
mkOptionType mkOptionType
; ;
prioritySuggestion = ''
Use `lib.mkForce value` or `lib.mkDefault value` to change the priority on any of these definitions.
'';
in in
rec { rec {
@ -184,7 +187,7 @@ rec {
if length defs == 1 if length defs == 1
then (head defs).value then (head defs).value
else assert length defs > 1; else assert length defs > 1;
throw "The option `${showOption loc}' is defined multiple times.\n${message}\nDefinition values:${showDefs defs}"; throw "The option `${showOption loc}' is defined multiple times while it's expected to be unique.\n${message}\nDefinition values:${showDefs defs}\n${prioritySuggestion}";
/* "Merge" option definitions by checking that they all have the same value. */ /* "Merge" option definitions by checking that they all have the same value. */
mergeEqualOption = loc: defs: mergeEqualOption = loc: defs:
@ -195,7 +198,7 @@ rec {
else if length defs == 1 then (head defs).value else if length defs == 1 then (head defs).value
else (foldl' (first: def: else (foldl' (first: def:
if def.value != first.value then if def.value != first.value then
throw "The option `${showOption loc}' has conflicting definition values:${showDefs [ first def ]}" throw "The option `${showOption loc}' has conflicting definition values:${showDefs [ first def ]}\n${prioritySuggestion}"
else else
first) (head defs) (tail defs)).value; first) (head defs) (tail defs)).value;

View file

@ -40,14 +40,21 @@ rec {
# a superior CPU has all the features of an inferior and is able to build and test code for it # a superior CPU has all the features of an inferior and is able to build and test code for it
inferiors = { inferiors = {
# x86_64 Intel # x86_64 Intel
# https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html
default = [ ]; default = [ ];
westmere = [ ]; westmere = [ ];
sandybridge = [ "westmere" ] ++ inferiors.westmere; sandybridge = [ "westmere" ] ++ inferiors.westmere;
ivybridge = [ "sandybridge" ] ++ inferiors.sandybridge; ivybridge = [ "sandybridge" ] ++ inferiors.sandybridge;
haswell = [ "ivybridge" ] ++ inferiors.ivybridge; haswell = [ "ivybridge" ] ++ inferiors.ivybridge;
broadwell = [ "haswell" ] ++ inferiors.haswell; broadwell = [ "haswell" ] ++ inferiors.haswell;
skylake = [ "broadwell" ] ++ inferiors.broadwell; skylake = [ "broadwell" ] ++ inferiors.broadwell;
skylake-avx512 = [ "skylake" ] ++ inferiors.skylake; skylake-avx512 = [ "skylake" ] ++ inferiors.skylake;
cannonlake = [ "skylake-avx512" ] ++ inferiors.skylake-avx512;
icelake-client = [ "cannonlake" ] ++ inferiors.cannonlake;
icelake-server = [ "icelake-client" ] ++ inferiors.icelake-client;
cascadelake = [ "skylake-avx512" ] ++ inferiors.cannonlake;
cooperlake = [ "cascadelake" ] ++ inferiors.cascadelake;
tigerlake = [ "icelake-server" ] ++ inferiors.icelake-server;
# x86_64 AMD # x86_64 AMD
# TODO: fill this (need testing) # TODO: fill this (need testing)

View file

@ -76,7 +76,7 @@
_0xB10C = { _0xB10C = {
email = "nixpkgs@b10c.me"; email = "nixpkgs@b10c.me";
name = "0xB10C"; name = "0xB10C";
github = "0xb10c"; github = "0xB10C";
githubId = 19157360; githubId = 19157360;
}; };
_0xbe7a = { _0xbe7a = {
@ -169,6 +169,12 @@
githubId = 12578560; githubId = 12578560;
name = "Quinn Bohner"; name = "Quinn Bohner";
}; };
_9999years = {
email = "rbt@fastmail.com";
github = "9999years";
githubId = 15312184;
name = "Rebecca Turner";
};
a1russell = { a1russell = {
email = "adamlr6+pub@gmail.com"; email = "adamlr6+pub@gmail.com";
github = "a1russell"; github = "a1russell";
@ -811,7 +817,7 @@
notbandali = { notbandali = {
name = "Amin Bandali"; name = "Amin Bandali";
email = "bandali@gnu.org"; email = "bandali@gnu.org";
github = "notbandali"; github = "bandali0";
githubId = 1254858; githubId = 1254858;
keys = [{ keys = [{
fingerprint = "BE62 7373 8E61 6D6D 1B3A 08E8 A21A 0202 4881 6103"; fingerprint = "BE62 7373 8E61 6D6D 1B3A 08E8 A21A 0202 4881 6103";
@ -926,6 +932,12 @@
githubId = 106511; githubId = 106511;
name = "Andrew Kelley"; name = "Andrew Kelley";
}; };
andrewsmith = {
email = "andrew@velvet.software";
github = "andrewsmith";
githubId = 29887;
name = "Andrew Smith";
};
andsild = { andsild = {
email = "andsild@gmail.com"; email = "andsild@gmail.com";
github = "andsild"; github = "andsild";
@ -1754,7 +1766,7 @@
benesim = { benesim = {
name = "Benjamin Isbarn"; name = "Benjamin Isbarn";
email = "benjamin.isbarn@gmail.com"; email = "benjamin.isbarn@gmail.com";
github = "benesim"; github = "BeneSim";
githubId = 29384538; githubId = 29384538;
keys = [{ keys = [{
fingerprint = "D35E C9CE E631 638F F1D8 B401 6F0E 410D C3EE D02"; fingerprint = "D35E C9CE E631 638F F1D8 B401 6F0E 410D C3EE D02";
@ -2376,6 +2388,12 @@
github = "CaptainJawZ"; github = "CaptainJawZ";
githubId = 43111068; githubId = 43111068;
}; };
CardboardTurkey = {
name = "Kiran Ostrolenk";
email = "kostrolenk@gmail.com";
github = "CardboardTurkey";
githubId = 34030186;
};
carlosdagos = { carlosdagos = {
email = "m@cdagostino.io"; email = "m@cdagostino.io";
github = "carlosdagos"; github = "carlosdagos";
@ -3124,7 +3142,7 @@
cust0dian = { cust0dian = {
email = "serg@effectful.software"; email = "serg@effectful.software";
github = "cust0dian"; github = "cust0dian";
githubId = 389387; githubId = 119854490;
name = "Serg Nesterov"; name = "Serg Nesterov";
keys = [{ keys = [{
fingerprint = "6E7D BA30 DB5D BA60 693C 3BE3 1512 F6EB 84AE CC8C"; fingerprint = "6E7D BA30 DB5D BA60 693C 3BE3 1512 F6EB 84AE CC8C";
@ -3403,7 +3421,7 @@
}; };
davsanchez = { davsanchez = {
email = "davidslt+nixpkgs@pm.me"; email = "davidslt+nixpkgs@pm.me";
github = "davsanchez"; github = "DavSanchez";
githubId = 11422515; githubId = 11422515;
name = "David Sánchez"; name = "David Sánchez";
}; };
@ -3849,6 +3867,12 @@
githubId = 39825; githubId = 39825;
name = "Dominik Honnef"; name = "Dominik Honnef";
}; };
doriath = {
email = "tomasz.zurkowski@gmail.com";
github = "doriath";
githubId = 150959;
name = "Tomasz Zurkowski";
};
doronbehar = { doronbehar = {
email = "me@doronbehar.com"; email = "me@doronbehar.com";
github = "doronbehar"; github = "doronbehar";
@ -3890,6 +3914,7 @@
name = "Davide Peressoni"; name = "Davide Peressoni";
email = "davide.peressoni@tuta.io"; email = "davide.peressoni@tuta.io";
matrix = "@dpd-:matrix.org"; matrix = "@dpd-:matrix.org";
github = "DPDmancul";
githubId = 3186857; githubId = 3186857;
}; };
dpercy = { dpercy = {
@ -4320,7 +4345,7 @@
}; };
elnudev = { elnudev = {
email = "elnu@elnu.com"; email = "elnu@elnu.com";
github = "elnudev"; github = "ElnuDev";
githubId = 9874955; githubId = 9874955;
name = "Elnu"; name = "Elnu";
}; };
@ -4608,7 +4633,7 @@
}; };
ewok = { ewok = {
email = "ewok@ewok.ru"; email = "ewok@ewok.ru";
github = "ewok"; github = "ewok-old";
githubId = 454695; githubId = 454695;
name = "Artur Taranchiev"; name = "Artur Taranchiev";
}; };
@ -5163,6 +5188,12 @@
githubId = 606000; githubId = 606000;
name = "Gabriel Adomnicai"; name = "Gabriel Adomnicai";
}; };
garaiza-93 = {
email = "araizagustavo93@gmail.com";
github = "garaiza-93";
githubId = 57430880;
name = "Gustavo Araiza";
};
Gabriel439 = { Gabriel439 = {
email = "Gabriel439@gmail.com"; email = "Gabriel439@gmail.com";
github = "Gabriella439"; github = "Gabriella439";
@ -5739,7 +5770,7 @@
}; };
harrisonthorne = { harrisonthorne = {
email = "harrisonthorne@proton.me"; email = "harrisonthorne@proton.me";
github = "harrisonthorne"; github = "muni-corn";
githubId = 33523827; githubId = 33523827;
name = "Harrison Thorne"; name = "Harrison Thorne";
}; };
@ -6974,7 +7005,7 @@
}; };
jkarlson = { jkarlson = {
email = "jekarlson@gmail.com"; email = "jekarlson@gmail.com";
github = "jkarlson"; github = "ethorsoe";
githubId = 1204734; githubId = 1204734;
name = "Emil Karlson"; name = "Emil Karlson";
}; };
@ -7752,7 +7783,7 @@
name = "Kid"; name = "Kid";
}; };
kidsan = { kidsan = {
github = "kidsan"; github = "Kidsan";
githubId = 8798449; githubId = 8798449;
name = "kidsan"; name = "kidsan";
}; };
@ -8649,6 +8680,8 @@
loveisgrief = { loveisgrief = {
name = "LoveIsGrief"; name = "LoveIsGrief";
email = "loveisgrief@tuta.io"; email = "loveisgrief@tuta.io";
github = "LoveIsGrief";
githubId = 2829538;
keys = [{ keys = [{
fingerprint = "9847 4F48 18C6 4E0A F0C5 3529 E96D 1EDF A053 45EB"; fingerprint = "9847 4F48 18C6 4E0A F0C5 3529 E96D 1EDF A053 45EB";
}]; }];
@ -8800,7 +8833,7 @@
}; };
lux = { lux = {
email = "lux@lux.name"; email = "lux@lux.name";
github = "luxferresum"; github = "luxzeitlos";
githubId = 1208273; githubId = 1208273;
matrix = "@lux:ontheblueplanet.com"; matrix = "@lux:ontheblueplanet.com";
name = "Lux"; name = "Lux";
@ -9273,7 +9306,7 @@
}; };
maxwell-lt = { maxwell-lt = {
email = "maxwell.lt@live.com"; email = "maxwell.lt@live.com";
github = "maxwell-lt"; github = "Maxwell-lt";
githubId = 17859747; githubId = 17859747;
name = "Maxwell L-T"; name = "Maxwell L-T";
}; };
@ -9912,7 +9945,7 @@
name = "Mon Aaraj"; name = "Mon Aaraj";
email = "owo69uwu69@gmail.com"; email = "owo69uwu69@gmail.com";
matrix = "@mon:tchncs.de"; matrix = "@mon:tchncs.de";
github = "MonAaraj"; github = "ribosomerocker";
githubId = 46468162; githubId = 46468162;
}; };
monsieurp = { monsieurp = {
@ -10161,7 +10194,7 @@
munksgaard = { munksgaard = {
name = "Philip Munksgaard"; name = "Philip Munksgaard";
email = "philip@munksgaard.me"; email = "philip@munksgaard.me";
github = "munksgaard"; github = "Munksgaard";
githubId = 230613; githubId = 230613;
matrix = "@philip:matrix.munksgaard.me"; matrix = "@philip:matrix.munksgaard.me";
keys = [{ keys = [{
@ -10496,6 +10529,12 @@
github = "nikstur"; github = "nikstur";
githubId = 61635709; githubId = 61635709;
}; };
nintron = {
email = "nintron@sent.com";
github = "Nintron27";
githubId = 47835714;
name = "Nintron";
};
ngerstle = { ngerstle = {
name = "Nicholas Gerstle"; name = "Nicholas Gerstle";
email = "ngerstle@gmail.com"; email = "ngerstle@gmail.com";
@ -10778,7 +10817,7 @@
}; };
nrhelmi = { nrhelmi = {
email = "helmiinour@gmail.com"; email = "helmiinour@gmail.com";
github = "nrhelmi"; github = "NRHelmi";
githubId = 15707703; githubId = 15707703;
name = "Helmi Nour"; name = "Helmi Nour";
}; };
@ -11155,7 +11194,7 @@
}; };
paddygord = { paddygord = {
email = "pgpatrickgordon@gmail.com"; email = "pgpatrickgordon@gmail.com";
github = "paddygord"; github = "avaunit02";
githubId = 10776658; githubId = 10776658;
name = "Patrick Gordon"; name = "Patrick Gordon";
}; };
@ -12205,7 +12244,7 @@
}; };
ratsclub = { ratsclub = {
email = "victor@freire.dev.br"; email = "victor@freire.dev.br";
github = "vtrf"; github = "ratsclub";
githubId = 25647735; githubId = 25647735;
name = "Victor Freire"; name = "Victor Freire";
}; };
@ -12469,7 +12508,7 @@
}; };
rika = { rika = {
email = "rika@paymentswit.ch"; email = "rika@paymentswit.ch";
github = "NekomimiScience"; github = "ScarletHg";
githubId = 1810487; githubId = 1810487;
name = "Rika"; name = "Rika";
}; };
@ -12815,6 +12854,12 @@
githubId = 5236428; githubId = 5236428;
name = "Gaëtan André"; name = "Gaëtan André";
}; };
rvnstn = {
email = "github@rvnstn.de";
github = "rvnstn";
githubId = 2364742;
name = "Tobias Ravenstein";
};
rvolosatovs = { rvolosatovs = {
email = "rvolosatovs@riseup.net"; email = "rvolosatovs@riseup.net";
github = "rvolosatovs"; github = "rvolosatovs";
@ -13464,7 +13509,7 @@
shreerammodi = { shreerammodi = {
name = "Shreeram Modi"; name = "Shreeram Modi";
email = "shreerammodi10@gmail.com"; email = "shreerammodi10@gmail.com";
github = "Shrimpram"; github = "shrimpram";
githubId = 67710369; githubId = 67710369;
keys = [{ keys = [{
fingerprint = "EA88 EA07 26E9 6CBF 6365 3966 163B 16EE 76ED 24CE"; fingerprint = "EA88 EA07 26E9 6CBF 6365 3966 163B 16EE 76ED 24CE";
@ -13702,7 +13747,7 @@
sno2wman = { sno2wman = {
name = "SnO2WMaN"; name = "SnO2WMaN";
email = "me@sno2wman.net"; email = "me@sno2wman.net";
github = "sno2wman"; github = "SnO2WMaN";
githubId = 15155608; githubId = 15155608;
}; };
snpschaaf = { snpschaaf = {
@ -14428,6 +14473,12 @@
githubId = 139251; githubId = 139251;
name = "Tom Hunger"; name = "Tom Hunger";
}; };
tehmatt = {
name = "tehmatt";
email = "nix@programsareproofs.com";
github = "tehmatt";
githubId = 3358866;
};
tejasag = { tejasag = {
name = "Tejas Agarwal"; name = "Tejas Agarwal";
email = "tejasagarwalbly@gmail.com"; email = "tejasagarwalbly@gmail.com";
@ -14450,7 +14501,7 @@
}; };
teozkr = { teozkr = {
email = "teo@nullable.se"; email = "teo@nullable.se";
github = "teozkr"; github = "nightkr";
githubId = 649832; githubId = 649832;
name = "Teo Klestrup Röijezon"; name = "Teo Klestrup Röijezon";
}; };
@ -14864,7 +14915,7 @@
}; };
toastal = { toastal = {
email = "toastal+nix@posteo.net"; email = "toastal+nix@posteo.net";
matrix = "@toastal:matrix.org"; matrix = "@toastal:chat.mozilla.org";
github = "toastal"; github = "toastal";
githubId = 561087; githubId = 561087;
name = "toastal"; name = "toastal";
@ -14937,7 +14988,7 @@
}; };
tonyshkurenko = { tonyshkurenko = {
email = "support@twingate.com"; email = "support@twingate.com";
github = "tonyshkurenko"; github = "antonshkurenko";
githubId = 8597964; githubId = 8597964;
name = "Anton Shkurenko"; name = "Anton Shkurenko";
}; };
@ -15276,7 +15327,7 @@
}; };
uthar = { uthar = {
email = "galkowskikasper@gmail.com"; email = "galkowskikasper@gmail.com";
github = "uthar"; github = "Uthar";
githubId = 15697697; githubId = 15697697;
name = "Kasper Gałkowski"; name = "Kasper Gałkowski";
}; };
@ -16108,6 +16159,12 @@
githubId = 2242427; githubId = 2242427;
name = "Yoann Ono"; name = "Yoann Ono";
}; };
yajo = {
email = "yajo.sk8@gmail.com";
github = "yajo";
githubId = 973709;
name = "Jairo Llopis";
};
yana = { yana = {
email = "yana@riseup.net"; email = "yana@riseup.net";
github = "yanalunaterra"; github = "yanalunaterra";
@ -16400,7 +16457,7 @@
zebreus = { zebreus = {
matrix = "@lennart:cicen.net"; matrix = "@lennart:cicen.net";
email = "lennarteichhorn+nixpkgs@gmail.com"; email = "lennarteichhorn+nixpkgs@gmail.com";
github = "Zebreus"; github = "zebreus";
githubId = 1557253; githubId = 1557253;
name = "Lennart Eichhorn"; name = "Lennart Eichhorn";
}; };
@ -16466,7 +16523,7 @@
name = "zimbatm"; name = "zimbatm";
}; };
Zimmi48 = { Zimmi48 = {
email = "theo.zimmermann@univ-paris-diderot.fr"; email = "theo.zimmermann@telecom-paris.fr";
github = "Zimmi48"; github = "Zimmi48";
githubId = 1108325; githubId = 1108325;
name = "Théo Zimmermann"; name = "Théo Zimmermann";

View file

@ -1,7 +1,21 @@
# Nix script to lookup maintainer github handles from their email address. Used by ./hydra-report.hs. # Nix script to lookup maintainer github handles from their email address. Used by ./hydra-report.hs.
#
# This script produces an attr set mapping of email addresses to GitHub handles:
#
# ```nix
# > import ./maintainer-handles.nix
# { "cdep.illabout@gmail.com" = "cdepillabout"; "john@smith.com" = "johnsmith"; ... }
# ```
#
# This mapping contains all maintainers in ../../mainatainer-list.nix, but it
# ignores maintainers who don't have a GitHub account or an email address.
let let
pkgs = import ../../.. {}; pkgs = import ../../.. {};
maintainers = import ../../maintainer-list.nix; maintainers = import ../../maintainer-list.nix;
inherit (pkgs) lib; inherit (pkgs) lib;
mkMailGithubPair = _: maintainer: if maintainer ? github then { "${maintainer.email}" = maintainer.github; } else {}; mkMailGithubPair = _: maintainer:
if (maintainer ? email) && (maintainer ? github) then
{ "${maintainer.email}" = maintainer.github; }
else
{};
in lib.zipAttrsWith (_: builtins.head) (lib.mapAttrsToList mkMailGithubPair maintainers) in lib.zipAttrsWith (_: builtins.head) (lib.mapAttrsToList mkMailGithubPair maintainers)

View file

@ -312,6 +312,19 @@ with lib.maintainers; {
enableFeatureFreezePing = true; enableFeatureFreezePing = true;
}; };
graalvm-ce = {
members = [
bandresen
hlolli
glittershark
babariviere
ericdallo
thiagokokada
];
scope = "Maintain GraalVM Community Edition packages.";
shortName = "GraalVM-CE";
};
haskell = { haskell = {
members = [ members = [
cdepillabout cdepillabout

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 defined in other modules. This is what the `config` function argument is
for: it contains the complete, merged system configuration. That is, for: it contains the complete, merged system configuration. That is,
`config` is the result of combining the configurations returned by every `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-environment.systemPackages) only if
[](#opt-services.xserver.enable) is set to `true` somewhere else: [](#opt-services.xserver.enable) is set to `true` somewhere else:
@ -125,9 +131,3 @@ in
{ imports = [ (netConfig "nixos.localdomain") ]; } { 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} ## 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: Once installed, mounting a directory interactively is simple as running:
```ShellSession ```ShellSession
$ sshfs my-user@example.com:/my-dir /mnt/my-dir $ 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; 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 The x11 login screen can be skipped entirely, automatically logging you
into your window manager and desktop environment when you boot your 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"; 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` There are two choices for Intel Graphics drivers in X.org: `modesetting`
(included in the xorg-server itself) and `intel` (provided by the (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 Note that this will likely downgrade the performance compared to
`modesetting` or `intel` with DRI 3 (default). `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 NVIDIA provides a proprietary driver for its graphics cards that has
better 3D performance than the X.org drivers. It is not enabled by 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 You may need to reboot after enabling this driver to prevent a clash
with other kernel modules. 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 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 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 You will need to reboot after enabling this driver to prevent a clash
with other kernel modules. 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 Support for Synaptics touchpads (found in many laptops such as the Dell
Latitude series) can be enabled as follows: 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 Note: the use of `services.xserver.synaptics` is deprecated since NixOS
17.09. 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 GTK themes can be installed either to user profile or system-wide (via
`environment.systemPackages`). To make Qt 5 applications look similar to `environment.systemPackages`). To make Qt 5 applications look similar to
@ -204,7 +204,7 @@ qt.platformTheme = "gtk2";
qt.style = "gtk2"; qt.style = "gtk2";
``` ```
## Custom XKB layouts {#custom-xkb-layouts .unnumbered} ## Custom XKB layouts {#custom-xkb-layouts}
It is possible to install custom [ XKB It is possible to install custom [ XKB
](https://en.wikipedia.org/wiki/X_keyboard_extension) keyboard layouts ](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 manually (system wide), put them into your
[](#opt-environment.systemPackages) from `pkgs.xfce`. [](#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 Thunar (the Xfce file manager) is automatically enabled when Xfce is
enabled. To enable Thunar without enabling Xfce, use the configuration 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-programs.thunar.plugins). You shouldn't just add them to
[](#opt-environment.systemPackages). [](#opt-environment.systemPackages).
## Troubleshooting {#sec-xfce-troubleshooting .unnumbered} ## Troubleshooting {#sec-xfce-troubleshooting}
Even after enabling udisks2, volume management might not work. Thunar 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 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 ```ShellSession
$ cd /path/to/nixpkgs $ cd /path/to/nixpkgs
$ ./nixos/doc/manual/md-to-db.sh
$ nix-build nixos/release.nix -A manual.x86_64-linux $ nix-build nixos/release.nix -A manual.x86_64-linux
``` ```

View file

@ -68,12 +68,34 @@ let
optionIdPrefix = "test-opt-"; 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" { modulesDoc = runCommand "modules.xml" {
nativeBuildInputs = [ pkgs.nixos-render-docs ]; nativeBuildInputs = [ pkgs.nixos-render-docs ];
} '' } ''
nixos-render-docs manual docbook \ nixos-render-docs manual docbook-section \
--manpage-urls ${manpageUrls} \ --manpage-urls ${manpageUrls} \
"$out" \ "$out" \
--section \ --section \
@ -255,8 +277,7 @@ in rec {
# Generate the NixOS manpages. # Generate the NixOS manpages.
manpages = runCommand "nixos-manpages" manpages = runCommand "nixos-manpages"
{ inherit sources; { nativeBuildInputs = [
nativeBuildInputs = [
buildPackages.installShellFiles buildPackages.installShellFiles
] ++ lib.optionals allowDocBook [ ] ++ lib.optionals allowDocBook [
buildPackages.libxml2.bin buildPackages.libxml2.bin

View file

@ -13,9 +13,8 @@ checking for entire option trees, it is only recommended for use in
submodules. submodules.
::: {#ex-freeform-module .example} ::: {#ex-freeform-module .example}
::: {.title}
**Example: Freeform submodule** **Example: Freeform submodule**
:::
The following shows a submodule assigning a freeform type that allows The following shows a submodule assigning a freeform type that allows
arbitrary attributes with `str` values below `settings`, but also arbitrary attributes with `str` values below `settings`, but also
declares an option for the `settings.port` attribute to have it 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."; description = lib.mdDoc "Whether to enable magic.";
} }
``` ```
:::
### `mkPackageOption`, `mkPackageOptionMD` {#sec-option-declarations-util-mkPackageOption} ### `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. 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: Examples:
::: {#ex-options-declarations-util-mkPackageOption-hello .example} ::: {#ex-options-declarations-util-mkPackageOption-hello .example}
@ -122,6 +123,7 @@ lib.mkOption {
description = lib.mdDoc "The hello package to use."; description = lib.mdDoc "The hello package to use.";
} }
``` ```
:::
::: {#ex-options-declarations-util-mkPackageOption-ghc .example} ::: {#ex-options-declarations-util-mkPackageOption-ghc .example}
```nix ```nix
@ -138,6 +140,7 @@ lib.mkOption {
description = lib.mdDoc "The GHC package to use."; description = lib.mdDoc "The GHC package to use.";
} }
``` ```
:::
## Extensible Option Types {#sec-option-declarations-eot} ## 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. enforces that there can only be a single display manager enabled.
::: {#ex-option-declaration-eot-service .example} ::: {#ex-option-declaration-eot-service .example}
::: {.title}
**Example: Extensible type placeholder in the service module** **Example: Extensible type placeholder in the service module**
:::
```nix ```nix
services.xserver.displayManager.enable = mkOption { services.xserver.displayManager.enable = mkOption {
description = "Display manager to use"; description = "Display manager to use";
@ -198,9 +199,7 @@ services.xserver.displayManager.enable = mkOption {
::: :::
::: {#ex-option-declaration-eot-backend-gdm .example} ::: {#ex-option-declaration-eot-backend-gdm .example}
::: {.title}
**Example: Extending `services.xserver.displayManager.enable` in the `gdm` module** **Example: Extending `services.xserver.displayManager.enable` in the `gdm` module**
:::
```nix ```nix
services.xserver.displayManager.enable = mkOption { services.xserver.displayManager.enable = mkOption {
type = with types; nullOr (enum [ "gdm" ]); type = with types; nullOr (enum [ "gdm" ]);
@ -209,9 +208,7 @@ services.xserver.displayManager.enable = mkOption {
::: :::
::: {#ex-option-declaration-eot-backend-sddm .example} ::: {#ex-option-declaration-eot-backend-sddm .example}
::: {.title}
**Example: Extending `services.xserver.displayManager.enable` in the `sddm` module** **Example: Extending `services.xserver.displayManager.enable` in the `sddm` module**
:::
```nix ```nix
services.xserver.displayManager.enable = mkOption { services.xserver.displayManager.enable = mkOption {
type = with types; nullOr (enum [ "sddm" ]); 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 However, sometimes you need to wrap an option definition or set of
option definitions in a *property* to achieve certain effects: 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 If a set of option definitions is conditional on the value of another
option, you may need to use `mkIf`. Consider, for instance: 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 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 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 be discarded. The function `mkForce` is equal to `mkOverride 50`, and
`mkDefault` is equal to `mkOverride 1000`. `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 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. 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): 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. 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 In conjunction with `mkIf`, it is sometimes useful for a module to
return multiple sets of option definitions, to be merged together as if 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. together. This type is recommended when the option type is unknown.
::: {#ex-types-anything .example} ::: {#ex-types-anything .example}
::: {.title}
**Example: `types.anything` Example** **Example: `types.anything` Example**
:::
Two definitions of this type like Two definitions of this type like
```nix ```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. if you want to allow users to leave it undefined.
::: {#ex-submodule-direct .example} ::: {#ex-submodule-direct .example}
::: {.title}
**Example: Directly defined submodule** **Example: Directly defined submodule**
:::
```nix ```nix
options.mod = mkOption { options.mod = mkOption {
description = "submodule example"; description = "submodule example";
@ -378,9 +375,7 @@ options.mod = mkOption {
::: :::
::: {#ex-submodule-reference .example} ::: {#ex-submodule-reference .example}
::: {.title}
**Example: Submodule defined as a reference** **Example: Submodule defined as a reference**
:::
```nix ```nix
let let
modOptions = { modOptions = {
@ -408,9 +403,7 @@ multiple definitions of the submodule option set
([Example: Definition of a list of submodules](#ex-submodule-listof-definition)). ([Example: Definition of a list of submodules](#ex-submodule-listof-definition)).
::: {#ex-submodule-listof-declaration .example} ::: {#ex-submodule-listof-declaration .example}
::: {.title}
**Example: Declaration of a list of submodules** **Example: Declaration of a list of submodules**
:::
```nix ```nix
options.mod = mkOption { options.mod = mkOption {
description = "submodule example"; description = "submodule example";
@ -429,9 +422,7 @@ options.mod = mkOption {
::: :::
::: {#ex-submodule-listof-definition .example} ::: {#ex-submodule-listof-definition .example}
::: {.title}
**Example: Definition of a list of submodules** **Example: Definition of a list of submodules**
:::
```nix ```nix
config.mod = [ config.mod = [
{ foo = 1; bar = "one"; } { 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)). ([Example: Definition of attribute sets of submodules](#ex-submodule-attrsof-definition)).
::: {#ex-submodule-attrsof-declaration .example} ::: {#ex-submodule-attrsof-declaration .example}
::: {.title}
**Example: Declaration of attribute sets of submodules** **Example: Declaration of attribute sets of submodules**
:::
```nix ```nix
options.mod = mkOption { options.mod = mkOption {
description = "submodule example"; description = "submodule example";
@ -467,9 +456,7 @@ options.mod = mkOption {
::: :::
::: {#ex-submodule-attrsof-definition .example} ::: {#ex-submodule-attrsof-definition .example}
::: {.title}
**Example: Definition of attribute sets of submodules** **Example: Definition of attribute sets of submodules**
:::
```nix ```nix
config.mod.one = { foo = 1; bar = "one"; }; config.mod.one = { foo = 1; bar = "one"; };
config.mod.two = { foo = 2; bar = "two"; }; 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)). ([Example: Overriding a type check](#ex-extending-type-check-2)).
::: {#ex-extending-type-check-1 .example} ::: {#ex-extending-type-check-1 .example}
::: {.title}
**Example: Adding a type check** **Example: Adding a type check**
:::
```nix ```nix
byte = mkOption { byte = mkOption {
description = "An integer between 0 and 255."; 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} ::: {#ex-extending-type-check-2 .example}
::: {.title}
**Example: Overriding a type check** **Example: Overriding a type check**
:::
```nix ```nix
nixThings = mkOption { nixThings = mkOption {
description = "words that start with 'nix'"; 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 default Elixir keyword list
::: {#pkgs-formats-result} []{#pkgs-formats-result}
These functions all return an attribute set with these values: These functions all return an attribute set with these values:
:::
`type` `type`
@ -144,9 +143,8 @@ These functions all return an attribute set with these values:
::: :::
::: {#ex-settings-nix-representable .example} ::: {#ex-settings-nix-representable .example}
::: {.title}
**Example: Module with conventional `settings` option** **Example: Module with conventional `settings` option**
:::
The following shows a module for an example program that uses a JSON The following shows a module for an example program that uses a JSON
configuration file. It demonstrates how above values can be used, along configuration file. It demonstrates how above values can be used, along
with some other related best practices. See the comments for 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. up in the manual.
::: {#ex-settings-typed-attrs .example} ::: {#ex-settings-typed-attrs .example}
::: {.title}
**Example: Declaring a type-checked `settings` attribute** **Example: Declaring a type-checked `settings` attribute**
:::
```nix ```nix
settings = lib.mkOption { settings = lib.mkOption {
type = lib.types.submodule { 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). is shown in [Example: Structure of NixOS Modules](#ex-module-syntax).
::: {#ex-module-syntax .example} ::: {#ex-module-syntax .example}
::: {.title}
**Example: Structure of NixOS Modules** **Example: Structure of NixOS Modules**
:::
```nix ```nix
{ config, pkgs, ... }: { 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. functions system environment substitution should *not* be disabled explicitly.
::: {#locate-example .example} ::: {#locate-example .example}
::: {.title}
**Example: NixOS Module for the "locate" Service** **Example: NixOS Module for the "locate" Service**
:::
```nix ```nix
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
@ -165,9 +161,7 @@ in {
::: :::
::: {#exec-escaping-example .example} ::: {#exec-escaping-example .example}
::: {.title}
**Example: Escaping in Exec directives** **Example: Escaping in Exec directives**
:::
```nix ```nix
{ config, lib, pkgs, utils, ... }: { config, lib, pkgs, utils, ... }:

View file

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

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