This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| manuals:distributions:nixos:impermanence [2024/10/16 09:12] – aither | manuals:distributions:nixos:impermanence [2026/03/12 11:19] (current) – nix flakes aither | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | < | ||
| ====== NixOS Impermanence ====== | ====== NixOS Impermanence ====== | ||
| - | <note warning> | + | This page describes usage of [[https:// |
| - | This is a work in progress | + | at vpsFree.cz. We support impermanence with root filesystem in a temporary ZFS dataset that is |
| - | </ | + | provided by our platform. It is necessary to move the Nix store to a subdataset, which can be |
| + | done automatically [[# | ||
| + | set it up [[# | ||
| - | ===== 1. Create a NixOS VPS ===== | + | Please note that when you enable impermanence, |
| + | and its data reset on each VPS start. The temporary dataset also isn't backed up. Be mindful | ||
| + | of where you store your data. If it isn't in a persistent location, it will be lost. | ||
| + | |||
| + | ===== Using OS template ===== | ||
| + | vpsAdmin contains OS templates where impermanence is preconfigured. When creating a new VPS, | ||
| + | choose the appropriate template (impermanence is in its name). The new VPS will have ''/ | ||
| + | separated in a subdataset. The root dataset will be mounted to ''/ | ||
| + | flake-based NixOS configuration will be deployed to ''/ | ||
| + | and ''/ | ||
| + | versions of vpsAdminOS, '' | ||
| + | |||
| + | Impermanence is included as a flake input. To update it, update the flake lock and rebuild | ||
| + | the system: | ||
| + | |||
| + | <code bash> | ||
| + | cd / | ||
| + | nix flake lock --update-input impermanence | ||
| + | nixos-rebuild switch --flake / | ||
| + | </ | ||
| + | |||
| + | Note that reinstalling the VPS will be ineffective, | ||
| + | It will not touch the Nix store when it is moved to a subdataset. For the same reason, you | ||
| + | cannot convert an existing VPS to impermanence using reinstall. The OS template will | ||
| + | auto-configure the VPS only on creation. See [[# | ||
| + | enable impermanence on an existing VPS. | ||
| + | |||
| + | ===== Manual configuration ===== | ||
| + | |||
| + | ==== 1. Create a NixOS VPS ==== | ||
| Create a new VPS and let it start. You can also reuse your existing NixOS VPS. | Create a new VPS and let it start. You can also reuse your existing NixOS VPS. | ||
| - | ===== 2. Start the VPS in rescue mode ===== | + | ==== 2. Start the VPS in rescue mode ==== |
| In VPS details, use form **Boot VPS from template (rescue mode)**. It's best | In VPS details, use form **Boot VPS from template (rescue mode)**. It's best | ||
| - | to choose a different distribution than NixOS, so that there' | + | to choose a different distribution than NixOS, so that there' |
| Use e.g. Alpine or Debian. | Use e.g. Alpine or Debian. | ||
| - | ===== 3. Create VPS subdataset for the Nix store ===== | + | ==== 3. Create VPS subdataset for the Nix store ==== |
| - | In VPS details, create | + | In VPS details, create |
| want to boot into NixOS in the previous step). You might have to free some diskspace in order to be | want to boot into NixOS in the previous step). You might have to free some diskspace in order to be | ||
| - | able to create the dataset, you can do that be shrinking the root dataset. | + | able to create the dataset, you can do that by shrinking the root dataset. |
| - | ===== 4. Move the Nix store to the subdataset | + | ==== 4. Move the Nix store to the subdataset ==== |
| Login to the VPS while in rescue mode, either over SSH or use the remote console. | Login to the VPS while in rescue mode, either over SSH or use the remote console. | ||
| The root dataset is mounted at ''/ | The root dataset is mounted at ''/ | ||
| Line 27: | Line 59: | ||
| </ | </ | ||
| - | ===== 5. Mount root dataset to / | + | ==== 5. Mount root dataset to /persistent ==== |
| - | Since in the impermanence mode, your root filesystem | + | In the impermanence mode, your root file system |
| every start. We must mount our persistent storage to ''/ | every start. We must mount our persistent storage to ''/ | ||
| the root dataset, or you can create another subdataset for that purpose. We'll use the root | the root dataset, or you can create another subdataset for that purpose. We'll use the root | ||
| Line 34: | Line 66: | ||
| (its name is the VPS ID) and mount it to ''/ | (its name is the VPS ID) and mount it to ''/ | ||
| - | ===== 6. Restart the VPS ===== | + | ==== 6. Restart the VPS ==== |
| Now restart the VPS, you will leave the rescue mode. | Now restart the VPS, you will leave the rescue mode. | ||
| - | ===== 7. Edit your configuration and add the impermanence | + | ==== 7. Edit your flake configuration and add impermanence ==== |
| - | Clone the impermanence module repository into ''/ | + | vpsAdminOS templates enable flakes by default. Create |
| - | don't have it in your system, | + | keep your local settings in ''/ |
| + | stable | ||
| + | matching '' | ||
| + | '' | ||
| + | replace the stable container module line in the example with | ||
| + | '' | ||
| - | <code bash> | + | <file nix /etc/nixos/ |
| - | cd / | + | { |
| - | git clone https://github.com/ | + | inputs = { |
| - | </ | + | vpsadminos.url = " |
| + | nixpkgs.url = " | ||
| + | impermanence.url = " | ||
| + | }; | ||
| - | Extend | + | outputs = { nixpkgs, vpsadminos, impermanence, |
| + | let | ||
| + | containerModule = " | ||
| + | in | ||
| + | { | ||
| + | nixosConfigurations.vps = nixpkgs.lib.nixosSystem { | ||
| + | system = " | ||
| + | modules = [ | ||
| + | vpsadminos.nixosModules.${containerModule} | ||
| + | impermanence.nixosModules.impermanence | ||
| + | ./ | ||
| + | ]; | ||
| + | }; | ||
| + | }; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Then extend | ||
| <file nix / | <file nix / | ||
| - | { config, | + | { ... }: |
| { | { | ||
| - | imports = [ | ||
| - | ./ | ||
| - | ]; | ||
| - | |||
| environment.persistence."/ | environment.persistence."/ | ||
| hideMounts = true; | hideMounts = true; | ||
| Line 68: | Line 121: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | Ensure flakes are enabled, for example: | ||
| + | |||
| + | <code nix> | ||
| + | nix.settings.experimental-features = [ | ||
| + | " | ||
| + | " | ||
| + | ]; | ||
| + | </ | ||
| Note that ''/ | Note that ''/ | ||
| Line 76: | Line 138: | ||
| <code bash> | <code bash> | ||
| - | nixos-rebuild boot | + | nixos-rebuild boot --flake / |
| </ | </ | ||
| - | ===== 8. Turn on impermanence feature | + | ==== 8. Turn on impermanence feature ==== |
| In VPS details, enable the **NixOS Impermanence** feature. This will configure your VPS so that it | In VPS details, enable the **NixOS Impermanence** feature. This will configure your VPS so that it | ||
| is started with a clean, temporary dataset. Its contents will be lost on every reboot and it's not | is started with a clean, temporary dataset. Its contents will be lost on every reboot and it's not | ||
| Line 96: | Line 158: | ||
| ''/'' | ''/'' | ||
| contains the Nix store. | contains the Nix store. | ||
| - | |||