35 lines
		
	
	
	
		
			956 B
		
	
	
	
		
			Nix
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
	
		
			956 B
		
	
	
	
		
			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;
 | 
						|
    };
 | 
						|
  };
 | 
						|
 | 
						|
  config = lib.mkMerge [
 | 
						|
    (lib.mkIf config.impermanence.enable {
 | 
						|
      assertions = [
 | 
						|
        {
 | 
						|
          assertion = osConfig.host.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.host.impermanence.enable && !cfg.enable && cfg.fallbackPersistence.enable) {
 | 
						|
      home.persistence."/persist/home/${config.home.username}" = {
 | 
						|
        directories = ["."];
 | 
						|
        allowOther = true;
 | 
						|
      };
 | 
						|
    })
 | 
						|
  ];
 | 
						|
}
 |