Table of Contents
List of Examples
/dev/sda (MBR)/dev/sda (UEFI)/dev/sdaemacs.nix)configuration.nix~/.config/nixpkgs/config.nixmkEnableOption usagemkPackageOption usagemkPackageOption with explicit default and examplemkPackageOption with additional description textservices.xserver.displayManager.enable in the gdm moduleservices.xserver.displayManager.enable in the sddm moduletypes.anythingsettings optionsettings attributepassthru.tests to make (openssh.tests.overrideAttrs f).tests.nixos coherentThis manual describes how to install, use and extend NixOS, a Linux distribution based on the purely functional package management system Nix, that is composed using modules and packages defined in the Nixpkgs project.
Additional information regarding the Nix package manager and the Nixpkgs project can be found in respectively the Nix manual and the Nixpkgs manual.
If you encounter problems, please report them on the Discourse, the Matrix room, or on the #nixos channel on Libera.Chat. Alternatively, consider contributing to this manual. Bugs should be reported in NixOS’ GitHub issue tracker.
Commands prefixed with # have to be run as root, either requiring to login as root user or temporarily switching to it using sudo for example.
This section describes how to obtain, install, and configure NixOS for first-time use.
NixOS ISO images can be downloaded from the NixOS download page. Follow the instructions in the section called “Booting from a USB flash drive” to create a bootable USB flash drive.
If you have a very old system that can’t boot from USB, you can burn the image to an empty CD. NixOS might not work very well on such systems.
As an alternative to installing NixOS yourself, you can get a running NixOS system through several other means:
Using virtual appliances in Open Virtualization Format (OVF) that can be imported into VirtualBox. These are available from the NixOS download page.
Using AMIs for Amazon’s EC2. To find one for your region, please refer to the download page.
Using NixOps, the NixOS-based cloud deployment tool, which allows you to provision VirtualBox and EC2 NixOS instances from declarative specifications. Check out the NixOps homepage for details.
Table of Contents
To begin the installation, you have to boot your computer from the install drive.
Plug in the install drive. Then turn on or restart your computer.
Open the boot menu by pressing the appropriate key, which is usually shown on the display on early boot. Select the USB flash drive (the option usually contains the word “USB”). If you choose the incorrect drive, your computer will likely continue to boot as normal. In that case restart your computer and pick a different drive.
The key to open the boot menu is different across computer brands and even models. It can be F12, but also F1, F9, F10, Enter, Del, Esc or another function key. If you are unsure and don’t see it on the early boot screen, you can search online for your computers brand, model followed by “boot from usb”. The computer might not even have that feature, so you have to go into the BIOS/UEFI settings to change the boot order. Again, search online for details about your specific computer model.
For Apple computers with Intel processors press and hold the ⌥ (Option or Alt) key until you see the boot menu. On Apple silicon press and hold the power button.
If your computer supports both BIOS and UEFI boot, choose the UEFI option. You will likely need to disable “Secure Boot” to use the UEFI option. The exact steps vary by device manufacturer but generally “Secure Boot” will be listed under “Boot”, “Security” or “Advanced” in the BIOS/UEFI menu.
If you use a CD for the installation, the computer will probably boot from it automatically. If not, choose the option containing the word “CD” from the boot menu.
Shortly after selecting the appropriate boot drive, you should be presented with a menu with different installer options. Leave the default and wait (or press Enter to speed up).
The graphical images will start their corresponding desktop environment and the graphical installer, which can take some time. The minimal images will boot to a command line. You have to follow the instructions in the section called “Manual Installation” there.
The graphical installer is recommended for desktop users and will guide you through the installation.
In the “Welcome” screen, you can select the language of the Installer and the installed system.
Leaving the language as “American English” will make it easier to search for error messages in a search engine or to report an issue.
Next you should choose your location to have the timezone set correctly. You can actually click on the map!
The installer will use an online service to guess your location based on your public IP address.
Then you can select the keyboard layout. The default keyboard model should work well with most desktop keyboards. If you have a special keyboard or notebook, your model might be in the list. Select the language you are most comfortable typing in.
On the “Users” screen, you have to type in your display name, login name and password. You can also enable an option to automatically login to the desktop.
Then you have the option to choose a desktop environment. If you want to create a custom setup with a window manager, you can select “No desktop”.
If you don’t have a favorite desktop and don’t know which one to choose, you can stick to either GNOME or Plasma. They have a quite different design, so you should choose whichever you like better. They are both popular choices and well tested on NixOS.
You have the option to allow unfree software in the next screen.
The easiest option in the “Partitioning” screen is “Erase disk”, which will delete all data from the selected disk and install the system on it. Also select “Swap (with Hibernation)” in the dropdown below it. You have the option to encrypt the whole disk with LUKS.
At the top left you see if the Installer was booted with BIOS or UEFI. If you know your system supports UEFI and it shows “BIOS”, reboot with the correct option.
Make sure you have selected the correct disk at the top and that no valuable data is still on the disk! It will be deleted when formatting the disk.
Check the choices you made in the “Summary” and click “Install”.
The installation takes about 15 minutes. The time varies based on the selected desktop environment, internet connection speed and disk write speed.
When the install is complete, remove the USB flash drive and reboot into your new system!
NixOS can be installed on BIOS or UEFI systems. The procedure for a UEFI installation is broadly the same as for a BIOS installation. The differences are mentioned in the following steps.
The NixOS manual is available by running nixos-help in the command line
or from the application menu in the desktop environment.
To have access to the command line on the graphical images, open Terminal (GNOME) or Konsole (Plasma) from the application menu.
You are logged-in automatically as nixos. The nixos user account has
an empty password so you can use sudo without a password:
$ sudo -i
You can use loadkeys to switch to your preferred keyboard layout.
(We even provide neo2 via loadkeys de neo!)
If the text is too small to be legible, try setfont ter-v32n to
increase the font size.
To install over a serial port connect with 115200n8 (e.g.
picocom -b 115200 /dev/ttyUSB0). When the bootloader lists boot
entries, select the serial console boot entry.
The boot process should have brought up networking (check ip a). Networking is necessary for the installer, since it will
download lots of stuff (such as source tarballs or Nixpkgs channel
binaries). It’s best if you have a DHCP server on your network.
Otherwise configure networking manually using ip.
You can configure the network, Wi-Fi included, through NetworkManager.
Using the nmtui program, you can do so even in a non-graphical session.
If you prefer to configure the network manually, disable NetworkManager with
systemctl stop NetworkManager.
If you would like to continue the installation from a different machine
you can use activated SSH daemon. You need to copy your ssh key to
either /home/nixos/.ssh/authorized_keys or
/root/.ssh/authorized_keys (Tip: For installers with a modifiable
filesystem such as the sd-card installer image a key can be manually
placed by mounting the image on a different machine). Alternatively you
must set a password for either root or nixos with passwd to be
able to login.
The NixOS installer doesn’t do any partitioning or formatting, so you need to do that yourself.
The NixOS installer ships with multiple partitioning tools. The examples
below use parted, but also provides fdisk, gdisk, cfdisk, and
cgdisk.
Use the command ‘lsblk’ to find the name of your ‘disk’ device.
The recommended partition scheme differs depending if the computer uses Legacy Boot or UEFI.
Here’s an example partition scheme for UEFI, using /dev/sda as the
device.
You can safely ignore parted’s informational message about needing to
update /etc/fstab.
Create a GPT partition table.
# parted /dev/sda -- mklabel gpt
Add the root partition. This will fill the disk except for the end part, where the swap will live, and the space left in front (512MiB) which will be used by the boot partition.
# parted /dev/sda -- mkpart root ext4 512MB -8GB
Next, add a swap partition. The size required will vary according to needs, here a 8GB one is created.
# parted /dev/sda -- mkpart swap linux-swap -8GB 100%
The swap partition size rules are no different than for other Linux distributions.
Finally, the boot partition. NixOS by default uses the ESP (EFI system partition) as its /boot partition. It uses the initially reserved 512MiB at the start of the disk.
# parted /dev/sda -- mkpart ESP fat32 1MB 512MB
# parted /dev/sda -- set 3 esp on
In case you decided to not create a swap partition, replace 3 by 2. To be sure of the id number of ESP, run parted --list.
Once complete, you can follow with the section called “Formatting”.
Here’s an example partition scheme for Legacy Boot, using /dev/sda as
the device.
You can safely ignore parted’s informational message about needing to
update /etc/fstab.
Create a MBR partition table.
# parted /dev/sda -- mklabel msdos
Add the root partition. This will fill the disk except for the end part, where the swap will live.
# parted /dev/sda -- mkpart primary 1MB -8GB
Set the root partition’s boot flag to on. This allows the disk to be booted from.
# parted /dev/sda -- set 1 boot on
Finally, add a swap partition. The size required will vary according to needs, here a 8GB one is created.
# parted /dev/sda -- mkpart primary linux-swap -8GB 100%
The swap partition size rules are no different than for other Linux distributions.
Once complete, you can follow with the section called “Formatting”.
Use the following commands:
For initialising Ext4 partitions: mkfs.ext4. It is recommended
that you assign a unique symbolic label to the file system using the
option -L label, since this makes the file system configuration
independent from device changes. For example:
# mkfs.ext4 -L nixos /dev/sda1
For creating swap partitions: mkswap. Again it’s recommended to
assign a label to the swap partition: -L label. For example:
# mkswap -L swap /dev/sda2
UEFI systems
For creating boot partitions: mkfs.fat. Again it’s recommended
to assign a label to the boot partition: -n label. For
example:
# mkfs.fat -F 32 -n boot /dev/sda3
For creating LVM volumes, the LVM commands, e.g., pvcreate,
vgcreate, and lvcreate.
For creating software RAID devices, use mdadm.
Mount the target file system on which NixOS should be installed on
/mnt, e.g.
# mount /dev/disk/by-label/nixos /mnt
UEFI systems
Mount the boot file system on /mnt/boot, e.g.
# mkdir -p /mnt/boot
# mount -o umask=077 /dev/disk/by-label/boot /mnt/boot
If your machine has a limited amount of memory, you may want to
activate swap devices now (swapon device).
The installer (or rather, the build actions that it
may spawn) may need quite a bit of RAM, depending on your
configuration.
# swapon /dev/sda2
You now need to create a file /mnt/etc/nixos/configuration.nix
that specifies the intended configuration of the system. This is
because NixOS has a declarative configuration model: you create or
edit a description of the desired configuration of your system, and
then NixOS takes care of making it happen. The syntax of the NixOS
configuration file is described in Configuration Syntax,
while a list of available configuration options appears in
Appendix A. A minimal example is shown in
Example: NixOS Configuration.
This command accepts an optional --flake option, to also generate a
flake.nix file, if you want to set up a flake-based configuration.
The command nixos-generate-config can generate an initial
configuration file for you:
# nixos-generate-config --root /mnt
You should then edit /mnt/etc/nixos/configuration.nix to suit your
needs:
# nano /mnt/etc/nixos/configuration.nix
If you’re using the graphical ISO image, other editors may be
available (such as vim). If you have network access, you can also
install other editors – for instance, you can install Emacs by
running nix-env -f '<nixpkgs>' -iA emacs.
You must set the option boot.loader.grub.device to
specify on which disk the GRUB boot loader is to be installed.
Without it, NixOS cannot boot.
If there are other operating systems running on the machine before
installing NixOS, the boot.loader.grub.useOSProber
option can be set to true to automatically add them to the grub
menu.
You must select a boot-loader, either systemd-boot or GRUB. The recommended
option is systemd-boot: set the option boot.loader.systemd-boot.enable
to true. nixos-generate-config should do this automatically
for new configurations when booted in UEFI mode.
You may want to look at the options starting with
boot.loader.efi and
boot.loader.systemd-boot
as well.
If you want to use GRUB, set boot.loader.grub.device to nodev and
boot.loader.grub.efiSupport to true.
With systemd-boot, you should not need any special configuration to detect
other installed systems. With GRUB, set boot.loader.grub.useOSProber
to true, but this will only detect windows partitions, not other Linux
distributions. If you dual boot another Linux distribution, use systemd-boot
instead.
If you need to configure networking for your machine the
configuration options are described in Networking. In
particular, while wifi is supported on the installation image, it is
not enabled by default in the configuration generated by
nixos-generate-config.
Another critical option is fileSystems, specifying the file
systems that need to be mounted by NixOS. However, you typically
don’t need to set it yourself, because nixos-generate-config sets
it automatically in /mnt/etc/nixos/hardware-configuration.nix from
your currently mounted file systems. (The configuration file
hardware-configuration.nix is included from configuration.nix
and will be overwritten by future invocations of
nixos-generate-config; thus, you generally should not modify it.)
Additionally, you may want to look at Hardware configuration for
known-hardware at this
point or after installation.
Depending on your hardware configuration or type of file system, you
may need to set the option boot.initrd.kernelModules to include
the kernel modules that are necessary for mounting the root file
system, otherwise the installed system will not be able to boot. (If
this happens, boot from the installation media again, mount the
target file system on /mnt, fix /mnt/etc/nixos/configuration.nix
and rerun nixos-install.) In most cases, nixos-generate-config
will figure out the required modules.
Do the installation:
# nixos-install
This will install your system based on the configuration you
provided. If anything fails due to a configuration problem or any
other issue (such as a network outage while downloading binaries
from the NixOS binary cache), you can re-run nixos-install after
fixing your configuration.nix.
If you opted for a flake-based configuration, you will need to pass the
--flake here as well and specify the name of the configuration as used in
the flake.nix file. For the default generated flake, this is nixos.
# nixos-install --flake 'path/to/flake.nix#nixos'
As the last step, nixos-install will ask you to set the password
for the root user, e.g.
setting root password...
New password: ***
Retype new password: ***
If you have a user account declared in your configuration.nix and plan to log in using this user, set a password before rebooting, e.g. for the alice user:
# nixos-enter --root /mnt -c 'passwd alice'
For unattended installations, it is possible to use
nixos-install --no-root-passwd in order to disable the password
prompt entirely.
If everything went well:
# reboot
You should now be able to boot into the installed NixOS. The GRUB boot menu shows a list of available configurations (initially just one). Every time you change the NixOS configuration (see Changing Configuration), a new item is added to the menu. This allows you to easily roll back to a previous configuration if something goes wrong.
Use your declared user account to log in.
If you didn’t declare one, you should still be able to log in using the root user.
Some graphical display managers such as SDDM do not allow root login by default, so you might need to switch to TTY.
Refer to User Management for details on declaring user accounts.
You may also want to install some software. This will be covered in Package Management.
To summarise, Example: Commands for Installing NixOS on /dev/sda
shows a typical sequence of commands for installing NixOS on an empty hard
drive (here /dev/sda). Example: NixOS Configuration shows a
corresponding configuration Nix expression.
/dev/sda (MBR)# parted /dev/sda -- mklabel msdos
# parted /dev/sda -- mkpart primary 1MB -8GB
# parted /dev/sda -- mkpart primary linux-swap -8GB 100%
/dev/sda (UEFI)# parted /dev/sda -- mklabel gpt
# parted /dev/sda -- mkpart root ext4 512MB -8GB
# parted /dev/sda -- mkpart swap linux-swap -8GB 100%
# parted /dev/sda -- mkpart ESP fat32 1MB 512MB
# parted /dev/sda -- set 3 esp on
/dev/sdaWith a partitioned disk.
# mkfs.ext4 -L nixos /dev/sda1
# mkswap -L swap /dev/sda2
# swapon /dev/sda2
# mkfs.fat -F 32 -n boot /dev/sda3 # (for UEFI systems only)
# mount /dev/disk/by-label/nixos /mnt
# mkdir -p /mnt/boot # (for UEFI systems only)
# mount -o umask=077 /dev/disk/by-label/boot /mnt/boot # (for UEFI systems only)
# nixos-generate-config --root /mnt
# nano /mnt/etc/nixos/configuration.nix
# nixos-install
# reboot
{ config, pkgs, ... }: {
imports = [
# Include the results of the hardware scan.
./hardware-configuration.nix
];
boot.loader.grub.device = "/dev/sda"; # (for BIOS systems only)
boot.loader.systemd-boot.enable = true; # (for UEFI systems only)
# Note: setting fileSystems is generally not
# necessary, since nixos-generate-config figures them out
# automatically in hardware-configuration.nix.
#fileSystems."/".device = "/dev/disk/by-label/nixos";
# Enable the OpenSSH server.
services.sshd.enable = true;
}
The image has to be written verbatim to the USB flash drive for it to be bootable on UEFI and BIOS systems. Here are the recommended tools to do that.
Etcher is a popular and user-friendly tool. It works on Linux, Windows and macOS.
Download it from balena.io, start the program, select the downloaded NixOS ISO, then select the USB flash drive and flash it.
Etcher reports errors and usage statistics by default, which can be disabled in the settings.
An alternative is USBImager, which is very simple and does not connect to the internet. Download the version with write-only (wo) interface for your system. Start the program, select the image, select the USB flash drive and click “Write”.
Plug in the USB flash drive.
Find the corresponding device with lsblk. You can distinguish them by
their size.
Make sure all partitions on the device are properly unmounted. Replace sdX
with your device (e.g. sdb).
sudo umount /dev/sdX*
Then use the dd utility to write the image to the USB flash drive.
sudo dd bs=4M conv=fsync oflag=direct status=progress if=<path-to-image> of=/dev/sdX
Plug in the USB flash drive.
Find the corresponding device with diskutil list. You can distinguish them
by their size.
Make sure all partitions on the device are properly unmounted. Replace diskX
with your device (e.g. disk1).
diskutil unmountDisk diskX
Then use the dd utility to write the image to the USB flash drive.
sudo dd if=<path-to-image> of=/dev/rdiskX bs=4m
After dd completes, a GUI dialog “The disk
you inserted was not readable by this computer” will pop up, which can
be ignored.
Using the ‘raw’ rdiskX device instead of diskX with dd completes in
minutes instead of hours.
Eject the disk when it is finished.
diskutil eject /dev/diskX
Advanced users may wish to install NixOS using an existing PXE or iPXE setup.
These instructions assume that you have an existing PXE or iPXE infrastructure and want to add the NixOS installer as another option. To build the necessary files from your current version of nixpkgs, you can run:
nix-build -A netboot.x86_64-linux '<nixpkgs/nixos/release.nix>'
This will create a result directory containing:
bzImage – the Linux kernel
initrd – the initrd file
netboot.ipxe – an example ipxe script demonstrating the appropriate kernel command line arguments for this image
If you’re using plain PXE, configure your boot loader to use the
bzImage and initrd files and have it provide the same kernel command
line arguments found in netboot.ipxe.
If you’re using iPXE, depending on how your HTTP/FTP/etc. server is
configured you may be able to use netboot.ipxe unmodified, or you may
need to update the paths to the files to match your server’s directory
layout.
In the future we may begin making these files available as build products from hydra at which point we will update this documentation with instructions on how to obtain them either for placing on a dedicated TFTP server or to boot them directly over the internet.
In some cases, your system might already be booted into/preinstalled with another Linux distribution, and booting NixOS by attaching an installation image is quite a manual process.
This is particularly useful for (cloud) providers where you can’t boot a custom image, but get some Debian or Ubuntu installation.
In these cases, it might be easier to use kexec to “jump into NixOS” from the
running system, which only assumes bash and kexec to be installed on the
machine.
Note that kexec may not work correctly on some hardware, as devices are not fully re-initialized in the process. In practice, this however is rarely the case.
To build the necessary files from your current version of nixpkgs, you can run:
nix-build -A kexec.x86_64-linux '<nixpkgs/nixos/release.nix>'
This will create a result directory containing the following:
bzImage (the Linux kernel)
initrd (the initrd file)
kexec-boot (a shellscript invoking kexec)
These three files are meant to be copied over to the other already running Linux Distribution.
Note its symlinks pointing elsewhere, so cd in, and use
scp * root@$destination to copy it over, rather than rsync.
Once you finished copying, execute kexec-boot on the destination, and after
some seconds, the machine should be booting into an (ephemeral) NixOS
installation medium.
In case you want to describe your own system closure to kexec into, instead of
the default installer image, you can build your own configuration.nix:
{ modulesPath, ... }:
{
imports = [ (modulesPath + "/installer/netboot/netboot-minimal.nix") ];
services.openssh.enable = true;
users.users.root.openssh.authorizedKeys.keys = [ "my-ssh-pubkey" ];
}
nix-build '<nixpkgs/nixos>' \
--arg configuration ./configuration.nix
--attr config.system.build.kexecTree
Make sure your configuration.nix does still import netboot-minimal.nix (or
netboot-base.nix).
Installing NixOS into a VirtualBox guest is convenient for users who want to try NixOS without installing it on bare metal. If you want to set up a VirtualBox guest, follow these instructions:
Add a New Machine in VirtualBox with OS Type “Linux / Other Linux”
Base Memory Size: 768 MB or higher.
New Hard Disk of 10 GB or higher.
Mount the CD-ROM with the NixOS ISO (by clicking on CD/DVD-ROM)
Click on Settings / System / Processor and enable PAE/NX
Click on Settings / System / Acceleration and enable “VT-x/AMD-V” acceleration
Click on Settings / Display / Screen and select VMSVGA as Graphics Controller
Save the settings, start the virtual machine, and continue installation like normal
There are a few modifications you should make in configuration.nix. Enable booting:
{ boot.loader.grub.device = "/dev/sda"; }
Also remove the fsck that runs at startup. It will always fail to run,
stopping your boot until you press *.
{ boot.initrd.checkJournalingFS = false; }
Shared folders can be given a name and a path in the host system in the
VirtualBox settings (Machine / Settings / Shared Folders, then click on
the “Add” icon). Add the following to the
/etc/nixos/configuration.nix to auto-mount them. If you do not add
"nofail", the system will not boot properly.
{ config, pkgs, ... }:
{
fileSystems."/virtualboxshare" = {
fsType = "vboxsf";
device = "nameofthesharedfolder";
options = [
"rw"
"nofail"
];
};
}
The folder will be available directly under the root directory.
Because Nix (the package manager) & Nixpkgs (the Nix packages collection) can both be installed on any (most?) Linux distributions, they can be used to install NixOS in various creative ways. You can, for instance:
Install NixOS on another partition, from your existing Linux distribution (without the use of a USB or optical device!)
Install NixOS on the same partition (in place!), from your existing
non-NixOS Linux distribution using NIXOS_LUSTRATE.
Install NixOS on your hard drive from the Live CD of any Linux distribution.
The first steps to all these are the same:
Install the Nix package manager:
Short version:
$ curl -L https://nixos.org/nix/install | sh
$ . $HOME/.nix-profile/etc/profile.d/nix.sh # …or open a fresh shell
More details in the Nix manual
Switch to the NixOS channel:
If you’ve just installed Nix on a non-NixOS distribution, you will
be on the nixpkgs channel by default.
$ nix-channel --list
nixpkgs https://channels.nixos.org/nixpkgs-unstable
As that channel gets released without running the NixOS tests, it
will be safer to use the nixos-* channels instead:
$ nix-channel --add https://channels.nixos.org/nixos-<version> nixpkgs
Where <version> corresponds to the latest version available on channels.nixos.org.
You may want to throw in a nix-channel --update for good measure.
Install the NixOS installation tools:
You’ll need nixos-generate-config and nixos-install, but this
also makes some man pages and nixos-enter available, just in case
you want to chroot into your NixOS partition. NixOS installs these
by default, but you don’t have NixOS yet…
$ nix-env -f '<nixpkgs>' -iA nixos-install-tools
The following 5 steps are only for installing NixOS to another
partition. For installing NixOS in place using NIXOS_LUSTRATE,
skip ahead.
Prepare your target partition:
At this point it is time to prepare your target partition. Please refer to the partitioning, file-system creation, and mounting steps of Installing NixOS
If you’re about to install NixOS in place using NIXOS_LUSTRATE
there is nothing to do for this step.
Generate your NixOS configuration:
$ sudo `which nixos-generate-config` --root /mnt
You’ll probably want to edit the configuration files. Refer to the
nixos-generate-config step in Installing NixOS for more
information.
Consider setting up the NixOS bootloader to give you the ability to
boot on your existing Linux partition. For instance, if you’re
using GRUB and your existing distribution is running Ubuntu, you may
want to add something like this to your configuration.nix:
{
boot.loader.grub.extraEntries = ''
menuentry "Ubuntu" {
search --set=ubuntu --fs-uuid 3cc3e652-0c1f-4800-8451-033754f68e6e
configfile "($ubuntu)/boot/grub/grub.cfg"
}
'';
}
(You can find the appropriate UUID for your partition in
/dev/disk/by-uuid)
Create the nixbld group and user on your original distribution:
$ sudo groupadd -g 30000 nixbld
$ sudo useradd -u 30000 -g nixbld -G nixbld nixbld
Download/build/install NixOS:
Once you complete this step, you might no longer be able to boot on existing systems without the help of a rescue USB drive or similar.
On some distributions there are separate PATHS for programs intended
only for root. In order for the installation to succeed, you might
have to use PATH="$PATH:/usr/sbin:/sbin" in the following command.
$ sudo PATH="$PATH" `which nixos-install` --root /mnt
Again, please refer to the nixos-install step in
Installing NixOS for more information.
That should be it for installation to another partition!
Optionally, you may want to clean up your non-NixOS distribution:
$ sudo userdel nixbld
$ sudo groupdel nixbld
If you do not wish to keep the Nix package manager installed either,
run something like sudo rm -rv ~/.nix-* /nix and remove the line
that the Nix installer added to your ~/.profile.
The following steps are only for installing NixOS in place using
NIXOS_LUSTRATE:
Generate your NixOS configuration:
$ sudo `which nixos-generate-config`
Note that this will place the generated configuration files in
/etc/nixos. You’ll probably want to edit the configuration files.
Refer to the nixos-generate-config step in
Installing NixOS for more information.
On UEFI systems, check that your /etc/nixos/hardware-configuration.nix did the right thing with the EFI System Partition.
In NixOS, by default, both systemd-boot and grub expect it to be mounted on /boot.
However, the configuration generator bases its fileSystems configuration on the current mount points at the time it is run.
If the current system and NixOS’s bootloader configuration don’t agree on where the EFI System Partition is to be mounted, you’ll need to manually alter the mount point in hardware-configuration.nix before building the system closure.
The lustrate process will not work if the boot.initrd.systemd.enable option is set to true.
If you want to use this option, wait until after the first boot into the NixOS system to enable it and rebuild.
You’ll likely want to set a root password for your first boot using
the configuration files because you won’t have a chance to enter a
password until after you reboot. You can initialize the root password
to an empty one with this line: (and of course don’t forget to set
one once you’ve rebooted or to lock the account with
sudo passwd -l root if you use sudo)
{ users.users.root.initialHashedPassword = ""; }
Build the NixOS closure and install it in the system profile:
$ nix-env -p /nix/var/nix/profiles/system -f '<nixpkgs/nixos>' -I nixos-config=/etc/nixos/configuration.nix -iA system
Change ownership of the /nix tree to root (since your Nix install
was probably single user):
$ sudo chown -R 0:0 /nix
Set up the /etc/NIXOS and /etc/NIXOS_LUSTRATE files:
/etc/NIXOS officializes that this is now a NixOS partition (the
bootup scripts require its presence).
/etc/NIXOS_LUSTRATE tells the NixOS bootup scripts to move
everything that’s in the root partition to /old-root. This will
move your existing distribution out of the way in the very early
stages of the NixOS bootup. There are exceptions (we do need to keep
NixOS there after all), so the NixOS lustrate process will not
touch:
The /nix directory
The /boot directory
Any file or directory listed in /etc/NIXOS_LUSTRATE (one per
line)
The act of “lustrating” refers to the wiping of the existing distribution.
Creating /etc/NIXOS_LUSTRATE can also be used on NixOS to remove
all mutable files from your root partition (anything that’s not in
/nix or /boot gets “lustrated” on the next boot.
lustrate /ˈlʌstreɪt/ verb.
purify by expiatory sacrifice, ceremonial washing, or some other ritual action.
Let’s create the files:
$ sudo touch /etc/NIXOS
$ sudo touch /etc/NIXOS_LUSTRATE
Let’s also make sure the NixOS configuration files are kept once we reboot on NixOS:
$ echo etc/nixos | sudo tee -a /etc/NIXOS_LUSTRATE
Finally, install NixOS’s boot system, backing up the current boot system’s files in the process.
The details of this step can vary depending on the bootloader configuration in NixOS and the bootloader in use by the current system.
The commands below should work for:
BIOS systems.
UEFI systems where both the current system and NixOS mount the EFI System Partition on /boot.
Both systemd-boot and grub expect this by default in NixOS, but other distributions vary.
Once you complete this step, your current distribution will no longer be bootable! If you didn’t get all the NixOS configuration right, especially those settings pertaining to boot loading and root partition, NixOS may not be bootable either. Have a USB rescue device ready in case this happens.
On UEFI systems, anything on the EFI System Partition will be removed by these commands, such as other coexisting OS’s bootloaders.
$ sudo mkdir /boot.bak && sudo mv /boot/* /boot.bak &&
sudo NIXOS_INSTALL_BOOTLOADER=1 /nix/var/nix/profiles/system/bin/switch-to-configuration boot
Cross your fingers, reboot, hopefully you should get a NixOS prompt!
In other cases, most commonly where the EFI System Partition of the current system is instead mounted on /boot/efi, the goal is to:
Make sure /boot (and the EFI System Partition, if mounted elsewhere) are mounted how the NixOS configuration would mount them.
Clear them of files related to the current system, backing them up outside of /boot.
NixOS will move the backups into /old-root along with everything else when it first boots.
Instruct the NixOS closure built earlier to install its bootloader with:
sudo NIXOS_INSTALL_BOOTLOADER=1 /nix/var/nix/profiles/system/bin/switch-to-configuration boot
If for some reason you want to revert to the old distribution, you’ll need to boot on a USB rescue disk and do something along these lines:
# mkdir root
# mount /dev/sdaX root
# mkdir root/nixos-root
# mv -v root/* root/nixos-root/
# mv -v root/nixos-root/old-root/* root/
# mv -v root/boot.bak root/boot # We had renamed this by hand earlier
# umount root
# reboot
This may work as is or you might also need to reinstall the boot loader.
And of course, if you’re happy with NixOS and no longer need the old distribution:
sudo rm -rf /old-root
It’s also worth noting that this whole process can be automated. This is especially useful for Cloud VMs, where provider do not provide NixOS. For instance, nixos-infect uses the lustrate process to convert Digital Ocean droplets to NixOS from other distributions automatically.
To install NixOS behind a proxy, do the following before running
nixos-install.
Update proxy configuration in /mnt/etc/nixos/configuration.nix to
keep the internet accessible after reboot.
{
networking.proxy.default = "http://user:password@proxy:port/";
networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
}
Setup the proxy environment variables in the shell where you are
running nixos-install.
# proxy_url="http://user:password@proxy:port/"
# export http_proxy="$proxy_url"
# export HTTP_PROXY="$proxy_url"
# export https_proxy="$proxy_url"
# export HTTPS_PROXY="$proxy_url"
If you are switching networks with different proxy configurations, use
the specialisation option in configuration.nix to switch proxies at
runtime. Refer to Appendix A for more information.
The file /etc/nixos/configuration.nix contains the current
configuration of your machine. Whenever you’ve changed
something in that file, you should do
# nixos-rebuild switch
to build the new configuration, make it the default configuration for booting, and try to realise the configuration in the running system (e.g., by restarting system services).
This command doesn’t start/stop user services
automatically. nixos-rebuild only runs a daemon-reload for each user with running
user services.
These commands must be executed as root, so you should either run them
from a root shell or by prefixing them with sudo -i.
You can also do
# nixos-rebuild test
to build the configuration and switch the running system to it, but without making it the boot default. So if (say) the configuration locks up your machine, you can just reboot to get back to a working configuration.
There is also
# nixos-rebuild boot
to build the configuration and make it the boot default, but not switch to it now (so it will only take effect after the next reboot).
You can make your configuration show up in a different submenu of the GRUB 2 boot screen by giving it a different profile name, e.g.
# nixos-rebuild switch -p test
which causes the new configuration (and previous ones created using
-p test) to show up in the GRUB submenu “NixOS - Profile ‘test’”.
This can be useful to separate test configurations from “stable”
configurations.
A repl, or read-eval-print loop, is also available. You can inspect your configuration and use the Nix language with
# nixos-rebuild repl
Your configuration is loaded into the config variable. Use tab for autocompletion, use the :r command to reload the configuration files. See :? or nix repl in the Nix manual to learn more.
Finally, you can do
$ nixos-rebuild build
to build the configuration but nothing more. This is useful to see whether everything compiles cleanly.
If you have a machine that supports hardware virtualisation, you can also test the new configuration in a sandbox by building and running a QEMU virtual machine that contains the desired configuration. Just do
$ nixos-rebuild build-vm
$ ./result/bin/run-*-vm
The VM does not have any data from your host system, so your existing
user accounts and home directories will not be available unless you have
set mutableUsers = false. Another way is to temporarily add the
following to your configuration:
{ users.users.your-user.initialHashedPassword = "test"; }
Important: delete the $hostname.qcow2 file if you have started the virtual machine at least once without the right users, otherwise the changes will not get picked up. You can forward ports on the host to the guest. For instance, the following will forward host port 2222 to guest port 22 (SSH):
$ QEMU_NET_OPTS="hostfwd=tcp:127.0.0.1:2222-:22" ./result/bin/run-*-vm
allowing you to log in via SSH (assuming you have set the appropriate passwords or SSH authorized keys):
$ ssh -p 2222 localhost
Such port forwardings connect via the VM’s virtual network interface.
Thus they cannot connect to ports that are only bound to the VM’s
loopback interface (127.0.0.1), and the VM’s NixOS firewall
must be configured to allow these connections.
Table of Contents
The best way to keep your NixOS installation up to date is to use one of
the NixOS channels. A channel is a Nix mechanism for distributing Nix
expressions and associated binaries. The NixOS channels are updated
automatically from NixOS’s Git repository after certain tests have
passed and a selection of packages has been built successfully
(see nixos/release-combined.nix and nixos/release-small.nix).
These channels are:
Stable channels, such as nixos-25.11.
These only get conservative bug fixes and package upgrades. For
instance, a channel update may cause the Linux kernel on your system
to be upgraded from 4.19.34 to 4.19.38 (a minor bug fix), but not
from 4.19.x to 4.20.x (a major change that has the potential to break things).
Stable channels are generally maintained until the next stable
branch is created.
The unstable channel, nixos-unstable.
This corresponds to NixOS’s main development branch, and may thus see
radical changes between channel updates. It’s not recommended for
production systems.
Small channels, such as nixos-25.11-small
or nixos-unstable-small.
These are identical to the stable and unstable channels described above,
except that they contain fewer binary packages. This means they get updated
faster than the regular channels (for instance, when a critical security patch
is committed to NixOS’s source tree), but may require more packages to be
built from source than usual. They’re mostly intended for server environments
and as such contain few GUI applications.
To see what channels are available, go to https://channels.nixos.org. (Note that the URIs of the various channels redirect to a directory that contains the channel’s latest version and includes ISO images and VirtualBox appliances.) Please note that during the release process, channels that are not yet released will be present here as well. See the Getting NixOS page https://nixos.org/download/ to find the newest supported stable release.
When you first install NixOS, you’re automatically subscribed to the
NixOS channel that corresponds to your installation source. For
instance, if you installed from a 25.11 ISO, you will be subscribed to
the nixos-25.11 channel. To see which NixOS channel you’re subscribed
to, run the following as root:
# nix-channel --list | grep nixos
nixos https://channels.nixos.org/nixos-unstable
To switch to a different NixOS channel, do
# nix-channel --add https://channels.nixos.org/channel-name nixos
(Be sure to include the nixos parameter at the end.) For instance, to
use the NixOS 25.05 stable channel:
# nix-channel --add https://channels.nixos.org/nixos-25.11 nixos
If you have a server, you may want to use the “small” channel instead:
# nix-channel --add https://channels.nixos.org/nixos-25.11-small nixos
And if you want to live on the bleeding edge:
# nix-channel --add https://channels.nixos.org/nixos-unstable nixos
You can then upgrade NixOS to the latest version in your chosen channel by running
# nixos-rebuild switch --upgrade
which is equivalent to the more verbose nix-channel --update nixos; nixos-rebuild switch.
Channels are set per user. This means that running nix-channel --add
as a non root user (or without sudo) will not affect
configuration in /etc/nixos/configuration.nix
It is generally safe to switch back and forth between channels. The only exception is that a newer NixOS may also have a newer Nix version, which may involve an upgrade of Nix’s database schema. This cannot be undone easily, so in that case you will not be able to go back to your original channel.
You can keep a NixOS system up-to-date automatically by adding the
following to configuration.nix:
{
system.autoUpgrade.enable = true;
system.autoUpgrade.allowReboot = true;
}
This enables a periodically executed systemd service named
nixos-upgrade.service. If the allowReboot option is false, it runs
nixos-rebuild switch --upgrade to upgrade NixOS to the latest version
in the current channel. (To see when the service runs, see systemctl list-timers.)
If allowReboot is true, then the system will automatically reboot if
the new generation contains a different kernel, initrd or kernel
modules. You can also specify a channel explicitly, e.g.
{ system.autoUpgrade.channel = "https://channels.nixos.org/nixos-25.11"; }
Table of Contents
Default live installer configurations are available inside nixos/modules/installer/cd-dvd.
For building other system images, see Building Images with nixos-rebuild build-image.
You have two options:
Use any of those default configurations as is
Combine them with (any of) your host config(s)
System images, such as the live installer ones, know how to enforce configuration settings on which they immediately depend in order to work correctly.
However, if you are confident, you can opt to override those
enforced values with mkForce.
To build an ISO image for the channel nixos-unstable:
$ git clone https://github.com/NixOS/nixpkgs.git
$ cd nixpkgs/nixos
$ git switch nixos-unstable
$ nix-build -A config.system.build.isoImage -I nixos-config=modules/installer/cd-dvd/installation-cd-minimal.nix default.nix
To check the content of an ISO image, mount it like so:
# mount -o loop -t iso9660 ./result/iso/nixos-image-25.05pre-git-x86_64-linux.iso /mnt/iso
If you need additional (non-distributable) drivers or firmware in the installer, you might want to extend these configurations.
For example, to build the GNOME graphical installer ISO, but with support for
certain WiFi adapters present in some MacBooks, you can create the following
file at modules/installer/cd-dvd/installation-cd-graphical-gnome-macbook.nix:
{ config, ... }:
{
imports = [ ./installation-cd-graphical-gnome.nix ];
boot.initrd.kernelModules = [ "wl" ];
boot.kernelModules = [
"kvm-intel"
"wl"
];
boot.extraModulePackages = [ config.boot.kernelPackages.broadcom_sta ];
}
Then build it like in the example above:
$ git clone https://github.com/NixOS/nixpkgs.git
$ cd nixpkgs/nixos
$ export NIXPKGS_ALLOW_UNFREE=1
$ nix-build -A config.system.build.isoImage -I nixos-config=modules/installer/cd-dvd/installation-cd-graphical-gnome-macbook.nix default.nix
The config value enforcement is implemented via mkImageMediaOverride = mkOverride 60;
and therefore primes over simple value assignments, but also yields to mkForce.
This property allows image designers to implement in semantically correct ways those configuration values upon which the correct functioning of the image depends.
For example, the iso base image overrides those file systems which it needs at a minimum for correct functioning, while the installer base image overrides the entire file system layout because there can’t be any other guarantees on a live medium than those given by the live medium itself. The latter is especially true before formatting the target block device(s). On the other hand, the netboot iso only overrides its minimum dependencies since netboot images are always made-to-target.
nixos-rebuild build-image Nixpkgs contains a variety of modules to build custom images for different virtualization platforms and cloud providers, such as e.g. amazon-image.nix and proxmox-lxc.nix.
While those can be imported directly, system.build.images provides an attribute set mapping variant names to image derivations. Available variants are defined - end extendable - in image.modules, an attribute set mapping variant names to NixOS modules.
All of those images can be built via both, their system.build.image attribute and the nixos-rebuild build-image command.
For example, to build an Amazon image from your existing NixOS configuration, run:
$ nixos-rebuild build-image --image-variant amazon
[...]
Done. The disk image can be found in /nix/store/[hash]-nixos-image-amazon-25.05pre-git-x86_64-linux/nixos-image-amazon-25.05pre-git-x86_64-linux.vpc
To get a list of all variants available, run nixos-rebuild build-image without arguments.
The image.modules option can be used to set specific options per image variant, in a similar fashion as specialisations for generic NixOS configurations.
E.g. images for the cloud provider Linode use grub2 as a bootloader by default. If you are using systemd-boot on other platforms and want to disable it for Linode only, you could use the following options:
{
image.modules.linode = {
boot.loader.systemd-boot.enable = lib.mkForce false;
};
}
systemd-repart Table of Contents
You can build disk images in NixOS with the image.repart option provided by
the module image/repart.nix. This module uses systemd-repart to build the
images and exposes it’s entire interface via the repartConfig option.
An example of how to build an image:
{ config, modulesPath, ... }:
{
imports = [ "${modulesPath}/image/repart.nix" ];
image.repart = {
name = "image";
partitions = {
"esp" = {
contents = {
# ...
};
repartConfig = {
Type = "esp";
# ...
};
};
"root" = {
storePaths = [ config.system.build.toplevel ];
repartConfig = {
Type = "root";
Label = "nixos";
# ...
};
};
};
};
}
If you want to rewrite Nix store paths, e.g., to remove the /nix/store prefix
or to nest it below a parent path, you can do that through the
nixStorePrefix option.
You can define a partition that only contains the Nix store and then mount it
under /nix/store. Because the /nix/store part of the paths is already
determined by the mount point, you have to set nixStorePrefix = "/" so
that /nix/store is stripped from the paths before copying them into the image.
{
fileSystems."/nix/store".device = "/dev/disk/by-partlabel/nix-store";
image.repart.partitions = {
"store" = {
storePaths = [ config.system.build.toplevel ];
nixStorePrefix = "/";
repartConfig = {
Type = "linux-generic";
Label = "nix-store";
# ...
};
};
};
}
Alternatively, you can create a Btrfs subvolume /@nix-store containing the
Nix store and mount it on /nix/store:
{
fileSystems."/" = {
device = "/dev/disk/by-partlabel/root";
fsType = "btrfs";
options = [ "subvol=/@" ];
};
fileSystems."/nix/store" = {
device = "/dev/disk/by-partlabel/root";
fsType = "btrfs";
options = [ "subvol=/@nix-store" ];
};
image.repart.partitions = {
"root" = {
storePaths = [ config.system.build.toplevel ];
nixStorePrefix = "/@nix-store";
repartConfig = {
Type = "root";
Label = "root";
Format = "btrfs";
Subvolumes = "/@ /@nix-store";
MakeDirectories = "/@ /@nix-store";
# ...
};
};
};
}
The image/repart.nix module can also be used to build self-contained software
appliances.
The generation based update mechanism of NixOS is not suited for appliances.
Updates of appliances are usually either performed by replacing the entire
image with a new one or by updating partitions via an A/B scheme. See the
Chrome OS update process for an example of how to achieve
this. The appliance image built in the following example does not contain a
configuration.nix and thus you will not be able to call nixos-rebuild from
this system. Furthermore, it uses a Unified Kernel Image.
let
pkgs = import <nixpkgs> { };
efiArch = pkgs.stdenv.hostPlatform.efiArch;
in
(pkgs.nixos [
(
{
config,
lib,
pkgs,
modulesPath,
...
}:
{
imports = [ "${modulesPath}/image/repart.nix" ];
boot.loader.grub.enable = false;
fileSystems."/".device = "/dev/disk/by-label/nixos";
image.repart = {
name = "image";
partitions = {
"esp" = {
contents = {
"/EFI/BOOT/BOOT${lib.toUpper efiArch}.EFI".source =
"${pkgs.systemd}/lib/systemd/boot/efi/systemd-boot${efiArch}.efi";
"/EFI/Linux/${config.system.boot.loader.ukiFile}".source =
"${config.system.build.uki}/${config.system.boot.loader.ukiFile}";
};
repartConfig = {
Type = "esp";
Format = "vfat";
SizeMinBytes = "96M";
};
};
"root" = {
storePaths = [ config.system.build.toplevel ];
repartConfig = {
Type = "root";
Format = "ext4";
Label = "nixos";
Minimize = "guess";
};
};
};
};
}
)
]).image
This chapter describes how to configure various aspects of a NixOS machine through the configuration file /etc/nixos/configuration.nix. As described in Changing the Configuration, changes to this file only take effect after you run nixos-rebuild.
Table of Contents
Table of Contents
The NixOS configuration file /etc/nixos/configuration.nix is actually
a Nix expression, which is the Nix package manager’s 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 Nix
manual, but
here we give a short overview of the most important constructs useful in
NixOS configuration files.
The NixOS configuration file generally looks like this:
{ config, pkgs, ... }:
{
# option definitions
}
The first line ({ config, pkgs, ... }:) denotes that this is actually
a function that takes at least the two arguments config and pkgs.
(These are explained later, in chapter Writing NixOS Modules) The
function returns a set of option definitions ({ ... }).
These definitions have the form name = value, where name is the
name of an option and value is its value. For example,
{ config, pkgs, ... }:
{
services.httpd.enable = true;
services.httpd.adminAddr = "[email protected]";
services.httpd.virtualHosts.localhost.documentRoot = "/webroot";
}
defines a configuration with three option definitions that together
enable the Apache HTTP Server with /webroot as the document root.
Sets can be nested, and in fact dots in option names are shorthand for
defining a set containing another set. For instance,
services.httpd.enable defines a set named
services that contains a set named httpd, which in turn contains an
option definition named enable with value true. This means that the
example above can also be written as:
{ config, pkgs, ... }:
{
services = {
httpd = {
enable = true;
adminAddr = "[email protected]";
virtualHosts = {
localhost = {
documentRoot = "/webroot";
};
};
};
};
}
which may be more convenient if you have lots of option definitions that
share the same prefix (such as services.httpd).
NixOS checks your option definitions for correctness. For instance, if
you try to define an option that doesn’t exist (that is, doesn’t have a
corresponding option declaration), nixos-rebuild will give an error
like:
The option `services.httpd.enable' defined in `/etc/nixos/configuration.nix' does not exist.
Likewise, values in option definitions must have a correct type. For
instance, services.httpd.enable must be a Boolean (true or false).
Trying to give it a value of another type, such as a string, will cause
an error:
The option value `services.httpd.enable' in `/etc/nixos/configuration.nix' is not a boolean.
Options have various types of values. The most important are:
Strings are enclosed in double quotes, e.g.
{
networking.hostName = "dexter";
}
Special characters can be escaped by prefixing them with a backslash
(e.g. \").
Multi-line strings can be enclosed in double single quotes, e.g.
{
networking.extraHosts =
''
127.0.0.2 other-localhost
10.0.0.1 server
'';
}
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 " and \ are not special (making it more convenient for
including things like shell code). See more info about this in the
Nix manual here.
These can be true or false, e.g.
{
networking.firewall.enable = true;
networking.firewall.allowPing = false;
}
For example,
{
boot.kernel.sysctl."net.ipv4.tcp_keepalive_time" = 60;
}
(Note that here the attribute name net.ipv4.tcp_keepalive_time is
enclosed in quotes to prevent it from being interpreted as a set
named net containing a set named ipv4, and so on. This is
because it’s not a NixOS option but the literal name of a Linux
kernel setting.)
Sets were introduced above. They are name/value pairs enclosed in braces, as in the option definition
{
fileSystems."/boot" =
{ device = "/dev/sda1";
fsType = "ext4";
options = [ "rw" "data=ordered" "relatime" ];
};
}
The important thing to note about lists is that list elements are separated by whitespace, like this:
{
boot.kernelModules = [ "fuse" "kvm-intel" "coretemp" ];
}
List elements can be any other type, e.g. sets:
{
swapDevices = [ { device = "/dev/disk/by-label/swap"; } ];
}
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 pkgs. Typical uses:
{
environment.systemPackages =
[ pkgs.thunderbird
pkgs.emacs
];
services.postgresql.package = pkgs.postgresql_14;
}
The latter option definition changes the default PostgreSQL package used by NixOS’s PostgreSQL service to 14.x. For more information on packages, including how to add new ones, see the section called “Adding Custom Packages”.
If you find yourself repeating yourself over and over, it’s time to abstract. Take, for instance, this Apache HTTP Server configuration:
{
services.httpd.virtualHosts = {
"blog.example.org" = {
documentRoot = "/webroot/blog.example.org";
adminAddr = "[email protected]";
forceSSL = true;
enableACME = true;
};
"wiki.example.org" = {
documentRoot = "/webroot/wiki.example.org";
adminAddr = "[email protected]";
forceSSL = true;
enableACME = true;
};
};
}
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 let:
let
commonConfig = {
adminAddr = "[email protected]";
forceSSL = true;
enableACME = true;
};
in
{
services.httpd.virtualHosts = {
"blog.example.org" = (commonConfig // { documentRoot = "/webroot/blog.example.org"; });
"wiki.example.org" = (commonConfig // { documentRoot = "/webroot/wiki.example.org"; });
};
}
The let commonConfig = ... defines a variable named commonConfig. The // operator merges two attribute sets, so the configuration of the second virtual host is the set commonConfig extended with the document root option.
You can write a let wherever an expression is allowed. Thus, you also could have written:
{
services.httpd.virtualHosts =
let
commonConfig = {
# ...
};
in
{
"blog.example.org" = (
commonConfig
// {
# ...
}
);
"wiki.example.org" = (
commonConfig
// {
# ...
}
);
};
}
but not { let commonConfig = ...; in ...; } since attributes (as opposed to attribute values) are not expressions.
Functions 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:
{
services.httpd.virtualHosts =
let
makeVirtualHost = webroot: {
documentRoot = webroot;
adminAddr = "[email protected]";
forceSSL = true;
enableACME = true;
};
in
{
"example.org" = (makeVirtualHost "/webroot/example.org");
"example.com" = (makeVirtualHost "/webroot/example.com");
"example.gov" = (makeVirtualHost "/webroot/example.gov");
"example.nl" = (makeVirtualHost "/webroot/example.nl");
};
}
Here, makeVirtualHost is a function that takes a single argument webroot and returns the configuration for a virtual host. That function is then called for several names to produce the list of virtual host configurations.
The NixOS configuration mechanism is modular. If your
configuration.nix 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.
Modules have exactly the same syntax as configuration.nix. In fact,
configuration.nix is itself a module. You can use other modules by
including them from configuration.nix, e.g.:
{ config, pkgs, ... }:
{
imports = [
./vpn.nix
./kde.nix
];
services.httpd.enable = true;
environment.systemPackages = [ pkgs.emacs ];
# ...
}
Here, we include two modules from the same directory, vpn.nix and
kde.nix. The latter might look like this:
{ config, pkgs, ... }:
{
services.xserver.enable = true;
services.displayManager.sddm.enable = true;
services.desktopManager.plasma6.enable = true;
environment.systemPackages = [ pkgs.vim ];
}
Note that both configuration.nix and kde.nix define the option
environment.systemPackages. When multiple modules define an
option, NixOS will try to merge the definitions. In the case of
environment.systemPackages the lists of packages will be
concatenated. The value in configuration.nix 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 mkBefore:
{ boot.kernelModules = mkBefore [ "kvm-intel" ]; }
This causes the kvm-intel kernel module to be loaded before any other
kernel modules.
For other types of options, a merge may not be possible. For instance,
if two modules define services.httpd.adminAddr,
nixos-rebuild will give an error:
The unique option `services.httpd.adminAddr' is defined multiple times, in `/etc/nixos/httpd.nix' and `/etc/nixos/configuration.nix'.
When that happens, it’s possible to force one definition take precedence over the others:
{ services.httpd.adminAddr = pkgs.lib.mkForce "[email protected]"; }
When using multiple modules, you may need to access configuration values
defined in other modules. This is what the config function argument is
for: it contains the complete, merged system configuration. That is,
config is the result of combining the configurations returned by every
module. (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
environment.systemPackages only if
services.xserver.enable is set to true somewhere else:
{ config, pkgs, ... }:
{
environment.systemPackages =
if config.services.xserver.enable then
[
pkgs.firefox
pkgs.thunderbird
]
else
[ ];
}
With multiple modules, it may not be obvious what the final value of a
configuration option is. The command nixos-option allows you to find
out:
$ nixos-option services.xserver.enable
true
$ nixos-option boot.kernelModules
[ "tun" "ipv6" "loop" ... ]
Interactive exploration of the configuration is possible using nix repl, a read-eval-print loop for Nix expressions. A typical use:
$ nix repl '<nixpkgs/nixos>'
nix-repl> config.networking.hostName
"mandark"
nix-repl> map (x: x.hostName) config.services.httpd.virtualHosts
[ "example.org" "example.gov" ]
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.
{ config, pkgs, ... }:
let
netConfig = hostName: {
networking.hostName = hostName;
networking.useDHCP = false;
};
in
{
imports = [ (netConfig "nixos.localdomain") ];
}
Table of Contents
This section describes how to add additional packages to your system. NixOS has two distinct styles of package management:
Declarative, where you declare what packages you want in your
configuration.nix. Every time you run nixos-rebuild, NixOS will
ensure that you get a consistent set of binaries corresponding to
your specification.
Ad hoc, where you install, upgrade and uninstall packages via the
nix-env command. This style allows mixing packages from different
Nixpkgs versions. It’s the only choice for non-root users.
With declarative package management, you specify which packages you want
on your system by setting the option
environment.systemPackages. For instance, adding the
following line to configuration.nix enables the Mozilla Thunderbird
email application:
{ environment.systemPackages = [ pkgs.thunderbird ]; }
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
nixos-rebuild switch.
Some packages require additional global configuration such as D-Bus or
systemd service registration so adding them to
environment.systemPackages might not be sufficient. You are
advised to check the list of options whether a NixOS
module for the package does not exist.
You can get a list of the available packages as follows:
$ nix-env -qaP '*' --description
nixos.firefox firefox-23.0 Mozilla Firefox - the browser, reloaded
...
The first column in the output is the attribute name, such as
nixos.thunderbird.
Note: the nixos prefix tells us that we want to get the package from
the nixos channel and works only in CLI tools. In declarative
configuration, use pkgs prefix (variable).
To “uninstall” a package, remove it from
environment.systemPackages and run nixos-rebuild switch.
The Nixpkgs configuration for a NixOS system is set by the nixpkgs.config option.
{
nixpkgs.config = {
allowUnfree = true;
};
}
This only allows unfree software in the given NixOS configuration.
For users invoking Nix commands such as nix-build, Nixpkgs is configured independently.
See the Nixpkgs manual section on global configuration for details.
Some packages in Nixpkgs have options to enable or disable optional functionality, or change other aspects of the package.
Unfortunately, Nixpkgs currently lacks a way to query available package configuration options.
For example, many packages come with extensions one might add. Examples include:
You can use them like this:
{
environment.systemPackages = with pkgs; [
sl
(pass.withExtensions (
subpkgs: with subpkgs; [
pass-audit
pass-otp
pass-genphrase
]
))
(python3.withPackages (subpkgs: with subpkgs; [ requests ]))
cowsay
];
}
Apart from high-level options, it’s 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:
{ environment.systemPackages = [ (pkgs.emacs.override { gtk = pkgs.gtk3; }) ]; }
The function override 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 gtk gets the
value pkgs.gtk3, 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,
environment.systemPackages
would be a list with two elements.)
Even greater customisation is possible using the function
overrideAttrs. While the override mechanism above overrides the
arguments of a package function, overrideAttrs allows changing the
attributes passed to mkDerivation. 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:
{
environment.systemPackages = [
(pkgs.emacs.overrideAttrs (oldAttrs: {
name = "emacs-25.0-pre";
src = /path/to/my/emacs/tree;
}))
];
}
Here, overrideAttrs takes the Nix derivation specified by pkgs.emacs
and produces a new derivation in which the original’s name and src
attribute have been replaced by the given values by re-calling
stdenv.mkDerivation. The original attributes are accessible via the
function argument, which is conventionally named oldAttrs.
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 global override as follows:
{
nixpkgs.config.packageOverrides = pkgs: {
emacs = pkgs.emacs.override { gtk = pkgs.gtk3; };
};
}
The effect of this definition is essentially equivalent to modifying the
emacs attribute in the Nixpkgs source tree. Any package in Nixpkgs
that depends on emacs will be passed your customised instance.
(However, the value pkgs.emacs in nixpkgs.config.packageOverrides
refers to the original rather than overridden instance, to prevent an
infinite recursion.)
It’s 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.
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 Nixpkgs manual. In short, you clone Nixpkgs:
$ git clone https://github.com/NixOS/nixpkgs
$ cd nixpkgs
Then you write and test the package as described in the Nixpkgs manual.
Finally, you add it to environment.systemPackages, e.g.
{ environment.systemPackages = [ pkgs.my-package ]; }
and you run nixos-rebuild, specifying your own Nixpkgs tree:
# nixos-rebuild switch -I nixpkgs=/path/to/my/nixpkgs
The second possibility is to add the package outside of the Nixpkgs
tree. For instance, here is how you specify a build of the
GNU Hello package directly in
configuration.nix:
{
environment.systemPackages =
let
my-hello =
with pkgs;
stdenv.mkDerivation rec {
name = "hello-2.8";
src = fetchurl {
url = "mirror://gnu/hello/${name}.tar.gz";
hash = "sha256-5rd/gffPfa761Kn1tl3myunD8TuM+66oy1O7XqVGDXM=";
};
};
in
[ my-hello ];
}
Of course, you can also move the definition of my-hello into a
separate Nix expression, e.g.
{ environment.systemPackages = [ (import ./my-hello.nix) ]; }
where my-hello.nix contains:
with import <nixpkgs> { }; # bring all of Nixpkgs into scope
stdenv.mkDerivation rec {
name = "hello-2.8";
src = fetchurl {
url = "mirror://gnu/hello/${name}.tar.gz";
hash = "sha256-5rd/gffPfa761Kn1tl3myunD8TuM+66oy1O7XqVGDXM=";
};
}
This allows testing the package easily:
$ nix-build my-hello.nix
$ ./result/bin/hello
Hello, world!
Most pre-built executables will not work on NixOS. There are two notable exceptions: flatpaks and AppImages. For flatpaks see the dedicated section. AppImages can run “as-is” on NixOS.
First you need to enable AppImage support: add to /etc/nixos/configuration.nix
{
programs.appimage.enable = true;
programs.appimage.binfmt = true;
}
Then you can run the AppImage “as-is” or with appimage-run foo.appimage.
If there are shared libraries missing add them with
{
programs.appimage.package = pkgs.appimage-run.override {
extraPkgs = pkgs: [
# missing libraries here, e.g.: `pkgs.libepoxy`
];
};
}
To make other pre-built executables work on NixOS, you need to package them
with Nix and special helpers like autoPatchelfHook or buildFHSEnv. See
the Nixpkgs manual for details. This
is complex and often doing a source build is easier.
With the command nix-env, you can install and uninstall packages from
the command line. For instance, to install Mozilla Thunderbird:
$ nix-env -iA nixos.thunderbird
If you invoke this as root, the package is installed in the Nix profile
/nix/var/nix/profiles/default and visible to all users of the system;
otherwise, the package ends up in
/nix/var/nix/profiles/per-user/username/profile and is not visible to
other users. The -A flag specifies the package by its attribute name;
without it, the package is installed by matching against its package
name (e.g. thunderbird). The latter is slower because it requires
matching against all available Nix packages, and is ambiguous if there
are multiple matching packages.
Packages come from the NixOS channel. You typically upgrade a package by updating to the latest version of the NixOS channel:
$ nix-channel --update nixos
and then running nix-env -i again. Other packages in the profile are
not affected; this is the crucial difference with the declarative
style of package management, where running nixos-rebuild switch 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:
$ nix-env -u '*'
A package can be uninstalled using the -e flag:
$ nix-env -e thunderbird
Finally, you can roll back an undesirable nix-env action:
$ nix-env --rollback
nix-env has many more flags. For details, see the nix-env(1) manpage or
the Nix manual.
Table of Contents
NixOS supports both declarative and imperative styles of user
management. In the declarative style, users are specified in
configuration.nix. For instance, the following states that a user
account named alice shall exist:
{
users.users.alice = {
isNormalUser = true;
home = "/home/alice";
description = "Alice Foobar";
extraGroups = [
"wheel"
"networkmanager"
];
openssh.authorizedKeys.keys = [ "ssh-dss AAAAB3Nza... alice@foobar" ];
};
}
Note that alice is a member of the wheel and networkmanager
groups, which allows her to use sudo to execute commands as root 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
passwd program to set a password, which is retained across invocations
of nixos-rebuild.
If you set users.mutableUsers to
false, then the contents of /etc/passwd and /etc/group will be congruent
to your NixOS configuration. For instance, if you remove a user from
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 user’s
hashedPassword option. A
hashed password can be generated using mkpasswd.
A user ID (uid) is assigned automatically. You can also specify a uid manually by adding
{ uid = 1000; }
to the user specification.
Groups can be specified similarly. The following states that a group
named students shall exist:
{ users.groups.students.gid = 1000; }
As with users, the group ID (gid) is optional and will be assigned automatically if it’s missing.
In the imperative style, users and groups are managed by commands such
as useradd, groupmod and so on. For instance, to create a user
account named alice:
# useradd -m alice
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:
# su - alice -c "true"
The flag -m 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
passwd utility:
# passwd alice
Enter new UNIX password: ***
Retype new UNIX password: ***
A user can be deleted using userdel:
# userdel -r alice
The flag -r deletes the user’s home directory. Accounts can be
modified using usermod. Unix groups can be managed using groupadd,
groupmod and groupdel.
systemd-sysusers This is experimental.
Please consider using Userborn over systemd-sysusers as it’s more feature complete.
Instead of using a custom perl script to create users and groups, you can use systemd-sysusers:
{ systemd.sysusers.enable = true; }
The primary benefit of this is to remove a dependency on perl.
userborn This is experimental.
Like systemd-sysusers, Userborn doesn’t depend on Perl but offers some more advantages over systemd-sysusers:
It can create “normal” users (with a GID >= 1000).
It can update some information about users. Most notably it can update their passwords.
It will warn when users use an insecure or unsupported password hashing scheme.
Userborn is the recommended way to manage users if you don’t want to rely on the Perl script. It aims to eventually replace the Perl script by default.
You can enable Userborn via:
{ services.userborn.enable = true; }
You can configure Userborn to store the password files
(/etc/{group,passwd,shadow}) outside of /etc and symlink them from this
location to /etc:
{ services.userborn.passwordFilesLocation = "/persistent/etc"; }
This is useful when you store /etc on a tmpfs or if /etc is immutable
(e.g. when using system.etc.overlay.mutable = false;). In the latter case the
original files are by default stored in /var/lib/nixos.
Userborn implements immutable users by re-mounting the password files
read-only. This means that unlike when using the Perl script, trying to add a
new user (e.g. via useradd) will fail right away.
Timekpr-nExT is a screen time managing application that helps optimizing time spent at computer for your subordinates, children or even for yourself.
You can enable it via:
{ services.timekpr.enable = true; }
This will install the timekpr package and start the timekpr service.
You can then use the timekpra application to configure time limits for users.
Table of Contents
You can define file systems using the fileSystems configuration
option. For instance, the following definition causes NixOS to mount the
Ext4 file system on device /dev/disk/by-label/data onto the mount
point /data:
{
fileSystems."/data" = {
device = "/dev/disk/by-label/data";
fsType = "ext4";
};
}
This will create an entry in /etc/fstab, which will generate a
corresponding systemd.mount
unit via systemd-fstab-generator.
The filesystem will be mounted automatically unless "noauto" is
present in options. "noauto"
filesystems can be mounted explicitly using systemctl e.g.
systemctl start data.mount. Mount points are created automatically if they don’t
already exist. For device, it’s best to use the topology-independent
device aliases in /dev/disk/by-label and /dev/disk/by-uuid, as these
don’t change if the topology changes (e.g. if a disk is moved to another
IDE controller).
You can usually omit the file system type (fsType), since mount 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 ext2, ext3 or ext4, then it’s best
to specify fsType to ensure that the kernel module is available.
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 options = [ "nofail" ];.
NixOS supports file systems that are encrypted using LUKS (Linux
Unified Key Setup). For example, here is how you create an encrypted
Ext4 file system on the device
/dev/disk/by-uuid/3f6b0024-3a44-4fde-a43a-767b872abe5d:
# 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
The LUKS volume should be automatically picked up by
nixos-generate-config, but you might want to verify that your
hardware-configuration.nix looks correct. To manually ensure that the
system is automatically mounted at boot time as /, add the following
to configuration.nix:
{
boot.initrd.luks.devices.crypted.device = "/dev/disk/by-uuid/3f6b0024-3a44-4fde-a43a-767b872abe5d";
fileSystems."/".device = "/dev/mapper/crypted";
}
Should grub be used as bootloader, and /boot is located on an
encrypted partition, it is necessary to add the following grub option:
{ boot.loader.grub.enableCryptodisk = true; }
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
/dev/sda2:
# export FIDO2_LABEL="/dev/sda2 @ $HOSTNAME"
# fido2luks credential "$FIDO2_LABEL"
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
To ensure that this file system is decrypted using the FIDO2 compatible
key, add the following to configuration.nix:
{
boot.initrd.luks.fido2Support = true;
boot.initrd.luks.devices."/dev/sda2".fido2.credential =
"f1d00200108b9d6e849a8b388da457688e3dd653b4e53770012d8f28e5d3b269865038c346802f36f3da7278b13ad6a3bb6a1452e24ebeeaa24ba40eef559b1b287d2a2f80b7";
}
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 Trezor.
{ boot.initrd.luks.devices."/dev/sda2".fido2.passwordLess = true; }
If systemd stage 1 is enabled, it handles unlocking of LUKS-encrypted volumes
during boot. The following example enables systemd stage1 and adds support for
unlocking the existing LUKS2 volume root using any enrolled FIDO2 compatible
tokens.
{
boot.initrd = {
luks.devices.root = {
crypttabExtraOpts = [ "fido2-device=auto" ];
device = "/dev/sda2";
};
systemd.enable = true;
};
}
All tokens that should be used for unlocking the LUKS2-encrypted volume must first be enrolled using systemd-cryptenroll. In the following example, a new key slot for the first discovered token is added to the LUKS volume.
# systemd-cryptenroll --fido2-device=auto /dev/sda2
Existing key slots are left intact, unless --wipe-slot= is specified. It is
recommended to add a recovery key that should be stored in a secure physical
location and can be entered wherever a password would be entered.
# systemd-cryptenroll --recovery-key /dev/sda2
SSHFS is a FUSE 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.
In NixOS, SSHFS is packaged as sshfs.
Once installed, mounting a directory interactively is simple as running:
$ sshfs [email protected]:/my-dir /mnt/my-dir
Like any other FUSE file system, the directory is unmounted using:
$ fusermount -u /mnt/my-dir
Mounting non-interactively requires some precautions because sshfs will run at boot and under a different user (root).
For obvious reason, you can’t input a password, so public key authentication using an unencrypted key is needed.
To create a new key without a passphrase you can do:
$ ssh-keygen -t ed25519 -P '' -f example-key
Generating public/private ed25519 key pair.
Your identification has been saved in example-key
Your public key has been saved in example-key.pub
The key fingerprint is:
SHA256:yjxl3UbTn31fLWeyLYTAKYJPRmzknjQZoyG8gSNEoIE my-user@workstation
To keep the key safe, change the ownership to root:root and make sure the permissions are 600:
OpenSSH normally refuses to use the key if it’s not well-protected.
The file system can be configured in NixOS via the usual fileSystems option. Here’s a typical setup:
{
fileSystems."/mnt/my-dir" = {
device = "[email protected]:/my-dir/";
fsType = "sshfs";
options = [
# Filesystem options
"allow_other" # for non-root access
"_netdev" # this is a network fs
"x-systemd.automount" # mount on demand
# SSH options
"reconnect" # handle connection drops
"ServerAliveInterval=15" # keep connections alive
"IdentityFile=/var/secrets/example-key"
];
};
}
More options from ssh_config(5) can be given as well, for example you can change the default SSH port or specify a jump proxy:
{
options = [
"[email protected]"
"Port=22"
];
}
It’s also possible to change the ssh command used by SSHFS to connect to the server.
For example:
{
options = [
(builtins.replaceStrings [ " " ] [ "\\040" ]
"ssh_command=${pkgs.openssh}/bin/ssh -v -L 8080:localhost:80"
)
];
}
The escaping of spaces is needed because every option is written to the /etc/fstab file, which is a space-separated table.
If you’re having a hard time figuring out why mounting is failing, you can add the option "debug".
This enables a verbose log in SSHFS that you can access via:
$ 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 <ssh> <-x> <-a> <-oClearAllForwardings=yes> <-oServerAliveInterval=15> <-oIdentityFile=/var/secrets/wrong-key> <-2> <[email protected]> <-s> <sftp>
Jun 22 11:41:19 workstation mount[87793]: [email protected]: 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.
If the mount point contains special characters it needs to be escaped using systemd-escape.
This is due to the way systemd converts paths into unit names.
NixOS offers a convenient abstraction to create both read-only as well writable overlays.
{
fileSystems = {
"/writable-overlay" = {
overlay = {
lowerdir = [ writableOverlayLowerdir ];
upperdir = "/.rw-writable-overlay/upper";
workdir = "/.rw-writable-overlay/work";
};
# Mount the writable overlay in the initrd.
neededForBoot = true;
};
"/readonly-overlay".overlay.lowerdir = [
writableOverlayLowerdir
writableOverlayLowerdir2
];
};
}
If upperdir and workdir are not null, they will be created before the
overlay is mounted.
To mount an overlay as read-only, you need to provide at least two lowerdirs.
Table of Contents
The X Window System (X11) provides the basis of NixOS’ graphical user interface. It can be enabled as follows:
{ services.xserver.enable = true; }
The X server will automatically detect and use the appropriate video
driver from a set of X.org drivers (such as vesa and intel). You can
also specify a driver manually, e.g.
{ services.xserver.videoDrivers = [ "r128" ]; }
to enable X.org’s xf86-video-r128 driver.
You also need to enable at least one desktop or window manager.
Otherwise, you can only log into a plain undecorated xterm window.
Thus you should pick one or more of the following lines:
{
services.desktopManager.plasma6.enable = true;
services.xserver.desktopManager.xfce.enable = true;
services.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;
}
NixOS’s default display manager (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:
{
services.displayManager.sddm.enable = true;
services.displayManager.gdm.enable = true;
}
You can set the keyboard layout (and optionally the layout variant):
{
services.xserver.xkb.layout = "de";
services.xserver.xkb.variant = "neo";
}
The X server is started automatically at boot time. If you don’t want this to happen, you can set:
{ services.xserver.autorun = false; }
The X server can then be started manually:
# systemctl start display-manager.service
On 64-bit systems, if you want OpenGL for 32-bit programs such as in Wine, you should also set the following:
{ hardware.graphics.enable32Bit = true; }
The x11 login screen can be skipped entirely, automatically logging you into your window manager and desktop environment when you boot your computer.
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.
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, you’d define:
{ services.displayManager.defaultSession = "none+i3"; }
Every display manager in NixOS supports auto-login, here is an example
using lightdm for a user alice:
{
services.xserver.displayManager.lightdm.enable = true;
services.displayManager.autoLogin.enable = true;
services.displayManager.autoLogin.user = "alice";
}
It is possible to avoid a display manager entirely and starting the X server manually from a virtual terminal. Add to your configuration:
{
services.xserver.displayManager.startx = {
enable = true;
generateScript = true;
};
}
then you can start the X server with the startx command.
The second option will generate a base xinitrc script that will run your
window manager and set up the systemd user session.
You can extend the script using the
extraCommands
option, for example:
{
services.xserver.displayManager.startx = {
generateScript = true;
extraCommands = ''
xrdb -load .Xresources
xsetroot -solid '#666661'
xsetroot -cursor_name left_ptr
'';
};
}
or, alternatively, you can write your own from scratch in ~/.xinitrc.
In this case, remember you’re responsible for starting the window manager, for example:
sxhkd &
bspwm &
and if you have enabled some systemd user service, you will probably want to also add these lines too:
# import required env variables from the current shell
systemctl --user import-environment DISPLAY XDG_SESSION_ID
# start all graphical user services
systemctl --user start nixos-fake-graphical-session.target
# start the user dbus daemon
dbus-daemon --session --address="unix:path=/run/user/$(id -u)/bus" &
The default and recommended driver for Intel Graphics in X.org is modesetting
(included in the xorg-server package itself).
This is a generic driver which uses the kernel mode
setting (KMS) mechanism, it
supports Glamor (2D graphics acceleration via OpenGL) and is actively
maintained, it may perform worse in some cases (like in old chipsets).
There is a second driver, intel (provided by the xf86-video-intel package),
specific to older Intel iGPUs from generation 2 to 9. It is not recommended by
most distributions: it lacks several modern features (for example, it doesn’t
support Glamor) and the package hasn’t been officially updated since 2015.
Third generation and older iGPUs (15-20+ years old) are not supported by the
modesetting driver (X will crash upon startup). Thus, the intel driver is
required for these chipsets.
Otherwise, the results vary depending on the hardware, so you may have to try
both drivers. Use the option
services.xserver.videoDrivers
to set one. The recommended configuration for modern systems is:
{ services.xserver.videoDrivers = [ "modesetting" ]; }
The modesetting driver doesn’t currently provide a TearFree option (this
will become available in an upcoming X.org release), So, without using a
compositor (for example, see services.picom.enable) you will
experience screen tearing.
If you experience screen tearing no matter what, this configuration was reported to resolve the issue:
{
services.xserver.videoDrivers = [ "intel" ];
services.xserver.deviceSection = ''
Option "DRI" "2"
Option "TearFree" "true"
'';
}
Note that this will likely downgrade the performance compared to
modesetting or intel with DRI 3 (default).
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 it’s not free software. You can enable it as follows:
{ services.xserver.videoDrivers = [ "nvidia" ]; }
If you have an older card, you may have to use one of the legacy drivers:
{
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.legacy_470;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.legacy_390;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.legacy_340;
}
You may need to reboot after enabling this driver to prevent a clash with other kernel modules.
Support for Synaptics touchpads (found in many laptops such as the Dell Latitude series) can be enabled as follows:
{ services.libinput.enable = true; }
The driver has many options (see Appendix A). For instance, the following disables tap-to-click behavior:
{ services.libinput.touchpad.tapping = false; }
Note: the use of services.xserver.synaptics is deprecated since NixOS
17.09.
GTK themes can be installed either to user profile or system-wide (via
environment.systemPackages). To make Qt 5 applications look similar to
GTK ones, you can use the following configuration:
{
qt.enable = true;
qt.platformTheme = "gtk2";
qt.style = "gtk2";
}
It is possible to install custom XKB
keyboard layouts
using the option services.xserver.xkb.extraLayouts.
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.
Create a file called us-greek with the following content (under a
directory called symbols; it’s an XKB peculiarity that will help with
testing):
xkb_symbols "us-greek"
{
include "us(basic)" // includes the base US keys
include "level3(ralt_switch)" // configures right alt as a third level switch
key <LatA> { [ a, A, Greek_alpha ] };
key <LatB> { [ b, B, Greek_beta ] };
key <LatG> { [ g, G, Greek_gamma ] };
key <LatD> { [ d, D, Greek_delta ] };
key <LatZ> { [ z, Z, Greek_zeta ] };
};
A minimal layout specification must include the following:
{
services.xserver.xkb.extraLayouts.us-greek = {
description = "US layout with alt-gr greek";
languages = [ "eng" ];
symbolsFile = /yourpath/symbols/us-greek;
};
}
The name (after extraLayouts.) should match the one given to the
xkb_symbols block.
Applying this customization requires rebuilding several packages, and a broken XKB file can lead to the X session crashing at login. Therefore, you’re strongly advised to test your layout before applying it:
$ nix-shell -p xorg.xkbcomp
$ setxkbmap -I/yourpath us-greek -print | xkbcomp -I/yourpath - $DISPLAY
You can inspect the predefined XKB files for examples:
$ echo "$(nix-build --no-out-link '<nixpkgs>' -A xorg.xkeyboardconfig)/etc/X11/xkb/"
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
setxkbmap us-greek and then type <alt>+a (it may not get applied in
your terminal straight away). To change the default, the usual
services.xserver.xkb.layout option can still be used.
A layout can have several other components besides xkb_symbols, for
example we will define new keycodes for some multimedia key and bind
these to some symbol.
Use the xev utility from pkgs.xorg.xev to find the codes of the keys
of interest, then create a media-key file to hold the keycodes
definitions
xkb_keycodes "media"
{
<volUp> = 123;
<volDown> = 456;
}
Now use the newly define keycodes in media-sym:
xkb_symbols "media"
{
key.type = "ONE_LEVEL";
key <volUp> { [ XF86AudioLowerVolume ] };
key <volDown> { [ XF86AudioRaiseVolume ] };
}
As before, to install the layout do
{
services.xserver.xkb.extraLayouts.media = {
description = "Multimedia keys remapping";
languages = [ "eng" ];
symbolsFile = /path/to/media-key;
keycodesFile = /path/to/media-sym;
};
}
The function pkgs.writeText <filename> <content> can be useful if you
prefer to keep the layout definitions inside the NixOS configuration.
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 won’t be loaded by default. As a
workaround, you can set the keymap using setxkbmap at the start of the
session with:
{
services.xserver.displayManager.sessionCommands = "setxkbmap -keycodes media";
}
If you are manually starting the X server, you should set the argument
-xkbdir /etc/X11/xkb, otherwise X won’t find your layout files. For
example with xinit run
$ xinit -- -xkbdir /etc/X11/xkb
To learn how to write layouts take a look at the XKB documentation . More example layouts can also be found here .
While X11 (see X Window System) 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 ‘Server’ functionality. This means it is sufficient to install a Wayland Compositor such as sway without separately enabling a Wayland server:
{ programs.sway.enable = true; }
This installs the sway compositor along with some essential utilities. Now you can start sway from the TTY console.
If you are using a wlroots-based compositor, like sway, and want to be
able to share your screen, make sure to configure Pipewire using
services.pipewire.enable
and related options.
For more helpful tips and tricks, see the wiki page about Sway.
Table of Contents
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.
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.
OpenCL is a general compute API. It is used by various applications such as Blender and Darktable to accelerate certain operations.
OpenCL applications load drivers through the Installable Client Driver
(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 OCL_ICD_VENDORS environment variable. This variable can contain a
directory which is scanned by the ICL loader for ICD files. For example:
$ export \
OCL_ICD_VENDORS=`nix-build '<nixpkgs>' --no-out-link -A rocmPackages.clr.icd`/etc/OpenCL/vendors/
The second mechanism is to add the OpenCL driver package to
hardware.graphics.extraPackages.
This links the ICD file under /run/opengl-driver, where it will be visible
to the ICD loader.
The proper installation of OpenCL drivers can be verified through the
clinfo command of the clinfo package. This command will report the
number of hardware devices that is found and give detailed information
for each device:
$ clinfo | head -n3
Number of platforms 1
Platform Name AMD Accelerated Parallel Processing
Platform Vendor Advanced Micro Devices, Inc.
Modern AMD Graphics Core
Next (GCN) GPUs are
supported through the rocmPackages.clr.icd package. Adding this package to
hardware.graphics.extraPackages
enables OpenCL support:
{ hardware.graphics.extraPackages = [ rocmPackages.clr.icd ]; }
Intel Gen12 and later GPUs
are supported by the Intel NEO OpenCL runtime that is provided by the intel-compute-runtime package.
The previous generations (8,9 and 11), have been moved to the intel-compute-runtime-legacy1 package.
The proprietary Intel OpenCL runtime, in the intel-ocl package, is an alternative for Gen7 GPUs.
Both intel-compute-runtime packages, as well as the intel-ocl package can be added to
hardware.graphics.extraPackages
to enable OpenCL support. For example, for Gen12 and later GPUs, the following
configuration can be used:
{ hardware.graphics.extraPackages = [ intel-compute-runtime ]; }
Vulkan is a graphics and compute API for GPUs. It is used directly by games or indirectly though compatibility layers like DXVK.
By default, if hardware.graphics.enable
is enabled, Mesa is installed and provides Vulkan for supported hardware.
Similar to OpenCL, Vulkan drivers are loaded through the Installable Client Driver (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.
The way to do this is to add the Vulkan driver package to
hardware.graphics.extraPackages.
This links the ICD file under /run/opengl-driver, where it will be
visible to the ICD loader.
The proper installation of Vulkan drivers can be verified through the
vulkaninfo command of the vulkan-tools package. This command will
report the hardware devices and drivers found, in this example output
amdvlk and radv:
$ 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
A simple graphical application that uses Vulkan is vkcube from the
vulkan-tools package.
Modern AMD Graphics Core Next (GCN) GPUs are supported through the RADV driver, which is part of mesa.
VA-API (Video Acceleration API) is an open-source library and API specification, which provides access to graphics hardware acceleration capabilities for video processing.
VA-API drivers are loaded by libva. The version in nixpkgs is built to search
the opengl driver path, so drivers can be installed in
hardware.graphics.extraPackages.
VA-API can be tested using:
$ nix-shell -p libva-utils --run vainfo
Modern Intel GPUs use the iHD driver, which can be installed with:
{ hardware.graphics.extraPackages = [ intel-media-driver ]; }
Older Intel GPUs use the i965 driver, which can be installed with:
{ hardware.graphics.extraPackages = [ intel-vaapi-driver ]; }
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
(/dev/dri/renderD*) or are tagged as uaccess (/dev/dri/card*). The
access control lists of devices with the uaccess tag will be updated
automatically when a user logs in through systemd-logind. For example,
if the user alice is logged in, the access control list should look as
follows:
$ getfacl /dev/dri/card0
# file: dev/dri/card0
# owner: root
# group: video
user::rw-
user:alice:rw-
group::rw-
mask::rw-
other::---
If you disabled (this functionality of) systemd-logind, you may need
to add the user to the video group and log in again.
The Installable Client Driver (ICD) mechanism used by OpenCL and
Vulkan loads runtimes into its address space using dlopen. 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.
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 LD_DEBUG variable set to get more diagnostic information. For
example, OpenCL can be tested with LD_DEBUG=files clinfo, which should
report missing symbols.
Table of Contents
To enable the Xfce Desktop Environment, set
{
services.xserver.desktopManager.xfce.enable = true;
services.displayManager.defaultSession = "xfce";
}
Optionally, picom can be enabled for nice graphical effects, some example settings:
{
services.picom = {
enable = true;
fade = true;
inactiveOpacity = 0.9;
shadow = true;
fadeDelta = 4;
};
}
Some Xfce programs are not installed automatically. To install them
manually (system wide), put them into your
environment.systemPackages from pkgs.xfce.
Thunar (the Xfce file manager) is automatically enabled when Xfce is
enabled. To enable Thunar without enabling Xfce, use the configuration
option programs.thunar.enable instead of adding
pkgs.xfce.thunar to environment.systemPackages.
If you’d like to add extra plugins to Thunar, add them to
programs.thunar.plugins. You shouldn’t just add them to
environment.systemPackages.
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 journalctl --user -b).
Thunar:2410): GVFS-RemoteVolumeMonitor-WARNING **: remote volume monitor with dbus name org.gtk.Private.UDisks2VolumeMonitor is not supported
This is caused by some needed GNOME services not running. This is all fixed by enabling “Launch GNOME services on startup” in the Advanced tab of the Session and Startup settings panel. Alternatively, you can run this command to do the same thing.
$ xfconf-query -c xfce4-session -p /compat/LaunchGNOME -s true
It is necessary to log out and log in again for this to take effect.
Table of Contents
This section describes how to configure networking components on your NixOS machine.
To facilitate network configuration, some desktop environments use NetworkManager. You can enable NetworkManager by setting:
{ networking.networkmanager.enable = true; }
some desktop managers (e.g., GNOME) enable NetworkManager automatically for you.
All users that should have permission to change network settings must
belong to the networkmanager group:
{ users.users.alice.extraGroups = [ "networkmanager" ]; }
NetworkManager is controlled using either nmcli or nmtui
(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
programs.nm-applet.enable, the graphical applet will be
installed and will launch automatically when the graphical session is
started.
networking.networkmanager and networking.wireless (WPA Supplicant)
can be used together if desired. To do this you need to instruct
NetworkManager to ignore those interfaces like:
{
networking.networkmanager.unmanaged = [
"*"
"except:type:wwan"
"except:type:gsm"
];
}
Refer to the option description for the exact syntax and references to external documentation.
Secure shell (SSH) access to your machine can be enabled by setting:
{ services.openssh.enable = true; }
By default, root logins using a password are disallowed. They can be
disabled entirely by setting
services.openssh.settings.PermitRootLogin to "no".
You can declaratively specify authorised public keys for a user as follows:
{
users.users.alice.openssh.authorizedKeys.keys = [ "ssh-ed25519 AAAAB3NzaC1kc3MAAACBAPIkGWVEt4..." ];
}
By default, NixOS uses DHCP (specifically, dhcpcd) to automatically
configure network interfaces. However, you can configure an interface
manually as follows:
{
networking.interfaces.eth0.ipv4.addresses = [
{
address = "192.168.1.2";
prefixLength = 24;
}
];
}
Typically you’ll also want to set a default gateway and set of name servers:
{
networking.defaultGateway = "192.168.1.1";
networking.nameservers = [ "8.8.8.8" ];
}
Statically configured interfaces are set up by the systemd service
interface-name-cfg.service. The default gateway and name server
configuration is performed by network-setup.service.
The host name is set using networking.hostName:
{ networking.hostName = "cartman"; }
The default host name is nixos. Set it to the empty string ("") to
allow the DHCP server to provide the host name.
IPv6 is enabled by default. Stateless address autoconfiguration is used
to automatically assign IPv6 addresses to all interfaces, and Privacy
Extensions (RFC 4941) are enabled by default. You can adjust the default
for this by setting networking.tempAddresses. This option
may be overridden on a per-interface basis by
networking.interfaces.<name>.tempAddress. You can disable
IPv6 support globally by setting:
{ networking.enableIPv6 = false; }
You can disable IPv6 on a single interface using a normal sysctl (in
this example, we use interface eth0):
{ boot.kernel.sysctl."net.ipv6.conf.eth0.disable_ipv6" = true; }
As with IPv4 networking interfaces are automatically configured via DHCPv6. You can configure an interface manually:
{
networking.interfaces.eth0.ipv6.addresses = [
{
address = "fe00:aa:bb:cc::2";
prefixLength = 64;
}
];
}
For configuring a gateway, optionally with explicitly specified interface:
{
networking.defaultGateway6 = {
address = "fe00::1";
interface = "enp0s3";
};
}
See the section called “IPv4 Configuration” for similar examples and additional information.
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:
{ networking.firewall.enable = false; }
If the firewall is enabled, you can open specific TCP ports to the outside world:
{
networking.firewall.allowedTCPPorts = [
80
443
];
}
Note that TCP port 22 (ssh) is opened automatically if the SSH daemon is
enabled (services.openssh.enable = true). UDP ports can be opened through
networking.firewall.allowedUDPPorts.
To open ranges of TCP ports:
{
networking.firewall.allowedTCPPortRanges = [
{
from = 4000;
to = 4007;
}
{
from = 8000;
to = 8010;
}
];
}
Similarly, UDP port ranges can be opened through
networking.firewall.allowedUDPPortRanges.
For a desktop installation using NetworkManager (e.g., GNOME), you just
have to make sure the user is in the networkmanager group and you can
skip the rest of this section on wireless networks.
NixOS will start wpa_supplicant for you if you enable this setting:
{ networking.wireless.enable = true; }
NixOS lets you specify networks for wpa_supplicant declaratively:
{
networking.wireless.networks = {
# SSID with no spaces or special characters
echelon = {
psk = "abcdefgh";
};
# SSID with spaces and/or special characters
"echelon's AP" = {
psk = "ijklmnop";
};
# Hidden SSID
echelon = {
hidden = true;
psk = "qrstuvwx";
};
free.wifi = { }; # Public wireless network
};
}
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
/etc/wpa_supplicant.conf. You should edit this file yourself to define
wireless networks, WPA keys and so on (see wpa_supplicant.conf(5)).
If you are using WPA2 you can generate pskRaw key using
wpa_passphrase:
$ wpa_passphrase ESSID PSK
network={
ssid="echelon"
#psk="abcdefgh"
psk=dca6d6ed41f4ab5a984c9f55f6f66d4efdc720ebf66959810f4329bb391c5435
}
{
networking.wireless.networks = {
echelon = {
pskRaw = "dca6d6ed41f4ab5a984c9f55f6f66d4efdc720ebf66959810f4329bb391c5435";
};
};
}
or you can use it to directly generate the wpa_supplicant.conf:
# wpa_passphrase ESSID PSK > /etc/wpa_supplicant.conf
After you have edited the wpa_supplicant.conf, you need to restart the
wpa_supplicant service.
# systemctl restart wpa_supplicant.service
You can use networking.localCommands to
specify shell commands to be run at the end of network-setup.service. This
is useful for doing network configuration not covered by the existing NixOS
modules. For instance, to statically configure an IPv6 address:
{
networking.localCommands = ''
ip -6 addr add 2001:610:685:1::1/64 dev eth0
'';
}
NixOS uses the udev predictable naming
scheme to assign names
to network interfaces. This means that by default cards are not given
the traditional names like eth0 or eth1, whose order can change
unpredictably across reboots. Instead, relying on physical locations and
firmware information, the scheme produces names like ens1, enp2s0,
etc.
These names are predictable but less memorable and not necessarily
stable: for example installing new hardware or changing firmware
settings can result in a name
change.
If this is undesirable, for example if you have a single ethernet card,
you can revert to the traditional scheme by setting
networking.usePredictableInterfaceNames
to false.
In case there are multiple interfaces of the same type, it’s better to
assign custom names based on the device hardware address. For example,
we assign the name wan to the interface with MAC address
52:54:00:12:01:01 using a netword link unit:
{
systemd.network.links."10-wan" = {
matchConfig.PermanentMACAddress = "52:54:00:12:01:01";
linkConfig.Name = "wan";
};
}
Note that links are directly read by udev, not networkd, and will work even if networkd is disabled.
Alternatively, we can use a plain old udev rule:
{
boot.initrd.services.udev.rules = ''
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", \
ATTR{address}=="52:54:00:12:01:01", KERNEL=="eth*", NAME="wan"
'';
}
The rule must be installed in the initrd using
boot.initrd.services.udev.rules, not the usual services.udev.extraRules
option. This is to avoid race conditions with other programs controlling
the interface.
Table of Contents
You can override the Linux kernel and associated packages using the
option boot.kernelPackages. For instance, this selects the Linux 3.10
kernel:
{ boot.kernelPackages = pkgs.linuxKernel.packages.linux_3_10; }
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.
While pkgs.linuxKernel.packages contains all available kernel packages,
you may want to use one of the unversioned pkgs.linuxPackages_* aliases
such as pkgs.linuxPackages_latest, that are kept up to date with new
versions.
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 it’s 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.
A kernel will be removed from nixpkgs when the first batch of stable kernels after the final release is published. E.g. when 6.15.11 is the final release of the 6.15 series and is released together with 6.16.3 and 6.12.43, it will be removed on the release of 6.16.4 and 6.12.44. Custom kernel variants such as linux-hardened are also affected by this.
Longterm versions of kernels will be removed before the next stable NixOS that will exceed the maintenance period of the kernel version.
The default Linux kernel configuration should be fine for most users. You can see the configuration of your current kernel with the following command:
zcat /proc/config.gz
If you want to change the kernel configuration, you can use the
packageOverrides feature (see the section called “Customising Packages”). For
instance, to enable support for the kernel debugger KGDB:
{
nixpkgs.config.packageOverrides =
pkgs:
pkgs.lib.recursiveUpdate pkgs {
linuxKernel.kernels.linux_5_10 = pkgs.linuxKernel.kernels.linux_5_10.override {
extraConfig = ''
KGDB y
'';
};
};
}
extraConfig takes a list of Linux kernel configuration options, one
per line. The name of the option should not include the prefix
CONFIG_. The option value is typically y, n or m (to build
something as a kernel module).
Kernel modules for hardware devices are generally loaded automatically
by udev. You can force a module to be loaded via
boot.kernelModules, e.g.
{
boot.kernelModules = [
"fuse"
"kvm-intel"
"coretemp"
];
}
If the module is required early during the boot (e.g. to mount the root
file system), you can use boot.initrd.kernelModules:
{ boot.initrd.kernelModules = [ "cifs" ]; }
This causes the specified modules and their dependencies to be added to the initial ramdisk.
Kernel runtime parameters can be set through
boot.kernel.sysctl, e.g.
{ boot.kernel.sysctl."net.ipv4.tcp_keepalive_time" = 120; }
sets the kernel’s TCP keepalive time to 120 seconds. To see the
available parameters, run sysctl -a.
Please refer to the Nixpkgs manual for the various ways of building a custom kernel.
To use your custom kernel package in your NixOS configuration, set
{ boot.kernelPackages = pkgs.linuxPackagesFor yourCustomKernel; }
The Linux kernel does not have Rust language support enabled by default. For kernel versions 6.7 or newer, experimental Rust support can be enabled. In a NixOS configuration, set:
{
boot.kernelPatches = [
{
name = "Rust Support";
patch = null;
features = {
rust = true;
};
}
];
}
This section was moved to the Nixpkgs manual.
It’s a common issue that the latest stable version of ZFS doesn’t support the latest
available Linux kernel. It is recommended to use the latest available LTS that’s compatible
with ZFS. Usually this is the default kernel provided by nixpkgs (i.e. pkgs.linuxPackages).
Table of Contents
Subversion is a centralized version-control system. It can use a variety of protocols for communication between client and server.
This section focuses on configuring a web-based server on top of the Apache HTTP server, which uses WebDAV/DeltaV for communication.
For more information on the general setup, please refer to the the appropriate section of the Subversion book.
To configure, include in /etc/nixos/configuration.nix code to activate
Apache HTTP, setting services.httpd.adminAddr
appropriately:
{
services.httpd.enable = true;
services.httpd.adminAddr = "...";
networking.firewall.allowedTCPPorts = [
80
443
];
}
For a simple Subversion server with basic authentication, configure the
Subversion module for Apache as follows, setting hostName and
documentRoot appropriately, and SVNParentPath to the parent
directory of the repositories, AuthzSVNAccessFile to the location of
the .authz file describing access permission, and AuthUserFile to
the password file.
{
services.httpd.extraModules = [
# note that order is *super* important here
{
name = "dav_svn";
path = "${pkgs.apacheHttpdPackages.subversion}/modules/mod_dav_svn.so";
}
{
name = "authz_svn";
path = "${pkgs.apacheHttpdPackages.subversion}/modules/mod_authz_svn.so";
}
];
services.httpd.virtualHosts = {
"svn" = {
hostName = HOSTNAME;
documentRoot = DOCUMENTROOT;
locations."/svn".extraConfig = ''
DAV svn
SVNParentPath REPO_PARENT
AuthzSVNAccessFile ACCESS_FILE
AuthName "SVN Repositories"
AuthType Basic
AuthUserFile PASSWORD_FILE
Require valid-user
'';
};
};
}
The key "svn" is just a symbolic name identifying the virtual host.
The "/svn" in locations."/svn".extraConfig is the path underneath
which the repositories will be served.
This page explains how to set up the Subversion configuration itself. This boils down to the following:
Underneath REPO_PARENT repositories can be set up as follows:
$ svn create REPO_NAME
Repository files need to be accessible by wwwrun:
$ chown -R wwwrun:wwwrun REPO_PARENT
The password file PASSWORD_FILE can be created as follows:
$ htpasswd -cs PASSWORD_FILE USER_NAME
Additional users can be set up similarly, omitting the c flag:
$ htpasswd -s PASSWORD_FILE USER_NAME
The file describing access permissions ACCESS_FILE will look something
like the following:
[/]
* = r
[REPO_NAME:/]
USER_NAME = rw
The Subversion repositories will be accessible as
http://HOSTNAME/svn/REPO_NAME.
Table of Contents
GNOME provides a simple, yet full-featured desktop environment with a focus on productivity. Its Mutter compositor supports both Wayland and X server, and the GNOME Shell user interface is fully customizable by extensions.
All of the core apps, optional apps, games, and core developer tools from GNOME are available.
To enable the GNOME desktop use:
{
services.desktopManager.gnome.enable = true;
services.displayManager.gdm.enable = true;
}
While it is not strictly necessary to use GDM as the display manager with GNOME, it is recommended, as some features such as screen lock might not work without it.
The default applications used in NixOS are very minimal, inspired by the defaults used in gnome-build-meta.
If you’d like to only use the GNOME desktop and not the apps, you can disable them with:
{ services.gnome.core-apps.enable = false; }
and none of them will be installed.
If you’d only like to omit a subset of the core utilities, you can use
environment.gnome.excludePackages.
Note that this mechanism can only exclude core utilities, games and core developer tools.
It is also possible to disable many of the core services. For example, if you do not need indexing files, you can disable TinySPARQL with:
{
services.gnome.localsearch.enable = false;
services.gnome.tinysparql.enable = false;
}
Note, however, that doing so is not supported and might break some applications. Notably, GNOME Music cannot work without TinySPARQL.
You can install all of the GNOME games with:
{ services.gnome.games.enable = true; }
You can install GNOME core developer tools with:
{ services.gnome.core-developer-tools.enable = true; }
GNOME Flashback provides a desktop environment based on the classic GNOME 2 architecture. You can enable the default GNOME Flashback session, which uses the Metacity window manager, with:
{ services.desktopManager.gnome.flashback.enableMetacity = true; }
It is also possible to create custom sessions that replace Metacity with a different window manager using services.desktopManager.gnome.flashback.customSessions.
The following example uses xmonad window manager:
{
services.desktopManager.gnome.flashback.customSessions = [
{
wmName = "xmonad";
wmLabel = "XMonad";
wmCommand = "${pkgs.haskellPackages.xmonad}/bin/xmonad";
enableGnomePanel = false;
}
];
}
Icon themes and GTK themes don’t require any special option to install in NixOS.
You can add them to environment.systemPackages and switch to them with GNOME Tweaks.
If you’d like to do this manually in dconf, change the values of the following keys:
/org/gnome/desktop/interface/gtk-theme
/org/gnome/desktop/interface/icon-theme
in dconf-editor
Most Shell extensions are packaged under the gnomeExtensions attribute.
Some packages that include Shell extensions, like gpaste, don’t have their extension decoupled under this attribute.
You can install them like any other package:
{
environment.systemPackages = [
pkgs.gnomeExtensions.dash-to-dock
pkgs.gnomeExtensions.gsconnect
pkgs.gnomeExtensions.mpris-indicator-button
];
}
Unfortunately, we lack a way for these to be managed in a completely declarative way.
So you have to enable them manually with an Extensions application.
It is possible to use a GSettings override for this on org.gnome.shell.enabled-extensions, but that will only influence the default value.
Majority of software building on the GNOME platform use GLib’s GSettings system to manage runtime configuration. For our purposes, the system consists of XML schemas describing the individual configuration options, stored in the package, and a settings backend, where the values of the settings are stored. On NixOS, like on most Linux distributions, dconf database is used as the backend.
GSettings vendor overrides can be used to adjust the default values for settings of the GNOME desktop and apps by replacing the default values specified in the XML schemas. Using overrides will allow you to pre-seed user settings before you even start the session.
Overrides really only change the default values for GSettings keys so if you or an application changes the setting value, the value set by the override will be ignored. Until NixOS’s dconf module implements changing values, you will either need to keep that in mind and clear the setting from the backend using dconf reset command when that happens, or use the module from home-manager.
You can override the default GSettings values using the
services.desktopManager.gnome.extraGSettingsOverrides option.
Take note that whatever packages you want to override GSettings for, you need to add them to
services.desktopManager.gnome.extraGSettingsOverridePackages.
You can use dconf-editor tool to explore which GSettings you can set.
{
services.desktopManager.gnome = {
extraGSettingsOverrides = ''
# Change default background
[org.gnome.desktop.background]
picture-uri='file://${pkgs.nixos-artwork.wallpapers.mosaic-blue.gnomeFilePath}'
# Favorite apps in gnome-shell
[org.gnome.shell]
favorite-apps=['org.gnome.Console.desktop', 'org.gnome.Nautilus.desktop']
'';
extraGSettingsOverridePackages = [
pkgs.gsettings-desktop-schemas # for org.gnome.desktop
pkgs.gnome-shell # for org.gnome.shell
];
};
}
Yes you can, and any other display-manager in NixOS.
However, it doesn’t work correctly for the Wayland session of GNOME Shell yet, and won’t be able to lock your screen.
See this issue.
Table of Contents
Pantheon is the desktop environment created for the elementary OS distribution. It is written from scratch in Vala, utilizing GNOME technologies with GTK and Granite.
All of Pantheon is working in NixOS and the applications should be available, aside from a few exceptions. To enable Pantheon, set
{ services.desktopManager.pantheon.enable = true; }
This automatically enables LightDM and Pantheon’s LightDM greeter. If you’d like to disable this, set
{
services.xserver.displayManager.lightdm.greeters.pantheon.enable = false;
services.xserver.displayManager.lightdm.enable = false;
}
but please be aware using Pantheon without LightDM as a display manager will break screenlocking from the UI. The NixOS module for Pantheon installs all of Pantheon’s default applications. If you’d like to not install Pantheon’s apps, set
{ services.pantheon.apps.enable = false; }
You can also use environment.pantheon.excludePackages to remove any other app (like elementary-mail).
Wingpanel and Switchboard work differently than they do in other distributions, as far as using plugins. You cannot install a plugin globally (like with environment.systemPackages) to start using it. You should instead be using the following options:
to configure the programs with plugs or indicators.
The difference in NixOS is both these programs are patched to load plugins from a directory that is the value of an environment variable. All of which is controlled in Nix. If you need to configure the particular packages manually you can override the packages like:
wingpanel-with-indicators.override {
indicators = [ pkgs.some-special-indicator ];
}
switchboard-with-plugs.override { plugs = [ pkgs.some-special-plug ]; }
please note that, like how the NixOS options describe these as extra plugins, this would only add to the default plugins included with the programs. If for some reason you’d like to configure which plugins to use exactly, both packages have an argument for this:
wingpanel-with-indicators.override {
useDefaultIndicators = false;
indicators = specialListOfIndicators;
}
switchboard-with-plugs.override {
useDefaultPlugs = false;
plugs = specialListOfPlugs;
}
this could be most useful for testing a particular plug-in in isolation.
Open Switchboard and go to: Administration → About → Restore Default Settings → Restore Settings. This will reset any dconf settings to their Pantheon defaults. Note this could reset certain GNOME specific preferences if that desktop was used prior.
This is a known issue and there is no known workaround.
AppCenter is available and the Flatpak backend should work so you can install some Flatpak applications using it. However, due to missing appstream metadata, the Packagekit backend does not function currently. See this issue.
If you are using Pantheon, AppCenter should be installed by default if you have Flatpak support enabled. If you also wish to add the appcenter Flatpak remote:
$ flatpak remote-add --if-not-exists appcenter https://flatpak.elementary.io/repo.flatpakrepo
Table of Contents
tpm2-totp attests the trustworthiness of a device against a human using time-based one-time passwords. This module uses a tpm2-totp configuration to display a TOTP at boot using Plymouth.
{
boot.plymouth.tpm2-totp.enable = true;
# Plymouth and systemd initrd/stage-1 are required:
boot.plymouth.enable = true;
boot.initrd.systemd.enable = true;
}
Switch to the new configuration before proceeding to the next step.
tpm2-totp Generate a new TOTP secret and save the secret in your chosen authenticator app. See man tpm2-totp for commands and configuration examples.
More information, including security considerations, can be found in the README.md in the tpm2-totp repository. Be sure to select the tag for the version of tpm2-totp you have installed.
Reboot and you should see the TOTP appear on the Plymouth boot screen. The TOTP should match the code displayed in your authenticator app (or the code immediately before/after).
Table of Contents
NixOS has support for several bootloader backends by default: systemd-boot, grub, uboot, etc. The built-in bootloader backend support is generic and supports most use cases. Some users may prefer to create advanced workflows around managing the bootloader and bootable entries.
You can replace the built-in bootloader support with your own tooling using the “external” bootloader option.
Imagine you have created a new package called FooBoot.
FooBoot provides a program at ${pkgs.fooboot}/bin/fooboot-install which takes the system closure’s path as its only argument and configures the system’s bootloader.
You can enable FooBoot like this:
{ pkgs, ... }:
{
boot.loader.external = {
enable = true;
installHook = "${pkgs.fooboot}/bin/fooboot-install";
};
}
Bootloaders should use RFC-0125’s Bootspec format and synthesis tools to identify the key properties for bootable system generations.
Table of Contents
Clevis is a framework for automated decryption of resources. Clevis allows for secure unattended disk decryption during boot, using decryption policies that must be satisfied for the data to decrypt.
The first step is to embed your secret in a JWE file. JWE files have to be created through the clevis command line. 3 types of policies are supported:
TPM policies
Secrets are pinned against the presence of a TPM2 device, for example:
echo -n hi | clevis encrypt tpm2 '{}' > hi.jwe
Tang policies
Secrets are pinned against the presence of a Tang server, for example:
echo -n hi | clevis encrypt tang '{"url": "http://tang.local"}' > hi.jwe
Shamir Secret Sharing
Using Shamir’s Secret Sharing (sss), secrets are pinned using a combination of the two preceding policies. For example:
echo -n hi | clevis encrypt sss \
'{"t": 2, "pins": {"tpm2": {"pcr_ids": "0"}, "tang": {"url": "http://tang.local"}}}' \
> hi.jwe
For more complete documentation on how to generate a secret with clevis, see the clevis documentation.
In order to activate unattended decryption of a resource at boot, enable the clevis module:
{ boot.initrd.clevis.enable = true; }
Then, specify the device you want to decrypt using a given clevis secret. Clevis will automatically try to decrypt the device at boot and will fallback to interactive unlocking if the decryption policy is not fulfilled.
{ boot.initrd.clevis.devices."/dev/nvme0n1p1".secretFile = ./nvme0n1p1.jwe; }
Only bcachefs, zfs and luks encrypted devices are supported at this time.
Table of Contents
Garage
is an open-source, self-hostable S3 store, simpler than MinIO, for geodistributed stores.
The server setup can be automated using
services.garage. A
client configured to your local Garage instance is available in
the global environment as garage-manage.
Garage provides a cookbook documentation on how to upgrade: https://garagehq.deuxfleurs.fr/documentation/cookbook/upgrading/
Garage has two types of upgrades: patch-level upgrades and minor/major version upgrades.
In all cases, you should read the changelog and ideally test the upgrade on a staging cluster.
Checking the health of your cluster can be achieved using garage-manage repair.
Straightforward upgrades (patch-level upgrades). Upgrades must be performed one by one, i.e. for each node, stop it, upgrade it : change stateVersion or services.garage.package, restart it if it was not already by switching.
Multiple version upgrades.
Garage do not provide any guarantee on moving more than one major-version forward.
E.g., if you’re on 0.9, you cannot upgrade to 2.0.
You need to upgrade to 1.2 first.
As long as stateVersion is declared properly,
this is enforced automatically. The module will issue a warning to remind the user to upgrade to latest
Garage after that deploy.
Here are some baseline instructions to handle advanced upgrades in Garage, when in doubt, please refer to upstream instructions.
Disable API and web access to Garage.
Perform garage-manage repair --all-nodes --yes tables and garage-manage repair --all-nodes --yes blocks.
Verify the resulting logs and check that data is synced properly between all nodes.
If you have time, do additional checks (scrub, block_refs, etc.).
Check if queues are empty by garage-manage stats or through monitoring tools.
Run systemctl stop garage to stop the actual Garage version.
Backup the metadata folder of ALL your nodes, e.g. for a metadata directory (the default one) in /var/lib/garage/meta,
you can run pushd /var/lib/garage; tar -acf meta-v0.7.tar.zst meta/; popd.
Run the offline migration: nix-shell -p garage_1 --run "garage offline-repair --yes", this can take some time depending on how many objects are stored in your cluster.
Bump Garage version in your NixOS configuration, either by changing stateVersion or bumping services.garage.package, this should restart Garage automatically.
Perform garage-manage repair --all-nodes --yes tables and garage-manage repair --all-nodes --yes blocks.
Wait for a full table sync to run.
Your upgraded cluster should be in a working state, re-enable API and web access.
As stated in the previous paragraph, we must provide a clean upgrade-path for Garage since it cannot move more than one major version forward on a single upgrade. This chapter adds some notes how Garage updates should be rolled out in the future. This is inspired from how Nextcloud does it.
While patch-level updates are no problem and can be done directly in the
package-expression (and should be backported to supported stable branches after that),
major-releases should be added in a new attribute (e.g. Garage v3.0.0
should be available in nixpkgs as pkgs.garage_3).
To provide simple upgrade paths it’s generally useful to backport those as well to stable
branches. As long as the package-default isn’t altered, this won’t break existing setups.
After that, the versioning-warning in the garage-module should be
updated to make sure that the
package-option selects the latest version
on fresh setups.
If major-releases will be abandoned by upstream, we should check first if those are needed
in NixOS for a safe upgrade-path before removing those. In that case we should keep those
packages, but mark them as insecure in an expression like this (in
<nixpkgs/pkgs/tools/filesystem/garage/default.nix>):
# ...
{
garage_1_2_0 = generic {
version = "1.2.0";
sha256 = "0000000000000000000000000000000000000000000000000000";
eol = true;
};
}
Ideally we should make sure that it’s possible to jump two NixOS versions forward: i.e. the warnings and the logic in the module should guard a user to upgrade from a Garage on e.g. 22.11 to a Garage on 23.11.
Table of Contents
YouTrack is a browser-based bug tracker, issue tracking system and project management software.
YouTrack exposes a web GUI installer on first login.
You need a token to access it.
You can find this token in the log of the youtrack service. The log line looks like
* JetBrains YouTrack 2023.3 Configuration Wizard will be available on [http://127.0.0.1:8090/?wizard_token=somelongtoken] after start
Starting with YouTrack 2023.1, JetBrains no longer distributes it as as JAR.
The new distribution with the JetBrains Launcher as a ZIP changed the basic data structure and also some configuration parameters.
Check out https://www.jetbrains.com/help/youtrack/server/YouTrack-Java-Start-Parameters.html for more information on the new configuration options.
When upgrading to YouTrack 2023.1 or higher, a migration script will move the old state directory to /var/lib/youtrack/2022_3 as a backup.
A one-time manual update is required:
Before you update take a backup of your YouTrack instance!
Migrate the options you set in services.youtrack.extraParams and services.youtrack.jvmOpts to services.youtrack.generalParameters and services.youtrack.environmentalParameters (see the examples and the YouTrack docs)
To start the upgrade set services.youtrack.package = pkgs.youtrack
YouTrack then starts in upgrade mode, meaning you need to obtain the wizard token as above
Select you want to Upgrade YouTrack
As source you select /var/lib/youtrack/2022_3/teamsysdata/ (adopt if you have a different state path)
Change the data directory location to /var/lib/youtrack/data/. The other paths should already be right.
If you migrate a larger YouTrack instance, it might be useful to set -Dexodus.entityStore.refactoring.forceAll=true in services.youtrack.generalParameters for the first startup of YouTrack 2023.x.
Table of Contents
An image board engine dedicated for small and medium communities.
By default the module will execute Szurubooru server only, the web client only contains static files that can be reached via a reverse proxy.
Here is a basic configuration:
{
services.szurubooru = {
enable = true;
server = {
port = 8080;
settings = {
domain = "https://szurubooru.domain.tld";
secretFile = /path/to/secret/file;
};
};
database = {
passwordFile = /path/to/secret/file;
};
};
}
The preferred method to run this service is behind a reverse proxy not to expose an open port. For example, here is a minimal Nginx configuration:
{
services.szurubooru = {
enable = true;
server = {
port = 8080;
# ...
};
# ...
};
services.nginx.virtualHosts."szurubooru.domain.tld" = {
locations = {
"/api/".proxyPass = "http://localhost:8080/";
"/data/".root = config.services.szurubooru.dataDir;
"/" = {
root = config.services.szurubooru.client.package;
tryFiles = "$uri /index.htm";
};
};
};
}
Not all configuration options of the server are available directly in this module, but you can add them in services.szurubooru.server.settings:
{
services.szurubooru = {
enable = true;
server.settings = {
domain = "https://szurubooru.domain.tld";
delete_source_files = "yes";
contact_email = "[email protected]";
};
};
}
You can find all of the options in the default config file available here.
Table of Contents
A free and open source manga reader server that runs extensions built for Tachiyomi.
By default, the module will execute Suwayomi-Server backend and web UI:
{ ... }:
{
services.suwayomi-server = {
enable = true;
};
}
It runs in the systemd service named suwayomi-server in the data directory /var/lib/suwayomi-server.
You can change the default parameters with some other parameters:
{ ... }:
{
services.suwayomi-server = {
enable = true;
dataDir = "/var/lib/suwayomi"; # Default is "/var/lib/suwayomi-server"
openFirewall = true;
settings = {
server.port = 4567;
};
};
}
If you want to create a desktop icon, you can activate the system tray option:
{ ... }:
{
services.suwayomi-server = {
enable = true;
dataDir = "/var/lib/suwayomi"; # Default is "/var/lib/suwayomi-server"
openFirewall = true;
settings = {
server.port = 4567;
server.enableSystemTray = true;
};
};
}
You can configure a basic authentication to the web interface with:
{ ... }:
{
services.suwayomi-server = {
enable = true;
openFirewall = true;
settings = {
server.port = 4567;
server = {
basicAuthEnabled = true;
basicAuthUsername = "username";
# NOTE: this is not a real upstream option
basicAuthPasswordFile = ./path/to/the/password/file;
};
};
};
}
Not all the configuration options are available directly in this module, but you can add the other options of suwayomi-server with:
{ ... }:
{
services.suwayomi-server = {
enable = true;
openFirewall = true;
settings = {
server = {
port = 4567;
autoDownloadNewChapters = false;
maxSourcesInParallel = 6;
extensionRepos = [
"https://raw.githubusercontent.com/MY_ACCOUNT/MY_REPO/repo/index.min.json"
];
};
};
};
}
Table of Contents
strfry is a relay for the nostr protocol.
By default, the module will execute strfry:
{ ... }:
{
services.strfry.enable = true;
}
It runs in the systemd service named strfry.
You can configure nginx as a reverse proxy with:
{ ... }:
{
security.acme = {
acceptTerms = true;
defaults.email = "[email protected]";
};
services.nginx.enable = true;
services.nginx.virtualHosts."strfry.example.com" = {
addSSL = true;
enableACME = true;
locations."/" = {
proxyPass = "http://127.0.0.1:${toString config.services.strfry.settings.relay.port}";
proxyWebsockets = true; # nostr uses websockets
};
};
services.strfry.enable = true;
}
Table of Contents
Plausible is a privacy-friendly alternative to Google analytics.
At first, a secret key is needed to be generated. This can be done with e.g.
$ openssl rand -base64 64
After that, plausible can be deployed like this:
{
services.plausible = {
enable = true;
server = {
baseUrl = "http://analytics.example.org";
# secretKeybaseFile is a path to the file which contains the secret generated
# with openssl as described above.
secretKeybaseFile = "/run/secrets/plausible-secret-key-base";
};
};
}
Table of Contents
A self-hosted file sharing platform and an alternative for WeTransfer.
By default, the module will execute Pingvin Share backend and frontend on the ports 8080 and 3000.
I will run two systemd services named pingvin-share-backend and pingvin-share-frontend in the specified data directory.
Here is a basic configuration:
{
services-pingvin-share = {
enable = true;
openFirewall = true;
backend.port = 9010;
frontend.port = 9011;
};
}
The preferred method to run this service is behind a reverse proxy not to expose an open port. This, you can configure Nginx such like this:
{
services-pingvin-share = {
enable = true;
hostname = "pingvin-share.domain.tld";
https = true;
nginx.enable = true;
};
}
Furthermore, you can increase the maximal size of an uploaded file with the option services.nginx.clientMaxBodySize.
Table of Contents
The Pi-hole suite provides a web GUI for controlling and monitoring pihole-FTL.
Example configuration:
{
services.pihole-web = {
enable = true;
ports = [ 80 ];
};
}
The dashboard can be configured using services.pihole-ftl.settings, in particular the webserver subsection.
Table of Contents
pict-rs is a a simple image hosting service.
the minimum to start pict-rs is
{ services.pict-rs.enable = true; }
this will start the http server on port 8080 by default.
pict-rs offers the following endpoints:
POST /image for uploading an image. Uploaded content must be valid multipart/form-data with an
image array located within the images[] key
This endpoint returns the following JSON structure on success with a 201 Created status
{
"files": [
{
"delete_token": "JFvFhqJA98",
"file": "lkWZDRvugm.jpg"
},
{
"delete_token": "kAYy9nk2WK",
"file": "8qFS0QooAn.jpg"
},
{
"delete_token": "OxRpM3sf0Y",
"file": "1hJaYfGE01.jpg"
}
],
"msg": "ok"
}
GET /image/download?url=... Download an image from a remote server, returning the same JSON
payload as the POST endpoint
GET /image/original/{file} for getting a full-resolution image. file here is the file key from the
/image endpoint’s JSON
GET /image/details/original/{file} for getting the details of a full-resolution image.
The returned JSON is structured like so:
{
"width": 800,
"height": 537,
"content_type": "image/webp",
"created_at": [
2020,
345,
67376,
394363487
]
}
GET /image/process.{ext}?src={file}&... get a file with transformations applied.
existing transformations include
identity=true: apply no changes
blur={float}: apply a gaussian blur to the file
thumbnail={int}: produce a thumbnail of the image fitting inside an {int} by {int}
square using raw pixel sampling
resize={int}: produce a thumbnail of the image fitting inside an {int} by {int} square
using a Lanczos2 filter. This is slower than sampling but looks a bit better in some cases
crop={int-w}x{int-h}: produce a cropped version of the image with an {int-w} by {int-h}
aspect ratio. The resulting crop will be centered on the image. Either the width or height
of the image will remain full-size, depending on the image’s aspect ratio and the requested
aspect ratio. For example, a 1600x900 image cropped with a 1x1 aspect ratio will become 900x900. A
1600x1100 image cropped with a 16x9 aspect ratio will become 1600x900.
Supported ext file extensions include png, jpg, and webp
An example of usage could be
GET /image/process.jpg?src=asdf.png&thumbnail=256&blur=3.0
which would create a 256x256px JPEG thumbnail and blur it
GET /image/details/process.{ext}?src={file}&... for getting the details of a processed image.
The returned JSON is the same format as listed for the full-resolution details endpoint.
DELETE /image/delete/{delete_token}/{file} or GET /image/delete/{delete_token}/{file} to
delete a file, where delete_token and file are from the /image endpoint’s JSON
Configuring the secure-api-key is not included yet. The envisioned basic use case is consumption on localhost by other services without exposing the service to the internet.
Table of Contents
OpenCloud is an open-source, modern file-sync and sharing platform. It is a fork of oCIS, a ground-up rewrite of the well-known PHP-based NextCloud server.
The service can be configured using a combination of services.opencloud.settings,
services.opencloud.environment and services.opencloud.environmentFile.
OpenCloud is configured using a combination of YAML and environment variables. The full documentation can be found at OpenCloud Admin Docs.
The general flow of configuring OpenCloud is:
configure services with services.opencloud.settings.<service> when possible
configure global settings that affect multiple services via services.opencloud.environment
allow NixOS to provision a default opencloud.yaml for you, containing default credentials
for communication between the microservices
provide additional secrets via environmentFile, provisioned out of band
Please note that current NixOS module for OpenCloud is configured to run in
fullstack mode, which starts all the services for OpenCloud in a single
instance, in so called supervised mode. This will start multiple OpenCloud
services and listen on multiple other ports.
Current known services and their ports are as below:
| Service | Group | Port |
|---|---|---|
| gateway | api | 9142 |
| sharing | api | 9150 |
| app-registry | api | 9242 |
| ocdav | web | 45023 |
| auth-machine | api | 9166 |
| storage-system | api | 9215 |
| webdav | web | 9115 |
| webfinger | web | 46871 |
| storage-system | web | 9216 |
| web | web | 9100 |
| eventhistory | api | 33177 |
| ocs | web | 9110 |
| storage-publiclink | api | 9178 |
| settings | web | 9190 |
| ocm | api | 9282 |
| settings | api | 9191 |
| ocm | web | 9280 |
| app-provider | api | 9164 |
| storage-users | api | 9157 |
| auth-service | api | 9199 |
| thumbnails | web | 9186 |
| thumbnails | api | 9185 |
| storage-shares | api | 9154 |
| sse | sse | 46833 |
| userlog | userlog | 45363 |
| search | api | 9220 |
| proxy | web | 9200 |
| idp | web | 9130 |
| frontend | web | 9140 |
| groups | api | 9160 |
| graph | graph | 9120 |
| users | api | 9144 |
| auth-basic | api | 9146 |
Table of Contents
Nextcloud is an open-source,
self-hostable cloud platform. The server setup can be automated using
services.nextcloud. A
desktop client is packaged at pkgs.nextcloud-client.
The current default by NixOS is nextcloud32 which is also the latest
major version available.
Nextcloud is a PHP-based application which requires an HTTP server
(services.nextcloud
and optionally supports
services.nginx).
For the database, you can set
services.nextcloud.config.dbtype to
either sqlite (the default), mysql, or pgsql. The simplest is sqlite,
which will be automatically created and managed by the application. For the
last two, you can easily create a local database by setting
services.nextcloud.database.createLocally
to true, Nextcloud will automatically be configured to connect to it through
socket.
A very basic configuration may look like this:
{ pkgs, ... }:
{
services.nextcloud = {
enable = true;
hostName = "nextcloud.tld";
database.createLocally = true;
config = {
dbtype = "pgsql";
adminpassFile = "/path/to/admin-pass-file";
};
};
networking.firewall.allowedTCPPorts = [
80
443
];
}
The hostName option is used internally to configure an HTTP
server using PHP-FPM
and nginx. The config attribute set is
used by the imperative installer and all values are written to an additional file
to ensure that changes can be applied by changing the module’s options.
In case the application serves multiple domains (those are checked with
$_SERVER['HTTP_HOST'])
it’s needed to add them to
services.nextcloud.settings.trusted_domains.
Auto updates for Nextcloud apps can be enabled using
services.nextcloud.autoUpdateApps.
nextcloud-occ The management command occ can be
invoked by using the nextcloud-occ wrapper that’s globally available on a system with Nextcloud enabled.
It requires elevated permissions to become the nextcloud user. Given the way the privilege
escalation is implemented, parameters passed via the environment to Nextcloud are
currently ignored, except for OC_PASS and NC_PASS.
Custom service units that need to run nextcloud-occ either need elevated privileges
or the systemd configuration from nextcloud-setup.service (recommended):
{ config, ... }:
{
systemd.services.my-custom-service = {
script = ''
nextcloud-occ …
'';
serviceConfig = {
inherit (config.systemd.services.nextcloud-cron.serviceConfig)
User
LoadCredential
KillMode
;
};
};
}
Please note that the options required are subject to change. Please make sure to read the release notes when upgrading.
General notes.
Unfortunately Nextcloud appears to be very stateful when it comes to
managing its own configuration. The config file lives in the home directory
of the nextcloud user (by default
/var/lib/nextcloud/config/config.php) and is also used to
track several states of the application (e.g., whether installed or not).
All configuration parameters are also stored in
/var/lib/nextcloud/config/override.config.php which is generated by
the module and linked from the store to ensure that all values from
config.php can be modified by the module.
However config.php manages the application’s state and shouldn’t be
touched manually because of that.
Don’t delete config.php! This file
tracks the application’s state and a deletion can cause unwanted
side-effects!
Don’t rerun nextcloud-occ maintenance:install!
This command tries to install the application
and can cause unwanted side-effects!
Multiple version upgrades.
Nextcloud doesn’t allow to move more than one major-version forward. E.g., if you’re on
v16, you cannot upgrade to v18, you need to upgrade to
v17 first. This is ensured automatically as long as the
stateVersion is declared properly. In that case
the oldest version available (one major behind the one from the previous NixOS
release) will be selected by default and the module will generate a warning that reminds
the user to upgrade to latest Nextcloud after that deploy.
Error: Command "upgrade" is not defined.
This error usually occurs if the initial installation
(nextcloud-occ maintenance:install) has failed. After that, the application
is not installed, but the upgrade is attempted to be executed. Further context can
be found in NixOS/nixpkgs#111175.
First of all, it makes sense to find out what went wrong by looking at the logs of the installation via journalctl -u nextcloud-setup and try to fix the underlying issue.
If this occurs on an existing setup, this is most likely because the maintenance mode is active. It can be deactivated by running nextcloud-occ maintenance:mode --off. It’s advisable though to check the logs first on why the maintenance mode was activated.
Only perform the following measures on freshly installed instances!
A re-run of the installer can be forced by deleting
/var/lib/nextcloud/config/config.php. This is the only time
advisable because the fresh install doesn’t have any state that can be lost.
In case that doesn’t help, an entire re-creation can be forced via
rm -rf ~nextcloud/.
Server-side encryption. Nextcloud supports server-side encryption (SSE). This is not an end-to-end encryption, but can be used to encrypt files that will be persisted to external storage such as S3.
Issues with file permissions / unsafe path transitions
systemd-tmpfiles(8) makes sure that the paths for
configuration (including declarative config)
data
app store
home directory itself (usually /var/lib/nextcloud)
are properly set up. However, systemd-tmpfiles will refuse to do so
if it detects an unsafe path transition, i.e. creating files/directories
within a directory that is neither owned by root nor by nextcloud, the
owning user of the files/directories to be created.
Symptoms of that include
config/override.config.php not being updated (and the config file
eventually being garbage-collected).
failure to read from application data.
To work around that, please make sure that all directories in question
are owned by nextcloud:nextcloud.
Failed to open stream: No such file or directory after deploys
Symptoms are errors like this after a deployment that disappear after a few minutes:
Warning: file_get_contents(/run/secrets/nextcloud_db_password): Failed to open stream: No such file or directory in /nix/store/lqw657xbh6h67ccv9cgv104qhcs1i2vw-nextcloud-config.php on line 11
Warning: http_response_code(): Cannot set response code - headers already sent (output started at /nix/store/lqw657xbh6h67ccv9cgv104qhcs1i2vw-nextcloud-config.php:11) in /nix/store/ikxpaq7kjdhpr4w7cgl1n28kc2gvlhg6-nextcloud-29.0.7/lib/base.php on line 639
Cannot decode /run/secrets/nextcloud_secrets, because: Syntax error
This can happen if services.nextcloud.secretFile or
services.nextcloud.config.dbpassFile are managed by
sops-nix.
Here, /run/secrets/nextcloud_secrets is a symlink to
/run/secrets.d/N/nextcloud_secrets. The N will be incremented
when the sops-nix activation script runs, i.e.
/run/secrets.d/N doesn’t exist anymore after a deploy,
only /run/secrets.d/N+1.
PHP maintains a cache for realpath
that still resolves to the old path which is causing
the No such file or directory error. Interestingly,
the cache isn’t used for file_exists which is why this warning
comes instead of the error from nix_read_secret in
override.config.php.
One option to work around this is to turn off the cache by setting the cache size to zero:
{ services.nextcloud.phpOptions."realpath_cache_size" = "0"; }
Empty Files on chunked uploads
Due to a limitation of PHP-FPM, Nextcloud is unable to handle chunked uploads. See upstream issue nextcloud/server#7995 for details.
A workaround is to disable chunked uploads with
nextcloud.nginx.enableFastcgiRequestBuffering.
httpd) By default, nginx is used as reverse-proxy for nextcloud.
However, it’s possible to use e.g. httpd by explicitly disabling
nginx using services.nginx.enable and fixing the
settings listen.owner & listen.group in the
phpfpm pool nextcloud.
Nextcloud apps are installed statefully through the web interface.
Some apps may require extra PHP extensions to be installed.
This can be configured with the services.nextcloud.phpExtraExtensions setting.
Alternatively, extra apps can also be declared with the services.nextcloud.extraApps setting.
When using this setting, apps can no longer be managed statefully because this can lead to Nextcloud updating apps
that are managed by Nix:
{ config, pkgs, ... }:
{
services.nextcloud.extraApps = with config.services.nextcloud.package.packages.apps; {
inherit user_oidc calendar contacts;
};
}
Keep in mind that this is essentially a mirror of the apps from the appstore, but managed in nixpkgs. This is by no means a curated list of apps that receive special testing on each update.
If you want automatic updates it is recommended that you use web interface to install apps.
This is because
our module writes logs into the journal (journalctl -t Nextcloud)
the Logreader application that allows reading logs in the admin panel is enabled by default and requires logs written to a file.
If you want to view logs in the admin panel,
set services.nextcloud.settings.log_type to “file”.
If you prefer logs in the journal, disable the logreader application to shut up the “info”. We can’t really do that by default since whether apps are enabled/disabled is part of the application’s state and tracked inside the database.
As stated in the previous paragraph, we must provide a clean upgrade-path for Nextcloud since it cannot move more than one major version forward on a single upgrade. This chapter adds some notes how Nextcloud updates should be rolled out in the future.
While minor and patch-level updates are no problem and can be done directly in the
package-expression (and should be backported to supported stable branches after that),
major-releases should be added in a new attribute (e.g. Nextcloud v19.0.0
should be available in nixpkgs as pkgs.nextcloud19).
To provide simple upgrade paths it’s generally useful to backport those as well to stable
branches. As long as the package-default isn’t altered, this won’t break existing setups.
After that, the versioning-warning in the nextcloud-module should be
updated to make sure that the
package-option selects the latest version
on fresh setups.
If major-releases will be abandoned by upstream, we should check first if those are needed
in NixOS for a safe upgrade-path before removing those. In that case we should keep those
packages, but mark them as insecure in an expression like this (in
<nixpkgs/pkgs/servers/nextcloud/default.nix>):
# ...
{
nextcloud17 = generic {
version = "17.0.x";
sha256 = "0000000000000000000000000000000000000000000000000000";
eol = true;
};
}
Ideally we should make sure that it’s possible to jump two NixOS versions forward: i.e. the warnings and the logic in the module should guard a user to upgrade from a Nextcloud on e.g. 19.09 to a Nextcloud on 20.09.
Table of Contents
Matomo is a real-time web analytics application. This module configures php-fpm as backend for Matomo, optionally configuring an nginx vhost as well.
An automatic setup is not supported by Matomo, so you need to configure Matomo itself in the browser-based Matomo setup.
You also need to configure a MariaDB or MySQL database and -user for Matomo yourself, and enter those credentials in your browser. You can use passwordless database authentication via the UNIX_SOCKET authentication plugin with the following SQL commands:
# For MariaDB
INSTALL PLUGIN unix_socket SONAME 'auth_socket';
CREATE DATABASE matomo;
CREATE USER 'matomo'@'localhost' IDENTIFIED WITH unix_socket;
GRANT ALL PRIVILEGES ON matomo.* TO 'matomo'@'localhost';
# For MySQL
INSTALL PLUGIN auth_socket SONAME 'auth_socket.so';
CREATE DATABASE matomo;
CREATE USER 'matomo'@'localhost' IDENTIFIED WITH auth_socket;
GRANT ALL PRIVILEGES ON matomo.* TO 'matomo'@'localhost';
Then fill in matomo as database user and database name,
and leave the password field blank. This authentication works by allowing
only the matomo unix user to authenticate as the
matomo database user (without needing a password), but no
other users. For more information on passwordless login, see
https://mariadb.com/kb/en/mariadb/unix_socket-authentication-plugin/.
Of course, you can use password based authentication as well, e.g. when the database is not on the same host.
This module comes with the systemd service
matomo-archive-processing.service and a timer that
automatically triggers archive processing every hour. This means that you
can safely
disable browser triggers for Matomo archiving at
Administration > System > General Settings.
With automatic archive processing, you can now also enable to
delete old visitor logs
at Administration > System > Privacy, but make sure that you run systemctl start matomo-archive-processing.service at least once without errors if
you have already collected data before, so that the reports get archived
before the source data gets deleted.
You only need to take backups of your MySQL database and the
/var/lib/matomo/config/config.ini.php file. Use a user
in the matomo group or root to access the file. For more
information, see
https://matomo.org/faq/how-to-install/faq_138/.
Matomo will warn you that the JavaScript tracker is not writable. This is because it’s located in the read-only nix store. You can safely ignore this, unless you need a plugin that needs JavaScript tracker access.
You can use other web servers by forwarding calls for
index.php and piwik.php to the
services.phpfpm.pools.<name>.socket
fastcgi unix socket. You can use
the nginx configuration in the module code as a reference to what else
should be configured.
Table of Contents
Lemmy is a federated alternative to reddit in rust.
The minimum to start lemmy is
{
services.lemmy = {
enable = true;
settings = {
hostname = "lemmy.union.rocks";
database.createLocally = true;
};
caddy.enable = true;
};
}
This will start the backend on port 8536 and the frontend on port 1234. It will expose your instance with a caddy reverse proxy to the hostname you’ve provided. Postgres will be initialized on that same instance automatically.
On first connection you will be asked to define an admin user.
Exposing with nginx is not implemented yet.
This has been tested using a local database with a unix socket connection. Using different database settings will likely require modifications
Table of Contents
Keycloak is an open source identity and access management server with support for OpenID Connect, OAUTH 2.0 and SAML 2.0.
An administrative user with the username
admin is automatically created in the
master realm. Its initial password can be
configured by setting services.keycloak.initialAdminPassword
and defaults to changeme. The password is
not stored safely and should be changed immediately in the
admin panel.
Refer to the Keycloak Server Administration Guide for information on how to administer your Keycloak instance.
Keycloak can be used with either PostgreSQL, MariaDB or
MySQL. Which one is used can be
configured in services.keycloak.database.type. The selected
database will automatically be enabled and a database and role
created unless services.keycloak.database.host is changed
from its default of localhost or
services.keycloak.database.createLocally is set to false.
External database access can also be configured by setting
services.keycloak.database.host,
services.keycloak.database.name,
services.keycloak.database.username,
services.keycloak.database.useSSL and
services.keycloak.database.caCert as
appropriate. Note that you need to manually create the database
and allow the configured database user full access to it.
services.keycloak.database.passwordFile
must be set to the path to a file containing the password used
to log in to the database. If services.keycloak.database.host
and services.keycloak.database.createLocally
are kept at their defaults, the database role
keycloak with that password is provisioned
on the local database instance.
The path should be provided as a string, not a Nix path, since Nix paths are copied into the world readable Nix store.
The hostname is used to build the public URL used as base for
all frontend requests and must be configured through
services.keycloak.settings.hostname.
If you’re migrating an old Wildfly based Keycloak instance
and want to keep compatibility with your current clients,
you’ll likely want to set services.keycloak.settings.http-relative-path
to /auth. See the option description
for more details.
services.keycloak.settings.hostname-backchannel-dynamic
Keycloak has the capability to offer a separate URL for backchannel requests,
enabling internal communication while maintaining the use of a public URL
for frontchannel requests. Moreover, the backchannel is dynamically
resolved based on incoming headers endpoint.
For more information on hostname configuration, see the Hostname section of the Keycloak Server Installation and Configuration Guide.
By default, Keycloak won’t accept unsecured HTTP connections originating from outside its local network.
HTTPS support requires a TLS/SSL certificate and a private key,
both PEM formatted.
Their paths should be set through
services.keycloak.sslCertificate and
services.keycloak.sslCertificateKey.
The paths should be provided as a strings, not a Nix paths, since Nix paths are copied into the world readable Nix store.
You can package custom themes and make them visible to
Keycloak through services.keycloak.themes. See the
Themes section of the Keycloak Server Development Guide and the description of the aforementioned NixOS option for
more information.
Keycloak server configuration parameters can be set in
services.keycloak.settings. These correspond
directly to options in
conf/keycloak.conf. Some of the most
important parameters are documented as suboptions, the rest can
be found in the All
configuration section of the Keycloak Server Installation and
Configuration Guide.
Options containing secret data should be set to an attribute
set containing the attribute _secret - a
string pointing to a file containing the value the option
should be set to. See the description of
services.keycloak.settings for an example.
A basic configuration with some custom settings could look like this:
{
services.keycloak = {
enable = true;
settings = {
hostname = "keycloak.example.com";
hostname-strict-backchannel = true;
};
initialAdminPassword = "e6Wcm0RrtegMEHl"; # change on first login
sslCertificate = "/run/keys/ssl_cert";
sslCertificateKey = "/run/keys/ssl_key";
database.passwordFile = "/run/keys/db_password";
};
}
Table of Contents
With Jitsi Meet on NixOS you can quickly configure a complete, private, self-hosted video conferencing solution.
A minimal configuration using Let’s Encrypt for TLS certificates looks like this:
{
services.jitsi-meet = {
enable = true;
hostName = "jitsi.example.com";
};
services.jitsi-videobridge.openFirewall = true;
networking.firewall.allowedTCPPorts = [
80
443
];
security.acme.email = "[email protected]";
security.acme.acceptTerms = true;
}
Jitsi Meet depends on the Prosody XMPP server only for message passing from
the web browser while the default Prosody configuration is intended for use
with standalone XMPP clients and XMPP federation. If you only use Prosody as
a backend for Jitsi Meet it is therefore recommended to also enable
services.jitsi-meet.prosody.lockdown option to disable unnecessary
Prosody features such as federation or the file proxy.
Here is the minimal configuration with additional configurations:
{
services.jitsi-meet = {
enable = true;
hostName = "jitsi.example.com";
prosody.lockdown = true;
config = {
enableWelcomePage = false;
prejoinPageEnabled = true;
defaultLang = "fi";
};
interfaceConfig = {
SHOW_JITSI_WATERMARK = false;
SHOW_WATERMARK_FOR_GUESTS = false;
};
};
services.jitsi-videobridge.openFirewall = true;
networking.firewall.allowedTCPPorts = [
80
443
];
security.acme.email = "[email protected]";
security.acme.acceptTerms = true;
}
Table of Contents
Immich is a self-hosted photo and video management solution, similar to SaaS offerings like Google Photos.
pgvecto-rs to VectorChord (pre-25.11 installations) Immich instances that were setup before 25.11 (as in
system.stateVersion = 25.11;) will be automatically migrated to VectorChord.
Note that this migration is not reversible, so database dumps should be created
if desired.
See Immich documentation for more details about the automatic migration.
After a successful migration, pgvecto-rs should be removed from the database
installation, unless other applications depend on it.
Make sure VectorChord is enabled (services.immich.database.enableVectorChord) and Immich has completed the migration. Refer to the Immich documentation for details.
Run the following two statements in the PostgreSQL database using a superuser role in Immich’s database.
DROP EXTENSION vectors;
DROP SCHEMA vectors;
You may use the following command to run these statements against the database: sudo -u postgres psql immich (Replace immich with the value of services.immich.database.name)
Disable pgvecto-rs by setting services.immich.database.enableVectors to false.
Rebuild and switch.
Table of Contents
With Honk on NixOS you can quickly configure a complete ActivityPub server with minimal setup and support costs.
A minimal configuration looks like this:
{
services.honk = {
enable = true;
host = "0.0.0.0";
port = 8080;
username = "username";
passwordFile = "/etc/honk/password.txt";
servername = "honk.example.com";
};
networking.firewall.allowedTCPPorts = [ 8080 ];
}
Table of Contents
Hatsu is an fully-automated ActivityPub bridge for static sites.
The minimum configuration to start hatsu server would look like this:
{
services.hatsu = {
enable = true;
settings = {
HATSU_DOMAIN = "hatsu.local";
HATSU_PRIMARY_ACCOUNT = "example.com";
};
};
}
this will start the hatsu server on port 3939 and save the database in /var/lib/hatsu/hatsu.sqlite3.
Please refer to the Hatsu Documentation for additional configuration options.
Table of Contents
Grocy is a web-based self-hosted groceries & household management solution for your home.
A very basic configuration may look like this:
{ pkgs, ... }:
{
services.grocy = {
enable = true;
hostName = "grocy.tld";
};
}
This configures a simple vhost using nginx
which listens to grocy.tld with fully configured ACME/LE (this can be
disabled by setting services.grocy.nginx.enableSSL
to false). After the initial setup the credentials admin:admin
can be used to login.
The application’s state is persisted at /var/lib/grocy/grocy.db in a
sqlite3 database. The migration is applied when requesting the /-route
of the application.
The configuration for grocy is located at /etc/grocy/config.php.
By default, the following settings can be defined in the NixOS-configuration:
{ pkgs, ... }:
{
services.grocy.settings = {
# The default currency in the system for invoices etc.
# Please note that exchange rates aren't taken into account, this
# is just the setting for what's shown in the frontend.
currency = "EUR";
# The display language (and locale configuration) for grocy.
culture = "de";
calendar = {
# Whether or not to show the week-numbers
# in the calendar.
showWeekNumber = true;
# Index of the first day to be shown in the calendar (0=Sunday, 1=Monday,
# 2=Tuesday and so on).
firstDayOfWeek = 2;
};
};
}
If you want to alter the configuration file on your own, you can do this manually with an expression like this:
{ lib, ... }:
{
environment.etc."grocy/config.php".text = lib.mkAfter ''
// Arbitrary PHP code in grocy's configuration file
'';
}
Table of Contents
GoToSocial is an ActivityPub social network server, written in Golang.
The following configuration sets up the PostgreSQL as database backend and binds
GoToSocial to 127.0.0.1:8080, expecting to be run behind a HTTP proxy on gotosocial.example.com.
{
services.gotosocial = {
enable = true;
setupPostgresqlDB = true;
settings = {
application-name = "My GoToSocial";
host = "gotosocial.example.com";
protocol = "https";
bind-address = "127.0.0.1";
port = 8080;
};
};
}
Please refer to the GoToSocial Documentation for additional configuration options.
Although it is possible to expose GoToSocial directly, it is common practice to operate it behind an HTTP reverse proxy such as nginx.
{
networking.firewall.allowedTCPPorts = [
80
443
];
services.nginx = {
enable = true;
clientMaxBodySize = "40M";
virtualHosts = with config.services.gotosocial.settings; {
"${host}" = {
enableACME = true;
forceSSL = true;
locations = {
"/" = {
recommendedProxySettings = true;
proxyWebsockets = true;
proxyPass = "http://${bind-address}:${toString port}";
};
};
};
};
};
}
Please refer to SSL/TLS Certificates with ACME for details on how to provision an SSL/TLS certificate.
After the GoToSocial service is running, the gotosocial-admin utility can be used to manage users. In particular an
administrative user can be created with
$ sudo gotosocial-admin account create --username <nickname> --email <email> --password <password>
$ sudo gotosocial-admin account confirm --username <nickname>
$ sudo gotosocial-admin account promote --username <nickname>
Table of Contents
Glance is a self-hosted dashboard that puts all your feeds in one place.
Visit the Glance project page to learn more about it.
Check out the configuration docs to learn more. Use the following configuration to start a public instance of Glance locally:
{
services.glance = {
enable = true;
settings = {
pages = [
{
name = "Home";
columns = [
{
size = "full";
widgets = [
{ type = "calendar"; }
{
type = "weather";
location = "Nivelles, Belgium";
}
];
}
];
}
];
};
openFirewall = true;
};
}
Table of Contents
Discourse is a modern and open source discussion platform.
A minimal configuration using Let’s Encrypt for TLS certificates looks like this:
{
services.discourse = {
enable = true;
hostname = "discourse.example.com";
admin = {
email = "[email protected]";
username = "admin";
fullName = "Administrator";
passwordFile = "/path/to/password_file";
};
secretKeyBaseFile = "/path/to/secret_key_base_file";
};
security.acme.email = "[email protected]";
security.acme.acceptTerms = true;
}
Provided a proper DNS setup, you’ll be able to connect to the
instance at discourse.example.com and log in
using the credentials provided in
services.discourse.admin.
To set up TLS using a regular certificate and key on file, use
the services.discourse.sslCertificate
and services.discourse.sslCertificateKey
options:
{
services.discourse = {
enable = true;
hostname = "discourse.example.com";
sslCertificate = "/path/to/ssl_certificate";
sslCertificateKey = "/path/to/ssl_certificate_key";
admin = {
email = "[email protected]";
username = "admin";
fullName = "Administrator";
passwordFile = "/path/to/password_file";
};
secretKeyBaseFile = "/path/to/secret_key_base_file";
};
}
Discourse uses PostgreSQL to store most of its
data. A database will automatically be enabled and a database
and role created unless services.discourse.database.host is changed from
its default of null or services.discourse.database.createLocally is set
to false.
External database access can also be configured by setting
services.discourse.database.host,
services.discourse.database.username and
services.discourse.database.passwordFile as
appropriate. Note that you need to manually create a database
called discourse (or the name you chose in
services.discourse.database.name) and
allow the configured database user full access to it.
In addition to the basic setup, you’ll want to configure an SMTP server Discourse can use to send user registration and password reset emails, among others. You can also optionally let Discourse receive email, which enables people to reply to threads and conversations via email.
A basic setup which assumes you want to use your configured hostname as email domain can be done like this:
{
services.discourse = {
enable = true;
hostname = "discourse.example.com";
sslCertificate = "/path/to/ssl_certificate";
sslCertificateKey = "/path/to/ssl_certificate_key";
admin = {
email = "[email protected]";
username = "admin";
fullName = "Administrator";
passwordFile = "/path/to/password_file";
};
mail.outgoing = {
serverAddress = "smtp.emailprovider.com";
port = 587;
username = "[email protected]";
passwordFile = "/path/to/smtp_password_file";
};
mail.incoming.enable = true;
secretKeyBaseFile = "/path/to/secret_key_base_file";
};
}
This assumes you have set up an MX record for the address you’ve set in hostname and requires proper SPF, DKIM and DMARC configuration to be done for the domain you’re sending from, in order for email to be reliably delivered.
If you want to use a different domain for your outgoing email
(for example example.com instead of
discourse.example.com) you should set
services.discourse.mail.notificationEmailAddress and
services.discourse.mail.contactEmailAddress manually.
Setup of TLS for incoming email is currently only configured
automatically when a regular TLS certificate is used, i.e. when
services.discourse.sslCertificate and
services.discourse.sslCertificateKey are
set.
Additional site settings and backend settings, for which no
explicit NixOS options are provided,
can be set in services.discourse.siteSettings and
services.discourse.backendSettings respectively.
“Site settings” are the settings that can be
changed through the Discourse
UI. Their default values can be set using
services.discourse.siteSettings.
Settings are expressed as a Nix attribute set which matches the
structure of the configuration in
config/site_settings.yml.
To find a setting’s path, you only need to care about the first
two levels; i.e. its category (e.g. login)
and name (e.g. invite_only).
Settings containing secret data should be set to an attribute
set containing the attribute _secret - a
string pointing to a file containing the value the option
should be set to. See the example.
Settings are expressed as a Nix attribute set which matches the
structure of the configuration in
config/discourse.conf.
Empty parameters can be defined by setting them to
null.
The following example sets the title and description of the Discourse instance and enables GitHub login in the site settings, and changes a few request limits in the backend settings:
{
services.discourse = {
enable = true;
hostname = "discourse.example.com";
sslCertificate = "/path/to/ssl_certificate";
sslCertificateKey = "/path/to/ssl_certificate_key";
admin = {
email = "[email protected]";
username = "admin";
fullName = "Administrator";
passwordFile = "/path/to/password_file";
};
mail.outgoing = {
serverAddress = "smtp.emailprovider.com";
port = 587;
username = "[email protected]";
passwordFile = "/path/to/smtp_password_file";
};
mail.incoming.enable = true;
siteSettings = {
required = {
title = "My Cats";
site_description = "Discuss My Cats (and be nice plz)";
};
login = {
enable_github_logins = true;
github_client_id = "a2f6dfe838cb3206ce20";
github_client_secret._secret = /run/keys/discourse_github_client_secret;
};
};
backendSettings = {
max_reqs_per_ip_per_minute = 300;
max_reqs_per_ip_per_10_seconds = 60;
max_asset_reqs_per_ip_per_10_seconds = 250;
max_reqs_per_ip_mode = "warn+block";
};
secretKeyBaseFile = "/path/to/secret_key_base_file";
};
}
In the resulting site settings file, the
login.github_client_secret key will be set
to the contents of the
/run/keys/discourse_github_client_secret
file.
You can install Discourse plugins
using the services.discourse.plugins
option. Pre-packaged plugins are provided in
<your_discourse_package_here>.plugins. If
you want the full suite of plugins provided through
nixpkgs, you can also set the services.discourse.package option to
pkgs.discourseAllPlugins.
Plugins can be built with the
<your_discourse_package_here>.mkDiscoursePlugin
function. Normally, it should suffice to provide a
name and src attribute. If
the plugin has Ruby dependencies, however, they need to be
packaged in accordance with the Developing with Ruby
section of the Nixpkgs manual and the
appropriate gem options set in bundlerEnvArgs
(normally gemdir is sufficient). A plugin’s
Ruby dependencies are listed in its
plugin.rb file as function calls to
gem. To construct the corresponding
Gemfile manually, run bundle init, then add the gem lines to it
verbatim.
Much of the packaging can be done automatically by the
nixpkgs/pkgs/servers/web-apps/discourse/update.py
script - just add the plugin to the plugins
list in the update_plugins function and run
the script:
./update.py update-plugins
Some plugins provide site settings.
Their defaults can be configured using services.discourse.siteSettings, just like
regular site settings. To find the names of these settings, look
in the config/settings.yml file of the plugin
repo.
For example, to add the discourse-spoiler-alert
and discourse-solved
plugins, and disable discourse-spoiler-alert
by default:
{
services.discourse = {
enable = true;
hostname = "discourse.example.com";
sslCertificate = "/path/to/ssl_certificate";
sslCertificateKey = "/path/to/ssl_certificate_key";
admin = {
email = "[email protected]";
username = "admin";
fullName = "Administrator";
passwordFile = "/path/to/password_file";
};
mail.outgoing = {
serverAddress = "smtp.emailprovider.com";
port = 587;
username = "[email protected]";
passwordFile = "/path/to/smtp_password_file";
};
mail.incoming.enable = true;
plugins = with config.services.discourse.package.plugins; [
discourse-spoiler-alert
discourse-solved
];
siteSettings = {
plugins = {
spoiler_enabled = false;
};
};
secretKeyBaseFile = "/path/to/secret_key_base_file";
};
}
Table of Contents
Davis is a caldav and carrddav server. It has a simple, fully translatable admin interface for sabre/dav based on Symfony 5 and Bootstrap 5, initially inspired by Baïkal.
At first, an application secret is needed, this can be generated with:
$ cat /dev/urandom | tr -dc a-zA-Z0-9 | fold -w 48 | head -n 1
After that, davis can be deployed like this:
{
services.davis = {
enable = true;
hostname = "davis.example.com";
mail = {
dsn = "smtp://[email protected]:25";
inviteFromAddress = "[email protected]";
};
adminLogin = "admin";
adminPasswordFile = "/run/secrets/davis-admin-password";
appSecretFile = "/run/secrets/davis-app-secret";
};
}
This deploys Davis using a sqlite database running out of /var/lib/davis.
Logs can be found in /var/lib/davis/var/log/.
Table of Contents
Castopod is an open-source hosting platform made for podcasters who want to engage and interact with their audience.
Configure ACME (https://nixos.org/manual/nixos/unstable/#module-security-acme).
Use the following configuration to start a public instance of Castopod on castopod.example.com domain:
{
networking.firewall.allowedTCPPorts = [
80
443
];
services.castopod = {
enable = true;
database.createLocally = true;
nginx.virtualHost = {
serverName = "castopod.example.com";
enableACME = true;
forceSSL = true;
};
};
}
Go to https://castopod.example.com/cp-install to create superadmin account after applying the above configuration.
c2FmZQ is an application that can securely encrypt, store, and share files, including but not limited to pictures and videos.
The service c2fmzq-server can be enabled by setting
{ services.c2fmzq-server.enable = true; }
This will spin up an instance of the server which is API-compatible with Stingle Photos and an experimental Progressive Web App (PWA) to interact with the storage via the browser.
In principle the server can be exposed directly on a public interface and there are command line options to manage HTTPS certificates directly, but the module is designed to be served behind a reverse proxy or only accessed via localhost.
{
services.c2fmzq-server = {
enable = true;
bindIP = "127.0.0.1"; # default
port = 8080; # default
};
services.nginx = {
enable = true;
recommendedProxySettings = true;
virtualHosts."example.com" = {
enableACME = true;
forceSSL = true;
locations."/" = {
proxyPass = "http://127.0.0.1:8080";
};
};
};
}
For more information, see https://github.com/c2FmZQ/c2FmZQ/.
Table of Contents
Akkoma is a lightweight ActivityPub microblogging server forked from Pleroma.
The Elixir configuration file required by Akkoma is generated automatically from
services.akkoma.config. Secrets must be
included from external files outside of the Nix store by setting the configuration option to
an attribute set containing the attribute _secret – a string pointing to the file
containing the actual value of the option.
For the mandatory configuration settings these secrets will be generated automatically if the
referenced file does not exist during startup, unless disabled through
services.akkoma.initSecrets.
The following configuration binds Akkoma to the Unix socket /run/akkoma/socket, expecting to
be run behind a HTTP proxy on fediverse.example.com.
{
services.akkoma.enable = true;
services.akkoma.config = {
":pleroma" = {
":instance" = {
name = "My Akkoma instance";
description = "More detailed description";
email = "[email protected]";
registration_open = false;
};
"Pleroma.Web.Endpoint" = {
url.host = "fediverse.example.com";
};
};
};
}
Please refer to the configuration cheat sheet for additional configuration options.
After the Akkoma service is running, the administration utility can be used to manage users. In particular an administrative user can be created with
$ pleroma_ctl user new <nickname> <email> --admin --moderator --password <password>
Although it is possible to expose Akkoma directly, it is common practice to operate it behind an HTTP reverse proxy such as nginx.
{
services.akkoma.nginx = {
enableACME = true;
forceSSL = true;
};
services.nginx = {
enable = true;
clientMaxBodySize = "16m";
recommendedTlsSettings = true;
recommendedOptimisation = true;
recommendedGzipSettings = true;
};
}
Please refer to SSL/TLS Certificates with ACME for details on how to provision an SSL/TLS certificate.
Without the media proxy function, Akkoma does not store any remote media like pictures or video locally, and clients have to fetch them directly from the source server.
{
# Enable nginx slice module distributed with Tengine
services.nginx.package = pkgs.tengine;
# Enable media proxy
services.akkoma.config.":pleroma".":media_proxy" = {
enabled = true;
proxy_opts.redirect_on_failure = true;
};
# Adjust the persistent cache size as needed:
# Assuming an average object size of 128 KiB, around 1 MiB
# of memory is required for the key zone per GiB of cache.
# Ensure that the cache directory exists and is writable by nginx.
services.nginx.commonHttpConfig = ''
proxy_cache_path /var/cache/nginx/cache/akkoma-media-cache
levels= keys_zone=akkoma_media_cache:16m max_size=16g
inactive=1y use_temp_path=off;
'';
services.akkoma.nginx = {
locations."/proxy" = {
proxyPass = "http://unix:/run/akkoma/socket";
extraConfig = ''
proxy_cache akkoma_media_cache;
# Cache objects in slices of 1 MiB
slice 1m;
proxy_cache_key $host$uri$is_args$args$slice_range;
proxy_set_header Range $slice_range;
# Decouple proxy and upstream responses
proxy_buffering on;
proxy_cache_lock on;
proxy_ignore_client_abort on;
# Default cache times for various responses
proxy_cache_valid 200 1y;
proxy_cache_valid 206 301 304 1h;
# Allow serving of stale items
proxy_cache_use_stale error timeout invalid_header updating;
'';
};
};
}
The following example enables the MediaProxyWarmingPolicy MRF policy which automatically
fetches all media associated with a post through the media proxy, as soon as the post is
received by the instance.
{
services.akkoma.config.":pleroma".":mrf".policies = map (pkgs.formats.elixirConf { }).lib.mkRaw [
"Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy"
];
}
Akkoma can generate previews for media.
{
services.akkoma.config.":pleroma".":media_preview_proxy" = {
enabled = true;
thumbnail_max_width = 1920;
thumbnail_max_height = 1080;
};
}
Akkoma will be deployed with the akkoma-fe and admin-fe frontends by default. These can be
modified by setting
services.akkoma.frontends.
The following example overrides the primary frontend’s default configuration using a custom derivation.
{
services.akkoma.frontends.primary.package =
pkgs.runCommand "akkoma-fe"
{
config = builtins.toJSON {
expertLevel = 1;
collapseMessageWithSubject = false;
stopGifs = false;
replyVisibility = "following";
webPushHideIfCW = true;
hideScopeNotice = true;
renderMisskeyMarkdown = false;
hideSiteFavicon = true;
postContentType = "text/markdown";
showNavShortcuts = false;
};
nativeBuildInputs = with pkgs; [
jq
xorg.lndir
];
passAsFile = [ "config" ];
}
''
mkdir $out
lndir ${pkgs.akkoma-frontends.akkoma-fe} $out
rm $out/static/config.json
jq -s add ${pkgs.akkoma-frontends.akkoma-fe}/static/config.json ${config} \
>$out/static/config.json
'';
}
Akkoma comes with a number of modules to police federation with other ActivityPub instances.
The most valuable for typical users is the
:mrf_simple module
which allows limiting federation based on instance hostnames.
This configuration snippet provides an example on how these can be used. Choosing an adequate federation policy is not trivial and entails finding a balance between connectivity to the rest of the fediverse and providing a pleasant experience to the users of an instance.
{
services.akkoma.config.":pleroma" = with (pkgs.formats.elixirConf { }).lib; {
":mrf".policies = map mkRaw [ "Pleroma.Web.ActivityPub.MRF.SimplePolicy" ];
":mrf_simple" = {
# Tag all media as sensitive
media_nsfw = mkMap { "nsfw.weird.kinky" = "Untagged NSFW content"; };
# Reject all activities except deletes
reject = mkMap {
"kiwifarms.cc" = "Persistent harassment of users, no moderation";
};
# Force posts to be visible by followers only
followers_only = mkMap {
"beta.birdsite.live" = "Avoid polluting timelines with Twitter posts";
};
};
};
}
This example strips GPS and location metadata from uploads, deduplicates them and anonymises the the file name.
{
services.akkoma.config.":pleroma"."Pleroma.Upload".filters =
map (pkgs.formats.elixirConf { }).lib.mkRaw
[
"Pleroma.Upload.Filter.Exiftool"
"Pleroma.Upload.Filter.Dedupe"
"Pleroma.Upload.Filter.AnonymizeFilename"
];
}
Pleroma instances can be migrated to Akkoma either by copying the database and upload data or by pointing Akkoma to the existing data. The necessary database migrations are run automatically during startup of the service.
The configuration has to be copy‐edited manually.
Depending on the size of the database, the initial migration may take a long time and exceed the
startup timeout of the system manager. To work around this issue one may adjust the startup timeout
systemd.services.akkoma.serviceConfig.TimeoutStartSec or simply run the migrations
manually:
pleroma_ctl migrate
Copying the Pleroma data instead of re‐using it in place may permit easier reversion to Pleroma, but allows the two data sets to diverge.
First disable Pleroma and then copy its database and upload data:
# Create a copy of the database
nix-shell -p postgresql --run 'createdb -T pleroma akkoma'
# Copy upload data
mkdir /var/lib/akkoma
cp -R --reflink=auto /var/lib/pleroma/uploads /var/lib/akkoma/
After the data has been copied, enable the Akkoma service and verify that the migration has been successful. If no longer required, the original data may then be deleted:
# Delete original database
nix-shell -p postgresql --run 'dropdb pleroma'
# Delete original Pleroma state
rm -r /var/lib/pleroma
To re‐use the Pleroma data in place, disable Pleroma and enable Akkoma, pointing it to the Pleroma database and upload directory.
{
# Adjust these settings according to the database name and upload directory path used by Pleroma
services.akkoma.config.":pleroma"."Pleroma.Repo".database = "pleroma";
services.akkoma.config.":pleroma".":instance".upload_dir = "/var/lib/pleroma/uploads";
}
Please keep in mind that after the Akkoma service has been started, any migrations applied by
Akkoma have to be rolled back before the database can be used again with Pleroma. This can be
achieved through pleroma_ctl ecto.rollback. Refer to the
Ecto SQL documentation for
details.
The Akkoma systemd service may be confined to a chroot with
{ services.systemd.akkoma.confinement.enable = true; }
Confinement of services is not generally supported in NixOS and therefore disabled by default. Depending on the Akkoma configuration, the default confinement settings may be insufficient and lead to subtle errors at run time, requiring adjustment:
Use
services.systemd.akkoma.confinement.packages
to make packages available in the chroot.
services.systemd.akkoma.serviceConfig.BindPaths and
services.systemd.akkoma.serviceConfig.BindReadOnlyPaths permit access to outside paths
through bind mounts. Refer to
BindPaths=
of systemd.exec(5) for details.
Being an Elixir application, Akkoma can be deployed in a distributed fashion.
This requires setting
services.akkoma.dist.address and
services.akkoma.dist.cookie. The
specifics depend strongly on the deployment environment. For more information please check the
relevant Erlang documentation.
The systemd-lock-handler module provides a service that bridges
D-Bus events from logind to user-level systemd targets:
lock.target started by loginctl lock-session,
unlock.target started by loginctl unlock-session and
sleep.target started by systemctl suspend.
You can create a user service that starts with any of these targets.
For example, to create a service for swaylock:
{
services.systemd-lock-handler.enable = true;
systemd.user.services.swaylock = {
description = "Screen locker for Wayland";
documentation = [ "man:swaylock(1)" ];
# If swaylock exits cleanly, unlock the session:
onSuccess = [ "unlock.target" ];
# When lock.target is stopped, stops this too:
partOf = [ "lock.target" ];
# Delay lock.target until this service is ready:
before = [ "lock.target" ];
wantedBy = [ "lock.target" ];
serviceConfig = {
# systemd will consider this service started when swaylock forks...
Type = "forking";
# ... and swaylock will fork only after it has locked the screen.
ExecStart = "${lib.getExe pkgs.swaylock} -f";
# If swaylock crashes, always restart it immediately:
Restart = "on-failure";
RestartSec = 0;
};
};
}
See upstream documentation for more information.
Table of Contents
Kerberos is a computer-network authentication protocol that works on the basis of tickets to allow nodes communicating over a non-secure network to prove their identity to one another in a secure manner.
This module provides both the MIT and Heimdal implementations of the a Kerberos server.
To enable a Kerberos server:
{
security.krb5 = {
# Here you can choose between the MIT and Heimdal implementations.
package = pkgs.krb5;
# package = pkgs.heimdal;
# Optionally set up a client on the same machine as the server
enable = true;
settings = {
libdefaults.default_realm = "EXAMPLE.COM";
realms."EXAMPLE.COM" = {
kdc = "kerberos.example.com";
admin_server = "kerberos.example.com";
};
};
};
services.kerberos-server = {
enable = true;
settings = {
realms."EXAMPLE.COM" = {
acl = [
{
principal = "adminuser";
access = [
"add"
"cpw"
];
}
];
};
};
};
}
The Heimdal documentation will sometimes assume that state is stored in /var/heimdal, but this module uses /var/lib/heimdal instead.
Due to the heimdal implementation being chosen through security.krb5.package, it is not possible to have a system with one implementation of the client and another of the server.
While services.kerberos_server.settings has a common freeform type between the two implementations, the actual settings that can be set can vary between the two implementations. To figure out what settings are available, you should consult the upstream documentation for the implementation you are using.
MIT Kerberos homepage: https://web.mit.edu/kerberos
MIT Kerberos docs: https://web.mit.edu/kerberos/krb5-latest/doc/index.html
Heimdal Kerberos GitHub wiki: https://github.com/heimdal/heimdal/wiki
Heimdal kerberos doc manpages (Debian unstable): https://manpages.debian.org/unstable/heimdal-docs/index.html
Heimdal Kerberos kdc manpages (Debian unstable): https://manpages.debian.org/unstable/heimdal-kdc/index.html
Note the version number in the URLs, it may be different for the latest version.
Table of Contents
Meilisearch is a lightweight, fast and powerful search engine. Think elastic search with a much smaller footprint.
the minimum to start meilisearch is
{ services.meilisearch.enable = true; }
this will start the http server included with meilisearch on port 7700.
test with curl -X GET 'http://localhost:7700/health'
you first need to add documents to an index before you can search for documents.
movies index curl -X POST 'http://127.0.0.1:7700/indexes/movies/documents' --data '[{"id": "123", "title": "Superman"}, {"id": 234, "title": "Batman"}]'
movies index curl 'http://127.0.0.1:7700/indexes/movies/search' --data '{ "q": "botman" }' (note the typo is intentional and there to demonstrate the typo tolerant capabilities)
The default nixos package doesn’t come with the dashboard, since the dashboard features makes some assets downloads at compile time.
no_analytics is set to true by default.
http_addr is derived from services.meilisearch.listenAddress and services.meilisearch.listenPort. The two sub-fields are separate because this makes it easier to consume in certain other modules.
db_path is set to /var/lib/meilisearch by default. Upstream, the default value is equivalent to /var/lib/meilisearch/data.ms.
dump_dir and snapshot_dir are set to /var/lib/meilisearch/dumps and /var/lib/meilisearch/snapshots, respectively. This is equivalent to the upstream defaults.
All other options inherit their upstream defaults. In particular, the default configuration uses env = "development", which doesn’t require a master key, in which case all routes are unprotected.
Table of Contents
Source: modules/services/networking/yggdrasil/default.nix
Upstream documentation: