nixConfig/nixos/modules/impermanence.nix

48 lines
998 B
Nix
Raw Permalink Normal View History

2023-11-07 23:47:14 +00:00
{
lib,
config,
...
}: let
inherit
(lib)
2023-09-28 15:12:34 +00:00
mkEnableOption
mkIf
mkOption
types
;
cfg = config.impermanence;
2023-11-07 23:47:14 +00:00
in {
imports = [];
2023-09-28 15:12:34 +00:00
2023-11-07 23:47:14 +00:00
options.impermanence = {
enable = mkEnableOption "impermanence";
storagePath = mkOption {
type = types.path;
default = "/persist";
description = "The path where persistent data is stored";
};
name = mkOption {
type = types.str;
default = "persist";
description = "the name of the persistent data store";
};
2023-09-28 15:12:34 +00:00
};
2023-11-07 23:47:14 +00:00
config = mkIf cfg.enable {
environment.persistence.${cfg.name} = {
persistentStoragePath = cfg.storagePath;
directories = [
"/var/log"
"/var/lib/nixos"
];
files = [
"/etc/ssh/ssh_host_ed25519_key"
"/etc/ssh/ssh_host_ed25519_key.pub"
"/etc/ssh/ssh_host_rsa_key"
"/etc/ssh/ssh_host_rsa_key.pub"
];
};
environment.etc.machine-id.source = "${cfg.storagePath}/machine-id";
2023-09-28 15:12:34 +00:00
};
}