31 lines
		
	
	
	
		
			826 B
		
	
	
	
		
			Nix
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
	
		
			826 B
		
	
	
	
		
			Nix
		
	
	
	
	
	
| {
 | |
|   config,
 | |
|   lib,
 | |
|   osConfig,
 | |
|   ...
 | |
| }: let
 | |
|   cfg = config.impermanence;
 | |
| in {
 | |
|   options.impermanence = {
 | |
|     enable = lib.mkEnableOption "impermanence for home directory";
 | |
|   };
 | |
| 
 | |
|   config = lib.mkMerge [
 | |
|     (lib.mkIf config.impermanence.enable {
 | |
|       assertions = [
 | |
|         {
 | |
|           assertion = osConfig.impermanence.enable;
 | |
|           message = "impermanence can not be enabled for a user when it is not enabled for a configuration";
 | |
|         }
 | |
|       ];
 | |
|     })
 | |
|     (lib.mkIf osConfig.host.impermanence.enable {
 | |
|       # If impermanence is not enabled for this user but system impermanence is enabled,
 | |
|       # persist the entire home directory as fallback
 | |
|       home.persistence."/persist/home/${config.home.username}" = lib.mkIf (!cfg.enable) {
 | |
|         directories = ["."];
 | |
|         allowOther = true;
 | |
|       };
 | |
|     })
 | |
|   ];
 | |
| }
 |