43 lines
1.3 KiB
Nix
43 lines
1.3 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
osConfig,
|
|
...
|
|
}: let
|
|
cfg = config.impermanence;
|
|
in {
|
|
options.impermanence = {
|
|
enable = lib.mkEnableOption "impermanence for home directory";
|
|
fallbackPersistence.enable = lib.mkOption {
|
|
type = lib.types.bool;
|
|
default = true;
|
|
};
|
|
persistencePath = lib.mkOption {
|
|
type = lib.types.str;
|
|
default =
|
|
if osConfig.storage.generateBase
|
|
then "/persist/replicate/home"
|
|
else "/persist";
|
|
description = "The base path for user home persistence. The impermanence module will automatically append the user's home directory path. Automatically adapts based on whether the system uses the new dataset layout or the legacy one.";
|
|
};
|
|
};
|
|
|
|
config = lib.mkMerge [
|
|
(lib.mkIf config.impermanence.enable {
|
|
assertions = [
|
|
{
|
|
assertion = osConfig.storage.impermanence.enable;
|
|
message = "impermanence can not be enabled for a user when it is not enabled for the system";
|
|
}
|
|
];
|
|
})
|
|
# If impermanence is not enabled for this user but system impermanence is enabled,
|
|
# persist the entire home directory as fallback
|
|
(lib.mkIf (osConfig.storage.impermanence.enable && !cfg.enable && cfg.fallbackPersistence.enable) {
|
|
home.persistence."${cfg.persistencePath}" = {
|
|
directories = ["."];
|
|
allowOther = true;
|
|
};
|
|
})
|
|
];
|
|
}
|