From NixOS Wiki
Revision as of 11:05, 6 April 2024 by Maintenance script (talk | contribs) (rollback unauthorized mass edits)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Warning: When setting up impermanence, make sure that you have declared password for your user to be able to log-in after the deployment as for example the nixos installer declares passwords imperatively.

Impermanence in NixOS is where your root directory gets wiped every reboot (such as by mounting a tmpfs to /). Such a setup is possible because NixOS only needs /boot and /nix in order to boot, all other system files are simply links to files in /nix. /boot and /nix still need to be stored on a hard drive or SSD.

Example hardware-configuration.nix settings:

  fileSystems."/" =
    { device = "none";
      fsType = "tmpfs";
      options = [ "size=3G" "mode=755" ]; # mode=755 so only root can write to those files
  fileSystems."/home/username" =
    { device = "none";
      fsType = "tmpfs";  # Can be stored on normal drive or on tmpfs as well
      options = [ "size=4G" "mode=777" ]; 
  fileSystems."/nix" =  # can be LUKS encrypted
    { device = "/dev/disk/by-uuid/UUID";
      fsType = "ext4";
  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/UUID";
      fsType = "vfat";
  # Can mount any other partitions as well


Some files and folders should be persisted between reboots though (such as /etc/nixos/). This can be accomplished through bind mounts or by using the NixOS Impermanence module, which will set up bind mounts and links as needed.

Put in configuration.nix:

{ config, pkgs, ... }:

  impermanence = builtins.fetchTarball "";
  imports = [ "${impermanence}/nixos.nix" ];

  environment.persistence."/nix/persist/system" = {
    hideMounts = true;
    directories = [
      { directory = "/var/lib/colord"; user = "colord"; group = "colord"; mode = "u=rwx,g=rx,o="; }
    files = [
      { file = "/etc/nix/id_rsa"; parentDirectory = { mode = "u=rwx,g=,o="; }; }

Home Managing

You can just make a home partition on a drive and mount it as normal, so everything in /home or /home/username will be persisted. If you want your home to be impermanent as well, then mount it on tmpfs the same way as root.

For persisting files in your home, you could simply use Home Manager like normal. However, then files are stored read-only in the Nix store. In order to persist files while still being writable, you can use the Home Manager Impermanence module. It will fuse mount folders and link files from persistent storage into your home directory.

Note: /home/user should be on a separate tmpfs, otherwise you'll get the error fuse: mountpoint not empty.

Put in configuration.nix:

{ config, pkgs, ... }:
  home-manager = builtins.fetchTarball "";
  impermanence = builtins.fetchTarball "";
  imports = [
    (import "${home-manager}/nixos")

  # might not be needed
  programs.fuse.userAllowOther = true;

  # Home Manager config goes in here
  home-manager.users.<username> = {
    home.homeDirectory = "/home/<username>";
    imports = [ "${impermanence}/home-manager.nix" ];

    programs = {
      home-manager.enable = true;
      git = {   # can use home-manager normally as well as with persistence
        enable = true;
        userName  = "Example";
        userEmail = "";

    home.persistence."/nix/dotfiles" = {
      removePrefixDirectory = true;   # for GNU Stow styled dotfile folders
      allowOther = true;
      directories = [

        # fuse mounted from /nix/dotfiles/Firefox/.mozilla to /home/$USERNAME/.mozilla
      files = [

    # fricking KDE Plasma has a bazillion files and each needs to be linked individually
    # because they're all just shoved into ~/.config and not into a single folder.
    # It's separate from the other dotfiles so I can write ".config"
    # instead of "Plasma/.config"
    home.persistence."/nix/dotfiles/Plasma" = {
      removePrefixDirectory = false;
      allowOther = true;
      directories = [
        ".config/gtk-3.0"   # fuse mounted from /nix/dotfiles/Plasma/.config/gtk-3.0
        ".config/gtk-4.0"     # to /home/$USERNAME/.config/gtk-3.0

      files = [


    home.stateVersion = "21.11";


builder for '/nix/store/file-name.service.drv' failed to produce output path for output 'out' at '/nix/store/file-name.service'

This can happen if your NixOS version is later than your Home-Manager version (ex. NixOS 22.05 with Home-Manager 21.11). See

See Also - Examples of using the NixOS modules - Explaining why you might want to do this. Uses ZFS snapshots instead of tmpfs.