69 lines
		
	
	
	
		
			2 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
			
		
		
	
	
			69 lines
		
	
	
	
		
			2 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
| {
 | |
|   config,
 | |
|   lib,
 | |
|   outputs,
 | |
|   ...
 | |
| }: let
 | |
|   mountDir = "/mnt/sync";
 | |
|   configDir = "/etc/syncthing";
 | |
| in {
 | |
|   config = lib.mkMerge [
 | |
|     {
 | |
|       systemd = lib.mkIf config.services.syncthing.enable {
 | |
|         tmpfiles.rules = [
 | |
|           "A ${mountDir} -    -        -               - u:syncthing:rwX,g:syncthing:rwX,o::-"
 | |
|           "d ${mountDir} 2755 syncthing syncthing -"
 | |
|           "d ${config.services.syncthing.dataDir} 775 syncthing syncthing -"
 | |
|           "d ${config.services.syncthing.configDir} 755 syncthing syncthing -"
 | |
|         ];
 | |
|       };
 | |
|     }
 | |
|     (lib.mkIf config.services.syncthing.enable (lib.mkMerge [
 | |
|       {
 | |
|         services.syncthing = {
 | |
|           user = "syncthing";
 | |
|           group = "syncthing";
 | |
|           dataDir = "${mountDir}/default";
 | |
|           configDir = configDir;
 | |
|           overrideDevices = true;
 | |
|           overrideFolders = true;
 | |
|           configuration = outputs.syncthingConfiguration;
 | |
|           deviceName = config.networking.hostName;
 | |
|         };
 | |
|       }
 | |
| 
 | |
|       (lib.mkIf config.host.impermanence.enable {
 | |
|         assertions =
 | |
|           [
 | |
|             {
 | |
|               assertion = config.services.syncthing.configDir == configDir;
 | |
|               message = "syncthing config dir does not match persistence";
 | |
|             }
 | |
|           ]
 | |
|           ++ lib.attrsets.mapAttrsToList (_: folder: {
 | |
|             assertion = lib.strings.hasPrefix mountDir folder.path;
 | |
|             message = "syncthing folder ${folder.label} is stored at ${folder.path} which not under the persisted path of ${mountDir}";
 | |
|           })
 | |
|           config.services.syncthing.settings.folders;
 | |
|         environment.persistence = {
 | |
|           "/persist/system/root" = {
 | |
|             enable = true;
 | |
|             hideMounts = true;
 | |
|             directories = [
 | |
|               {
 | |
|                 directory = mountDir;
 | |
|                 user = "syncthing";
 | |
|                 group = "syncthing";
 | |
|               }
 | |
|               {
 | |
|                 directory = configDir;
 | |
|                 user = "syncthing";
 | |
|                 group = "syncthing";
 | |
|               }
 | |
|             ];
 | |
|           };
 | |
|         };
 | |
|       })
 | |
|     ]))
 | |
|   ];
 | |
| }
 |