Impermanence: Difference between revisions
imported>Klaymore m Replaced $USERNAME with <username> so that it's not confused with normal variables |
add systemd timers folder for allowing Persistent= timers to last across boots |
||
(16 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
{{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 <code>/boot</code> and <code>/nix</code> in order to boot, all other system files are simply links to files in <code>/nix</code>. <code>/boot</code> and <code>/nix</code> still need to be stored on a hard drive or SSD. | 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 <code>/boot</code> and <code>/nix</code> in order to boot, all other system files are simply links to files in <code>/nix</code>. <code>/boot</code> and <code>/nix</code> still need to be stored on a hard drive or SSD. | ||
Example <code> | Example <code>hardware-configuration.nix</code> settings: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
fileSystems."/" = | fileSystems."/" = | ||
Line 29: | Line 31: | ||
Some files and folders should be persisted between reboots though (such as <code>/etc/nixos/</code>). This can be accomplished through bind mounts or by using the [https://github.com/nix-community/impermanence NixOS Impermanence module,] which will set up bind mounts and links as needed. | Some files and folders should be persisted between reboots though (such as <code>/etc/nixos/</code>). This can be accomplished through bind mounts or by using the [https://github.com/nix-community/impermanence NixOS Impermanence module,] which will set up bind mounts and links as needed. | ||
Put in <code>configuration.nix</code>: | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ config, pkgs, ... }: | { config, pkgs, ... }: | ||
Line 39: | Line 42: | ||
imports = [ "${impermanence}/nixos.nix" ]; | imports = [ "${impermanence}/nixos.nix" ]; | ||
environment.persistence."/nix/persist/system" = { | |||
environment.persistence."/nix/persist/system" = { | hideMounts = true; | ||
directories = [ | directories = [ | ||
"/var/log" | "/var/log" | ||
"/var/lib" | "/var/lib/bluetooth" | ||
"/var/lib/nixos" | |||
"/var/lib/systemd/coredump" | |||
"/var/lib/systemd/timers" | |||
"/etc/NetworkManager/system-connections" | |||
{ directory = "/var/lib/colord"; user = "colord"; group = "colord"; mode = "u=rwx,g=rx,o="; } | |||
]; | ]; | ||
files = [ | files = [ | ||
"/etc/machine-id" | |||
"/etc/nix/id_rsa" | { file = "/etc/nix/id_rsa"; parentDirectory = { mode = "u=rwx,g=,o="; }; } | ||
]; | ]; | ||
}; | }; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Home Managing === | === Home Managing === | ||
You can just make a home partition on a drive and mount it as normal, so everything in <code>/home</code> or <code>/home/username</code> will be persisted. If you want your home to be impermanent as well, then mount it on tmpfs the same way as root. | You can just make a home partition on a drive and mount it as normal, so everything in <code>/home</code> or <code>/home/username</code> 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 [https://github.com/nix-community/home-manager 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 [https://github.com/nix-community/impermanence Home Manager Impermanence module]. It will fuse mount and link files | For persisting files in your home, you could simply use [https://github.com/nix-community/home-manager 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 [https://github.com/nix-community/impermanence Home Manager Impermanence module]. It will fuse mount folders and link files from persistent storage into your home directory. | ||
Line 66: | Line 70: | ||
Put in <code>configuration.nix</code>: | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ config, pkgs, ... }: | { config, pkgs, ... }: | ||
let | let | ||
home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/release- | home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/release-22.05.tar.gz"; | ||
impermanence = builtins.fetchTarball "https://github.com/nix-community/impermanence/archive/master.tar.gz"; | impermanence = builtins.fetchTarball "https://github.com/nix-community/impermanence/archive/master.tar.gz"; | ||
in | in | ||
Line 78: | Line 82: | ||
]; | ]; | ||
# might not be needed | |||
programs.fuse.userAllowOther = true; | programs.fuse.userAllowOther = true; | ||
Line 87: | Line 92: | ||
programs = { | programs = { | ||
home-manager.enable = true; | home-manager.enable = true; | ||
git = { # can use home-manager normally as well as with persistence | git = { # can use home-manager normally as well as with persistence | ||
enable = true; | enable = true; | ||
Line 101: | Line 105: | ||
"Atom/.atom/atom-discord" | "Atom/.atom/atom-discord" | ||
"Atom/.atom/packages" | "Atom/.atom/packages" | ||
"Clementine/.config/Clementine" | "Clementine/.config/Clementine" | ||
# fuse mounted from /nix/dotfiles/Firefox/.mozilla to /home/$USERNAME/.mozilla | |||
"Firefox/.mozilla" | |||
]; | ]; | ||
files = [ | files = [ | ||
Line 119: | Line 125: | ||
allowOther = true; | allowOther = true; | ||
directories = [ | directories = [ | ||
".config/gtk-3.0" # fuse mounted | ".config/gtk-3.0" # fuse mounted from /nix/dotfiles/Plasma/.config/gtk-3.0 | ||
".config/gtk-4.0" | ".config/gtk-4.0" # to /home/$USERNAME/.config/gtk-3.0 | ||
".config/KDE" | ".config/KDE" | ||
".config/kde.org" | ".config/kde.org" | ||
Line 205: | Line 211: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Troubleshooting === | |||
==== 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 https://github.com/nix-community/impermanence/issues/95. | |||
Line 211: | Line 223: | ||
[https://grahamc.com/blog/erase-your-darlings https://grahamc.com/blog/erase-your-darlings] - Explaining why you might want to do this. Uses ZFS snapshots instead of tmpfs. | [https://grahamc.com/blog/erase-your-darlings https://grahamc.com/blog/erase-your-darlings] - Explaining why you might want to do this. Uses ZFS snapshots instead of tmpfs. | ||
https://web.archive.org/web/20241007130142/https://mt-caret.github.io/blog/posts/2020-06-29-optin-state.html - Encypted Btrfs Root with Opt-in State on NixOS. Uses Btrfs instead of tmpfs or ZFS. |