nixdots/options/system/impermanence.nix

89 lines
2.7 KiB
Nix
Raw Normal View History

2024-04-07 16:28:15 +00:00
{ lib, config, ... }: with lib; let
2024-04-07 22:36:02 +00:00
inherit (lib) mkEnableOption mkOption literalExpression types;
2024-04-07 16:28:15 +00:00
cfg = config.myOptions.system.impermanence;
in
{
options.myOptions.system.impermanence = {
root = {
enable = mkEnableOption ''
the Impermanence module for persisting important state directories.
'';
extraFiles = mkOption {
default = [];
2024-04-07 22:36:02 +00:00
type = types.listOf types.path;
2024-04-07 16:28:15 +00:00
example = literalExpression ''["/etc/nix/id_rsa"]'';
description = ''
Additional files in root to link to persistent storage.
'';
};
extraDirectories = mkOption {
default = [];
2024-04-07 22:36:02 +00:00
type = types.listOf types.path;
2024-04-07 16:28:15 +00:00
example = literalExpression ''["/etc/nix/id_rsa"]'';
description = ''
Additional directories in root to link to persistent storage.
'';
};
persistentMountPoint = mkOption {
default = "/persist";
description = ''
Path to a persistent directory (usually a mount point to a
standalone partition / subvolume), which will hold the persistent
system state files.
'';
};
2024-04-07 22:36:02 +00:00
};
2024-04-07 16:28:15 +00:00
2024-04-07 22:36:02 +00:00
autoWipeBtrfs = let
btrfsDeviceOptionType = types.submodule {
options = {
subvolumes = mkOption {
type = types.listOf types.str;
default = [];
description = ''
List of BTRFS subvolumes to be wiped from the device.
2024-04-07 16:28:15 +00:00
2024-04-07 22:36:02 +00:00
These subvolumes will be wiped from initrd, before the subvolumes are mounted.
'';
example = literalExpression ''[ "root" "home" ]'';
};
2024-04-07 16:28:15 +00:00
};
2024-04-07 22:36:02 +00:00
};
in {
enable = mkEnableOption ''
automatic wiping of specified BTRFS subvolumes from initrd.
2024-04-07 16:28:15 +00:00
2024-04-07 22:36:02 +00:00
If you're using BTRFS, you will generally want to enable this, however
with a non-BTRFS system, or in case you wish to set up some custom handling
which this module doesn't support, you will need to write your own logic
for automatic root wiping.
2024-04-07 16:28:15 +00:00
2024-04-07 22:36:02 +00:00
One option is is to simply have your root get mounted from tmpfs, making it
live in RAM. This does however require dedicating a concrete chunk of RAM.
'';
2024-04-07 16:28:15 +00:00
2024-04-07 22:36:02 +00:00
devices = mkOption {
default = {};
type = types.attrsOf btrfsDeviceOptionType;
description = ''
BTRFS devices and their subvolumes to be wiped.
'';
example = literalExpression ''
{
"/dev/sda1" = {
subvolumes = [ "root" ];
};
"/dev/mapper/cryptfs" = {
subvolumes = [ "homeJohn" "homeBob" ];
};
}
'';
2024-04-07 16:28:15 +00:00
};
};
};
}